Sunday, April 5, 2009

How To Compile Java Code To Eariler Version

For example if you want to compile java code to eariler version 1.4 is..
javac -target 1.4 -bootclasspath \jdk1.4.19\lib\rt.zip Hello.java
How to distinguish the compile version of the class file 
Every java class file had a version stamp two unsigned short integers starting at byte offset 4 right after the 0xCAFEBABE magic number

Java 1.2 platform: 0xCAFEBABE 0x00002E 0x00AF0100
Java 1.3 platform: 0xCAFEBABE 0x00002F
Java 1.4 platform: 0xCAFEBABE 0x000030
Java 1.5 platform: 0xCAFEBABE 0x000031
Java 1.6 platform: 0xCAFEBABE 0x000032

Relate Article: What version is your Java code?