List of Java class file format major version numbers?

前端 未结 4 1244
闹比i
闹比i 2020-11-22 12:18

I saw this list of major version numbers for Java in another post:

  • Java 1.2 uses major version 46
  • Java 1.3 uses major version 47
相关标签:
4条回答
  • 2020-11-22 12:32

    If you have a class file at build/com/foo/Hello.class, you can check what java version it is compiled at using the command:

    javap -v build/com/foo/Hello.class | grep "major"
    

    Example usage:

    $ javap -v build/classes/java/main/org/aguibert/liberty/Book.class | grep major
      major version: 57
    

    According to the table in the OP, major version 57 means the class file was compiled to JDK 13 bytecode level

    0 讨论(0)
  • 2020-11-22 12:36

    These come from the class version. If you try to load something compiled for java 6 in a java 5 runtime you'll get the error, incompatible class version, got 50, expected 49. Or something like that.

    See here in byte offset 7 for more info.

    Additional info can also be found here.

    0 讨论(0)
  • 2020-11-22 12:41

    I found a list of Java class file versions on the Wikipedia page that describes the class file format:

    http://en.wikipedia.org/wiki/Java_class_file#General_layout

    Under byte offset 6 & 7, the versions are listed with which Java VM they correspond to.

    0 讨论(0)
  • 2020-11-22 12:48

    If you're having some problem about "error compiler of class file", it's possible to resolve this by changing the project's JRE to its correspondent through Eclipse.

    1. Build path
    2. Configure build path
    3. Change library to correspondent of table that friend shows last.
    4. Create "jar file" and compile and execute.

    I did that and it worked.

    0 讨论(0)
提交回复
热议问题