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.
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.
Last modified 22-Jul-2019; size 1623 bytes
SHA-256 checksum 3300fe43abc2f26d1c5cf5e8870081c60e91d6cfd8d96f2fc8f18ce4660b151e
Compiled from “HelloWorld.java”
public class com.codippa.HelloWorld
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.
|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|
As per this table, the class file shown above was compiled on Java 8.