In this article I will show how to find the compiler version information of a java class file. It is very easy to find this information using java command.
Java virtual machine
class file format.
class file contains the definition of a single class or interface. Although a class or interface need not have an external representation literally contained in a file (for instance, because the class is generated by a class loader), we will colloquially refer to any valid representation of a class or interface as being in the
class file format.
class file consists of a stream of 8-bit bytes. All 16-bit, 32-bit, and 64-bit quantities are constructed by reading in two, four, and eight consecutive 8-bit bytes, respectively. Multibyte data items are always stored in big-endian order, where the high bytes come first. In the Java and Java 2 platforms, this format is supported by interfaces
java.io.DataOutput and classes such as
class file consists of a single
For example you want to inspect is TempJava.clas. Open the command console move to the compile class location. And run below command.
javap -verbose TempClass
And below is the example output:
Compiled from “TempClass.java”
public class TempClass extends java.lang.Object
minor version: 0
major version: 50
const #1 = class #2; // TempClass
const #2 = Asciz TempClass;
const #3 = class #4; // java/lang/Object
const #4 = Asciz java/lang/Object;
The first 4 bytes are a magic number, 0xCAFEBABe, to identify a valid class file then the next 2 bytes identify the class format version (major and minor).
Possible major/minor value :
major – minor – Java platform version
45 3 1.0
45 3 1.1
46 0 1.2
47 0 1.3
48 0 1.4
49 0 1.5
50 0 1.6
Its Sun’s simple disassembler.
It works much like java.exe except instead of running the program it takes the class file apart and shows you how it works at the byte code level, e. g.rem Disassemble a class file
where options include:
-c Disassemble the code
-classpath <pathlist> Specify where to find user class files
-extdirs <dirs> Override location of installed extensions
-help Print this usage message
-J<flag> Pass <flag> directly to the runtime system
-l Print line number and local variable tables
-public Show only public classes and members
-protected Show protected/public classes and members
-package Show package/protected/public classes and members (default)
-private Show all classes and members
-s Print internal type signatures
-bootclasspath <pathlist> Override location of class files loaded by the bootstrap class loader
-verbose Print stack size, number of locals and args for methods, If verifying, print reasons for failure
javap.exe -classpath E:\;. -c -l -private -s -verbose Biorhythms > bytecodes.txt