Another programmer was mentioning that they haven’t found a use case for using a linked list data structure in any professional software in his career. I couldn’t think of any good examples off the top of my head. He is mostly a C# and Java developer Can anyone give some examples where this was th…
Tag: java
Byte array of unknown length in java
I am constructing an array of bytes in java and I don’t know how long the array will be. I want some tool like Java’s StringBuffer that you can just call .append(byte b) or .append(byte[] buf) and have it buffer all my bytes and return to me a byte[] when I’m done. Is there a class that does…
Does JPA support mapping to sql views?
I’m currently using Eclipselink, but I know now days most JPA implementations have been pretty standardized. Is there a native way to map a JPA entity to a view? I am not looking to insert/update, but the question is really how to handle the @Id annotation. Every entity in the JPA world must have an ID …
getClassLoader().getResource() returns null
I have this test app: When I run it from Eclipse, I get the error: Classpath (from .CLASSPATH file) In my c:projectsrc folder, I have only the Test.java file and the ‘assets’ directory which contains pacman.png. What am I doing wrong and how to resolve it? Answer I would do it this way: “/as…
Determining binary/text file type in Java?
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…