How can I find the target Java version for a compiled class?

前端 未结 5 1542
萌比男神i
萌比男神i 2020-12-01 08:22

Duplicate:

Tool to read and display Java .class versions

If I have a compiled Java class, is there a way to tell from just the cla

5条回答
  •  天涯浪人
    2020-12-01 09:02

    I've found this on the net and it works.

    Every '.class' file starts off with the following:

    • Magic Number [4 bytes]
    • Version Information [4 bytes]

    A hexdump of a '.class' file compiled with each of the following options reveals:

    javac -target 1.1 ==> CA FE BA BE 00 03 00 2D
    javac -target 1.2 ==> CA FE BA BE 00 00 00 2E
    javac -target 1.3 ==> CA FE BA BE 00 00 00 2F
    javac -target 1.4 ==> CA FE BA BE 00 00 00 30

    Perhaps you could use this information to write your own '.class' file version checking utility, using Java, or perhaps a scripting or shell language ;) !

    I hope this helps.

    Anthony Borla

    From: http://bytes.com/groups/java/16603-how-determine-java-bytecode-version

提交回复
热议问题