博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Check the class version
阅读量:7222 次
发布时间:2019-06-29

本文共 2101 字,大约阅读时间需要 7 分钟。

hot3.png

The first 4 bytes are a magic number, 0xCAFEBABe, to identify a valid class file then the next 2 bytes identify the class format version (major and minor).

Possible major/minor value :

major  minor Java platform version  45       3           1.045       3           1.146       0           1.247       0           1.348       0           1.449       0           1.550       0           1.6
import java.io.*;public class ClassVersionChecker {    public static void main(String[] args) throws IOException {        for (int i = 0; i < args.length; i++)            checkClassVersion(args[i]);    }    private static void checkClassVersion(String filename)        throws IOException    {        DataInputStream in = new DataInputStream         (new FileInputStream(filename));        int magic = in.readInt();        if(magic != 0xcafebabe) {          System.out.println(filename + " is not a valid class!");;        }        int minor = in.readUnsignedShort();        int major = in.readUnsignedShort();        System.out.println(filename + ": " + major + " . " + minor);        in.close();    }}
> java ClassVersionChecker ClassVersionChecker.classClassVersionChecker.class: 49 . 0

from 

magic

The magic item supplies the magic number identifying the class file format; it has the value 0xCAFEBABE.

minor_version, major_version

The values of the minor_version and major_version items are the minor and major version numbers of this class file.Together, a major and a minor version number determine the version of the class file format. If a class file has major version number M and minor version number m, we denote the version of its class file format as M.m. Thus, class file format versions may be ordered lexicographically, for example, 1.5 < 2.0 < 2.1.

A Java virtual machine implementation can support a class file format of version v if and only if v lies in some contiguous range Mi.0 v Mj.m. Only Sun can specify what range of versions a Java virtual machine implementation conforming to a certain release level of the Java platform may support.

转载于:https://my.oschina.net/uniquejava/blog/140702

你可能感兴趣的文章
Ext JS4学习笔记1——环境的搭建
查看>>
.net MVC3实现不同的角色用不同的登录页面
查看>>
Scala学习笔记-12
查看>>
eq与gt的妙用
查看>>
哈哈哈
查看>>
projectEuler pro10
查看>>
聚焦“云开发圆桌论坛”,大前端Serverless大佬们释放了这些讯号!
查看>>
数学模板
查看>>
c#中英文混合字符串截取指定长度
查看>>
.NetCore应用多个target framework
查看>>
pdfminer获取整页文本
查看>>
windows服务器多端口Redis安装步骤
查看>>
第二次作业心得
查看>>
爬虫——请求库之requests
查看>>
android子线程更新UI,与主Thread一起工作
查看>>
50行实现简易HTTP服务器
查看>>
细讲递归(recursion)
查看>>
进程和进程间通信
查看>>
微处理器的两种结构比较
查看>>
ORACLE EXPIRED(GRACE)
查看>>