How do I copy an object in Java?

Tags: , , ,


Consider the code below: DummyBean dum = new DummyBean(); dum.setDummy(“foo”); System.out.println(dum.getDummy()); // prints ‘foo’ DummyBean dumtwo = dum; System.out.println(dumtwo.getDummy()); // …

Java FileReader encoding issue

Tags: , , ,


I tried to use java.io.FileReader to read some text files and convert them into a string, but I found the result is wrongly encoded and not readable at all. Here’s my environment: Windows 2003, OS …

Tags: applet java

getClassLoader().getResource() returns null

Tags: ,


I have this test app: import java.applet.*; import java.awt.*; import java.net.URL; public class Test extends Applet { public void init() { URL some=Test.class.getClass()….

Determining binary/text file type in Java?

Tags: , , ,


Namely, how would you tell an archive (jar/rar/etc.) file from a textual (xml/txt, encoding-independent) one?

Performance of ThreadLocal variable

Tags: , , ,


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 …

Why is a ConcurrentModificationException thrown and how to debug it

Tags: , , ,


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 …

Tags: java

Eager java class loading

Tags:


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 …

In java under Windows, how do I find a redirected Desktop folder?

Tags: , , , ,


I know using .NET languages such as C#, one can do something like Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) to find the redirected location of the Desktop. However, …

UTF-8 text is garbled when form is posted as multipart/form-data

Tags: ,


I’m uploading a file to the server. The file upload HTML form has 2 fields: File name – A HTML text box where the user can give a name in any language. File upload – A HTMl ‘file’ where user can …

Tags: java

How can “while (i == i) ;” be a non-infinite loop in a single threaded application?

Tags:


I just got a question that I can’t answer. Suppose you have this loop definition in Java: while (i == i) ; What is the type of i and the value of i if the loop is not an infinite loop and the …