Friday, September 14, 2007

How portable is Java code?

In my last blog entry, I mentioned the differences in file locking behaviour I found between Sun's Windows JDK and Mac JDK. Well, I recently acquired a Dell server, and am running SLES 10.1 64-bit edition on it. The default Java 5 SDK that comes with SLES 10.1 is IBM's JDK 5 SR3. SimpleDBM fails to pass all its test cases under this JVM. All tests pass successfully when I run using Sun's Java 6 SE Update 2 64-bit JVM.

I haven't tried any other JDK's yet, but it would be interesting to see the results.

The point is that when I code in Java, I expect my code to run correctly on all JDKs. I do not want to have to worry about portability issues. But reality is that the JDK and its libraries are so large, that it must be very hard to make independently developed JVM's to be completely compatible.

Update: One of the test cases started failing because the HashMap.values().toArray() on IBM's JVM returns values in reverse order of the Sun JVM. This changed the results of the test to be different from what was expected, and therefore the test failed.

No comments: