This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
I have jdk 1.6 installed in my system.
It was doing well initially.All of a sudden there is an error when trying to run even a small java program
the error is as follows.
Exception in thread "main" java.lang.UnsupportedClassVersionError:TDemo<Unsupported major.minor version 50.0>
at java.lang.ClassLoader.defineClass0(Native Method)
what reason might have caused the error?
thanks for the reply in advance
Sebastian Janisch wrote:I'm pretty sure it means you compiled your code with Java 5 and try to run it with Java 6.
You probably mean that the other way around: the code was compiled with Java 6, and you're trying to run it with Java 5.
Java is downward compatible: newer versions can run class files compiled with older versions. But it is not upward compatible - older versions cannot (normally) run class files compiled with newer versions.
Compile your code with Java 5 if it needs to run on a Java 5 JRE.
The mapping between the major / minor version in the magic number of the class file and the Java platform / compiler version might be useful for future reference:
Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
Joined: Aug 19, 2009
There is only one version installed in my system i.e., java 1.6
I compiled it in the command prompt and tried to run it as soon as it is compiled
I dint make any changes of the version.
The same code is running successfully when i tried to run it in netbeans IDE instead of command prompt.
I tried removing my classpath and path variable and system is still compiling the java programs
using the java 1.4 version.It never happened before.
Even if set the classpath and path to jdk 1.6 correctly its using the same java 1.4 version.
What am i supposed to do now?
Joined: Oct 13, 2005
Don't set a classpath; that usually causes more trouble later on.
You will have to restore your PATH otherwise lots of programs will fail to run.
David Newton told you what the problem was; you ought to have put the Java6 installation before the Java1.4 in the PATH.