Every time the structure of Java byte-code changes, the version number embedded in .class files must also change. Java 1.2 uses major version 46 Java 1.3 uses major version 47 Java 1.4 uses major version 48 Java 5 uses major version 49 Java 6 uses major version 50 Java 7 uses major version 51 Java 8 uses major version 52 Each newer version of Java fully supports classes compiled with an older Java version. A class file complied with JDK 6 is supported on Java 7 and Java 8, but it is not supported by Java 5 or earlier. If a .class file compiled with a later JDK version is attempted to be used on an older Java version, then the java.lang.UnsupportedClassVersionError
is raised by the Java runtime. For example given this error:
|
|
We can deduce that the Java version being used is Java 5 or earlier, since Java 6 or later will fully support .class files with a major version number of 50. The Java version being used can be checked using the following command:
|
|
On UNIX systems, you can also use the which
command to determine which Java executable is being used. On Windows you can use the where
command. In the above example it turned out that a 1.4.2 JRE that shipped with another product, was being picked up because of the way the Windows PATH
environment variable was configured.