Java API to find out the JDK version a class file is compiled for?

前端 未结 8 997
星月不相逢
星月不相逢 2020-11-28 07:52

Are there any Java APIs to find out the JDK version a class file is compiled for? Of course there is the javap tool to find out the major version as mentioned in here. Howev

8条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-28 08:11

    basszero's approach can be done via the UNIX command line, and the "od(1)" command:

    % od -x HelloWorldJava.class |head -2
    0000000 feca beba 0000 3100 dc00 0007 0102 2a00
    0000020 6f63 2f6d 6e65 6564 6163 642f 6d65 2f6f
    

    "feca beba" is the magic number. The "0000 3100" is 0x31, which represents J2SE 5.0.

提交回复
热议问题