How can I lock a file using java (if possible)

I have a Java process that opens a file using a FileReader. How can I prevent another (Java) process from opening this file, or at least notify that second process that the file is already opened? …

What’s the nearest substitute for a function pointer in Java?

I have a method that’s about ten lines of code. I want to create more methods that do exactly the same thing, except for a small calculation that’s going to change one line of code. This is a …

Why doesn’t Java offer operator overloading?

Coming from C++ to Java, the obvious unanswered question is why didn’t Java include operator overloading? Isn’t Complex a, b, c; a = b + c; much simpler than Complex a, b, c; a = b.add(c);? Is there …

How can I find the response time of a HTTP request through a Socket

I’m using a Java socket, connected to a server. If I send a HEADER http request, how can I measure the response time from the server? Must I use a provided java timer, or is there an easier way? I’m …

Does a finally block always get executed in Java?

Considering this code, can I be absolutely sure that the finally block always executes, no matter what something() is? try { something(); return success; } catch (Exception e) { …

Rule of thumb for choosing an implementation of a Java Collection?

Anyone have a good rule of thumb for choosing between different implementations of Java Collection interfaces like List, Map, or Set? For example, generally why or in what cases would I prefer to use …

How to convert a date String to a Date or Calendar object?

I have a String representation of a date that I need to create a Date or Calendar object from. I’ve looked through Date and Calendar APIs but haven’t found anything that can do this other than …

Checking the results of a Factory in a unit test

I have developed some classes with similar behavior, they all implement the same interface. I implemented a factory that creates the appropriate object and returns the interface. I am writing a unit …

How can I play sound in Java?

I want to be able to play sound files in my program. Where should I look?

IKVM and Licensing

I have been looking into IKVMing Apache’s FOP project to use with our .NET app. It’s a commercial product, and looking into licensing, IKVM runs into some sticky areas because of its use of GNU …