Namely, how would you tell an archive (jar/rar/etc.) file from a textual (xml/txt, encoding-independent) one?
Best way to check whether a certain exception type was the cause (of a cause, etc …) in a nested exception?
I am writing some JUnit tests that verify that an exception of type MyCustomException is thrown. However, this exception is wrapped in other exceptions a number of times, e.g. in an InvocationTargetException, which in turn is wrapped in a RuntimeException. What’s the best way to determine whether MyCust…
Convert from enum ordinal to enum type
I’ve the enum type ReportTypeEnum that get passed between methods in all my classes but I then need to pass this on the URL so I use the ordinal method to get the int value. After I get it in my other JSP page, I need to convert it to back to an ReportTypeEnum so that I can continue passing
Performance of ThreadLocal variable
How much is read from ThreadLocal variable slower than from regular field? More concretely is simple object creation faster or slower than access to ThreadLocal variable? I assume that it is fast enough so that having ThreadLocal<MessageDigest> instance is much faster then creating instance of MessageDi…
Why is a ConcurrentModificationException thrown and how to debug it
I am using a Collection (a HashMap used indirectly by the JPA, it so happens), but apparently randomly the code throws a ConcurrentModificationException. What is causing it and how do I fix this problem? By using some synchronization, perhaps? Here is the full stack-trace: Answer This is not a synchronization…
Eager java class loading
I’m trying to do some benchmarking of JVMs running on various hardware and OS platforms. I’ve created an algorithm to exercise the parts of the JVM I’m interested in and intend to run this algorithm many times to find a decent average. When I run the benchmark, I find that the first run is s…
Asynchronous IO in Java?
What options for async io (socket-based) are there in java other then java.nio? Also does java.nio use threads in the backround (as I think .NET’s async-socket-library does, maybe it’s been changed) or is it “true” async io using a proper select call? Answer Java’s NIO package (a…
What are the main benefits of using Mono over Java? [closed]
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, …
open resource with relative path in Java
In my Java app I need to get some files and directories. This is the program structure: guiclass loads the resourcesloader class which will load my resources (directory and file). As to the file, I tried in order to get the real path, but this way does not work. I have no idea which path to use for the direct…
In java under Windows, how do I find a redirected Desktop folder?
I know using .NET languages such as C#, one can do something like to find the redirected location of the Desktop. However, under Java, I cannot think of a good way to do this. What is the most appropriate way to find a redirected user Desktop directory from Java, without using JNI? The specific purpose here i…