java.lang.UnsupportedClassVersionError : This exception occurs when to try to run or load a class which is compiled in another version of java. A version of a class file is determined using major and minor version number which is stored in class file format(java class version = Major.Minor, for example if the minor version is 0 , and major is 49 then version will be 49.0).JVM can support only those classes whose version is in the range.Simply put , jvm will not support classes which are compiled using higher version of jdk than this jvm.
For example , i have created a Test.java , and compiled it using java version 7 , if i try to run it in JRE 6 , i will get error like this :
Exception in thread "main" java.lang.UnsupportedClassVersionError: Test : Unsupported major.minor version 51.0 at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClassCond(Unknown Source) at java.lang.ClassLoader.defineClass(Unknown Source) at java.security.SecureClassLoader.defineClass(Unknown Source) at java.net.URLClassLoader.defineClass(Unknown Source) at java.net.URLClassLoader.access$000(Unknown Source) at java.net.URLClassLoader$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) Could not find the main class: Test. Program will exit.If i run this class using JRE 5 , then i get error like this :
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(Unknown Source) at java.security.SecureClassLoader.defineClass(Unknown Source) at java.net.URLClassLoader.defineClass(Unknown Source) at java.net.URLClassLoader.access$100(Unknown Source) at java.net.URLClassLoader$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClassInternal(Unknown Source)You can check your jre version by running command :
java -versionAnd You can check the version of jdk by which the java file is compiled by running command :
javap -verbose TestIt will give you result like this :
public class Test SourceFile: "Test.java" minor version: 0 major version: 51 flags: ACC_PUBLIC, ACC_SUPER ....Major version number mapping is following
J2SE 7 = 51 (0x33 hex), J2SE 6.0 = 50 (0x32 hex), J2SE 5.0 = 49 (0x31 hex), JDK 1.4 = 48 (0x30 hex), JDK 1.3 = 47 (0x2F hex), JDK 1.2 = 46 (0x2E hex), JDK 1.1 = 45 (0x2D hex).You can read about it more on this Wiki link and Here also Post Comments !!!