I had thought that the .class file one created after compiling a piece of
java code was supposed to run under a different operating system. I tested this with some simple java code
public class HelloWorldApp {
public HelloWorldApp() {
}
public static void main(
String[] args) {
System.out.println("Hello World!");
}
}
I compiled it to a .class file on my home machine (Win XP). It runs fine. I transfered the .class file to my office machine (Linux). It won't run. If I Compile it on my office machine, the resulting .class file runs fine.
However, I thought the .class file itself was supposed to be portable, not just the original uncompiled code. It is true that at home I have Java 1.6.0 and at work I have Java 1.5.0_02-b09, but does that small of a difference really mess up "write once, run anywhere"?
-John
Exception in
thread "main" java.lang.UnsupportedClassVersionError: Bad version number in .class file
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)