Codementor Events

How to retrive the JDK version that was used for a class compilation

Published Nov 04, 2019Last updated Nov 06, 2019

Background

We usually have some

How to?

Use the following command to get the compile information of the class.

javap -verbose [the class path]

You will get the version information like the following in the output

public class com.MyClass implements java.io.Serializable
  minor version: 0
  major version: 51
  flags: ACC_PUBLIC, ACC_SUPER

You can map the JDK version base on the major version and the minor version by the following table.

JDK 1.0 — major version 45 and minor version 3
DK 1.1 — major version 45 and minor version 3
JDK 1.2 — major version 46 and minor version 0
JDK 1.3 — major version 47 and minor version 0
JDK 1.4 — major version 48 and minor version 0
JDK 1.5 — major version 49 and minor version 0
JDK 1.6 — major version 50 and minor version 0
JDK 1.7 — major version 51 and minor version 0

Grep the correct line

When the output of the above command is too large for a big class, you need to grep the currect line from the output.
Windows

javap -verbose [class name] | findstr /R /C:"major version"

Linux

javap -verbose [class name] | gerp "major version"
Discover and read more posts from JamesPoon
get started
post commentsBe the first to share your opinion
Show more replies