java

Delaying an exception

I have a method that periodically (e.g. once in every 10 secs) try to connect to a server and read some data from it. The server might not be available all the time. If the server is not available the method throws an exception. What would be the best way to implement a wrapper method that doesn't throw an exception except if the server...

How do I sign a Java applet using a certificate in my Mac keychain?

I have a self-signed root certificate with just the code signing extension (no other extensions) in my Mac keychain; I use it to sign all code coming out of ∞labs using Apple's codesign tool and it works great. I was looking to expand myself a little and doing some Java development. I know Apple provides a KeyStore implementation that r...

Is it worth learning Java when you already know C# fairly well?

Since C# is in many ways a direct derivative of Java I wondered whether there was any advantage to learning Java after the fact of having learnt quite a reasonable about about C#? Note: Please provide clear, direct advice rather than discussion in order to keep in line with SO guidelines. ...

Why are Exceptions not Checked in .NET?

I know Googling I can find an appropriate answer, but I prefer listening to your personal (and maybe technical) opinions. What is the main reason of the difference between Java and C# in throwing exceptions? In Java the signature of a method that throws an exception has to use the "throws" keyword, while in C# you don't know in compilati...

Should I never use primitive types again?

Mixing the use of primitive data types and their respective wrapper classes, in Java, can lead to a lot of bugs. The following example illustrates the issue: int i = 4; ... if (i == 10) doCrap(); Later on you figure that you want the variable i to be either defined or undefined, so you change the above instantiation to: Integer i =...

What is the best way to manage Time in a Java application?

So I'm using hibernate and working with an application that manages time. What is the best way to deal with times in a 24 hour clock? I do not need to worry about TimeZone issues at the beginning of this application but it would be best to ensure that this functionality is built in at the beginning. I'm using hibernate as well, just as...

Why does Hibernate seem to be designed for short lived sessions?

I know this is a subjective question, but why does Hibernate seem to be designed for short lived sessions? Generally in my apps I create DAOs to abstract my data layer, but since I can't predict how the entity objects are going to be used some of its collections are lazy loaded, or I should say fail to load once the session is closed. ...

Java equals(): to reflect or not to reflect

This question is specifically related to overriding the equals() method for objects with a large number of fields. First off, let me say that this large object cannot be broken down into multiple components without violating OO principles, so telling me "no class should have more than x fields" won't help. Moving on, the problem came...

Turn an array of pixels into an Image object with Java's ImageIO?

I'm currently turning an array of pixel values (originally created with a java.awt.image.PixelGrabber object) into an Image object using the following code: public Image getImageFromArray(int[] pixels, int width, int height) { MemoryImageSource mis = new MemoryImageSource(width, height, pixels, 0, width); Toolkit tk = Toolkit.ge...

Picking a random element from a set

How do I pick a random element from a set? I'm particularly interested in picking a random element from a HashSet or a LinkedHashSet, in Java. Solutions for other languages are also welcome. ...

How to map a Servlet to get extra path information with getPathInfo()

I am having an issue where Tomcat is treating extra path information as part of the servlet name. This is breaking a bunch of RESTFul functionality in our webapp (we use extra path info rather than ?name=value pairs for crawler friendly links). It was working correctly before, but it broke after adding explicit mappings and removing th...

Free/Open Source Test Generator for Java?

Are there any libraries for Java that can generate unit tests or unit test skeletons for existing code? I'm looking for something similar to pythoscope. Ideally it would generate code that follows JUnit4 or TestNG conventions. It looks like Agitar does something like this, but I'm looking for something free. ...

Java developer moving to web design, easiest transition?

This question gave me tons of great places to start looking into developing web apps. If I wanted to try to stick with Java, where do you recommend I look? Or, do you recommend I let go of my safety blanket and fly free with PHP, Django or Rails? ...

How to launch from Eclipse in Low priority under Windows?

I'm running programs from Eclipse (on Windows) that eat a lot of CPU time. To avoid bogging down my whole machine, I set the priority to Low with the Task Manager. However, this is a cumbersome manual process. Is there a way Eclipse can set this priority automatically? EDIT: I realized that each particular launcher (Java, Python etc) ha...

How to implement simple threading in Java

I'm looking for the simplest, most straightforward way to implement the following: The main program instantiates worker threads to do a task. Only n tasks can be running at once. When n is reached, no more workers are started until the count of running threads drops back below n. ...

Any clever ways of handling the context in a web app?

In Java, web apps are bundled in to WARs. By default, many servlet containers will use the WAR name as the context name for the application. Thus myapp.war gets deployed to http://example.com/myapp. The problem is that the webapp considers its "root" to be, well, "root", or simply "/", whereas HTML would consider the root of your appli...

Is it possible to define a Java ClassLoader that returns completely different classes to the one's requested?

I've tried this, but get a ClassNotFoundException when calling: Class.forName("com.AClass", false, mySpecialLoader) ...

How do you remotely update Java applications?

We've got a Java server application that runs on a number of computers, all connected to the Internet, some behind firewalls. We need to remotely update the JAR files and startup scripts from a central site, with no noticeable interruption to the app itself. The process has to be unattended and foolproof (i.e. we can't afford to break t...

Managed language for scientific computing software

Scientific computing is algorithm intensive and can also be data intensive. It often needs to use a lot of memory to run analysis and release it before continuing with the next. Sometime it also uses memory pool to recycle memory for each analysis. Managed language is interesting here because it can allow the developer to concentrate on ...

Java, NetBean : Access web.xml context parameters from Web Service method?

Hi all, I am new to java so excuse my lame questions:) I am trying to build a web service in Java NetBeans 6.1 , but I have some troubles with configuration parameters ( like .settings in .net). What is the right way to save and access such settings in a java web service. Is there a way to read context parameters from web.xml in a ...