How to find out the jdk version which compiled a class in java

You can easily determine the jdk version with which a given java file was compiled using the below command.

javap –verbose <class file name>

The above command should be executed at the location where the class file is placed or otherwise the entire path of class file needs to be given.

Open the command prompt on windows or terminal on linux/mac systems and navigate to the location of class file and execute the above command.
Example,

E:\com\codippa>javap -verbose HelloWorld.class

Note the folders com/codippa is the package of this class since a java file when compiled is located inside the folders that match its package.
This command will print a lengthy output which also contains the bytecode of the class but first few lines will let us know the version of jdk that we are looking for.
Above command prints the following output.

E:\com\codippa>javap -verbose HelloWorld.class
Classfile /E:/com/codippa/HelloWorld.class
Last modified 22-Jul-2019; size 1623 bytes
SHA-256 checksum 3300fe43abc2f26d1c5cf5e8870081c60e91d6cfd8d96f2fc8f18ce4660b151e
Compiled from “HelloWorld.java”
public class com.codippa.HelloWorld

minor version: 0
major version: 52

flags: (0x0021) ACC_PUBLIC, ACC_SUPER
this_class: #1 // com/codippa/HelloWorld
super_class: #3 // java/lang/Object
interfaces: 0, fields: 0, methods: 3, attributes: 1
……
……

Note that the output contains the name and complete path of the java file, its compiled class file name with package and other details.

If you look at the highlighted part, you will see a minor version: 0 and major version: 52. Out of these two values, major version will help us to determine the compiling jdk version as per the table below.

Major VersionJDK Version
58Java SE 14
57Java SE 13
58Java SE 12
55Java SE 11
54Java SE 10
53Java SE 9
52Java SE 8
51Java SE 7
50Java SE 6
49Java SE 5
48JDK 1.4
47JDK 1.3
46JDK 1.2
45JDK 1.1

As per this table, the class file shown above was compiled on Java 8.

Hit the clap below as a token of appreciation.

Leave a Reply