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 Version JDK Version
58 Java SE 14
57 Java SE 13
58 Java SE 12
55 Java SE 11
54 Java SE 10
53 Java SE 9
52 Java SE 8
51 Java SE 7
50 Java SE 6
49 Java SE 5
48 JDK 1.4
47 JDK 1.3
46 JDK 1.2
45 JDK 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