Main Tutorials

How to check which JDK version compiled the class?

javap example

Find the major version of the Java class file, and we will know which JDK version compiled the Java class. Below are some popular Java LTS released and their major version numbers.

Java SE Major Version Hex
17 61 0x3D
11 55 0x37
8 52 0x34

If the major version of the Java class file is 55, it means Java 11 compiled the class. Review this table for a complete list of a major versions of the Java class file.

javap command

In Java, we can use javap -verbose className to print out the Java class file information; the output includes the major version number.

Terminal

% javap -verbose JavaClassName

  Classfile /Users/mkyong/projects/test/JavaClassName.class
  Last modified 25 Aug 2022; size 414 bytes
  SHA-256 checksum b5addeb093c7d9106bbe1b400ea31c275201ff3aeda204aa365a27a2f44fb17c
  Compiled from "JavaClassName.java"
  public class JavaClassName
  minor version: 0
  major version: 61

  ##... too long

Or we can use the javap -verbose JavaClassName | grep major to display only the major version of the Java class file.

Java 17 (major version 61) compiled the JavaClassName.

Terminal

% javap -verbose JavaClassName | grep major

  major version: 61

Java 11 (55) compiled the JavaClassName.

Terminal

% javap -verbose JavaClassName | grep major

  major version: 55

Java 8 (52) compiled the JavaClassName.

Terminal

% javap -verbose JavaClassName | grep major

  major version: 52

References

About Author

author image
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter. If you like my tutorials, consider make a donation to these charities.

Comments

Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments