Home >Java >javaTutorial >How to Determine the JDK Version Used to Compile a .class File?

How to Determine the JDK Version Used to Compile a .class File?

DDD
DDDOriginal
2024-12-16 07:12:15802browse

How to Determine the JDK Version Used to Compile a .class File?

How to Check the JDK Version Used to Compile a .class File

Checking the Version

When encountering the error, "Bad version number in .class file," it can be helpful to determine the version of the .class files in question. Here's a cross-platform approach to checking the major JDK version used to compile a .class file:

Unix/Linux

javap -verbose MyClass | grep "major"

Windows

javap -verbose MyClass | findstr "major"

Interpreting the Output

The output of the above command will include a line similar to:

major version: 50

This value corresponds to the major JDK version used to compile the .class file. Refer to the table below for a mapping between major version numbers and Java versions:

Java Version Major Version
1.2 46
1.3 47
1.4 48
5 49
6 50
7 51
8 52
9 53
10 54
11 55
12 56
13 57
14 58
15 59
16 60
17 61
18 62
19 63
20 64
21 65
22 66

The above is the detailed content of How to Determine the JDK Version Used to Compile a .class File?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn