➤ How to Code a Game
➤ Array Programs in Java
➤ Java Inline Thread Creation
➤ Java Custom Exception
➤ Hibernate vs JDBC
➤ Object Relational Mapping
➤ Check Oracle DB Size
➤ Check Oracle DB Version
➤ Generation of Computers
➤ XML Pros & Cons
➤ Git Analytics & Its Uses
➤ Top Skills for Cloud Professional
➤ How to Hire Best Candidates
➤ Scrum Master Roles & Work
➤ CyberSecurity in Python
➤ Protect from Cyber-Attack
➤ Solve App Development Challenges
➤ Top Chrome Extensions for Twitch Users
➤ Mistakes That Can Ruin Your Test Metric Program
In this post, we will see how to read and display the .class file version? How we can find out a Java class file’s compiler version? Different tool to read and display Java .class versions? Check which JDK version compiled the class?
After compilation of a .java file, compiler generates .class file. Every .class file contains
major_version attributes that represent the version of the .class file. The JVM (Java virtual machine) uses minor_version & major_version attributes to identify the version of the compiler which generates the given .class file.
There are different ways to read and display the .class file version name.
- We can use
javaptool for this purpose.
In Windows operating system,
> javap -verbose ClassName | findstr "major"
In Linux operating system,
$ javap -verbose ClassName | grep "major"
|JDK Version||Major Version |
|Major Version |
|Java SE 5.0||49||0x31|
|Java SE 6.0||50||0x32|
|Java SE 7.0||51||0x33|
|Java SE 8.0||52||0x34|
|Java SE 9.0||53||0x35|
|Java SE 10.0||54||0x36|
|Java SE 11.0||55||0x37|
|Java SE 12.0||56||0x38|
|Java SE 13.0||57||0x39|
|Java SE 14.0||58||0x3A|
- By using
javaptool you can get every information about the .class file.
javap -verbose ClassName
The .class file generated by the lower version of the compiler can be executed by the higher version JVM, but the .class file generated by the higher version of the compiler can’t be executed by the lower version JVM.
For example:- If a .class is generated by Java SE 8.0 can be executed by Java SE 13.0, but the .class file generated by the Java SE 13.0 can’t be executed by the Java SE 8.0 version compiler.
Other Ways to Read & Display .class file Version In Linux
Go to the directory where the .class file is located and execute the command in terminal
$ file ClassName.class
It Will give the file type and version as well. Here is what the output looks like:
ClassName.class: compiled Java class data, version 57.0
You can also read and display .class file major_version without going to the directory.
$ file path-to-file/ClassName.class
In my case, the java file “Hello.java” is located in the “Java” directory. So, the below command gives the version number.
Using Hex Editor
If you don’t have access to
javap, you can also use a console-based utility or GUI hex editor to look at the value of the byte at position 7 in the file. Using Linux, this is easily done using the ‘od’ dump standard utility.
$ od --format=d1 MyClass.class -j 7 -N 1
The output looks like
0000007 57 0000010
If you enjoyed this post, share it with your friends. Do you want to share more information about the topic discussed above or do you find anything incorrect? Let us know in the comments. Thank you!