查看java class文件版本的方法

查看java class文件版本的方法

url: http://wangsong76.iteye.com/blog/264071

 

查看的方法: 
1.先装一个DJ Java Decompiler 这个工具网上到处都是,主要就是反编译java class文件。 
2.在DJ Java Decompiler的菜单中View->class version info,就会弹出对话框如: 

Major Version: 49 
Minor Version: 0 
参照下面的引用,可知class由jdk1.5编译而来。 

jackpk已经亲测,以上方法非常实用。

关于JDK版本,参见:

unsupported major.minor version 解决方法》(http://blog.csdn.net/jackpk/article/details/19755119

引用
http://www.rgagnon.com/javadetails/java-0544.html  
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.0  
45       3           1.1  
46       0           1.2  
47       0           1.3  
48       0           1.4  
49       0           1.5  
50       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.class  
ClassVersionChecker.class: 49 . 0  

from The Java Virtual Machine Specification  

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.  

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值