Thursday, May 15, 2014

Java Major Version

All class files while compiled include the version of the java they were compiled with in the generated class files.

Below are the "Major" version numbers for different versions of Java -

J2SE 8 = 52 (0x34 hex),
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).


To check the java version with which a class file was compiled with -
javap -verbose <<ClassFileName>> | grep "major"
In order to generate class files compatible with Java 1.4, use the following command line:
javac -source 1.4 HelloWorld.java
For the above command to work, you must have JRE 1.4 installed on your machine.