"javap -v" - Major Version Code

Q

How to use the major version code in the "javap" output to determine the Java version of a Java class bytecode.

✍: FYIcenter

A

The bytecode of each Java class has a format version code called "major version" of 2 byres at byte offset 7. You can convert bytecode "major version" to the version of the Java environment where the bytecode is expected to run using the following conversion table:

...
Java 1.2 uses major version 46
Java 1.3 uses major version 47
Java 1.4 uses major version 48
Java  5  uses major version 49
Java  6  uses major version 50
Java  7  uses major version 51
Java  8  uses major version 52
Java  9  uses major version 53
Java 10  uses major version 54
Java 11  uses major version 55
Java 12  uses major version 56
Java 13  uses major version 57
Java 14  uses major version 58
Java 15  uses major version 59
Java 16  uses major version 60

If you use the verbose option "-v" or "-verbose" option of the "javap" command, this bytecode format version code will be printed output as "major version".

1. Compile HelloWorldFrame.java used in the last tutorial into a bytecode file, HelloWorldFrame.class:

> javac HelloWorldFrame.java 

2. Print out its "major version" as the bytecode format version using "javap" command with the "-v" option.

> javap -v HelloWorldFrame.class | grep "major version"

  major version: 59

According to the conversion table, HelloWorldFrame.class bytecode is expected to run in Java 15 environment.

 

"javac -source 10 -target 10" - Lower Java Version

"javap -v" - Verbose Mode

JDK "javap" Command

⇑⇑ Java Bytecode Tools

2021-09-09, 944🔥, 0💬