`
dbaspider
  • 浏览: 257122 次
  • 性别: Icon_minigender_1
  • 来自: 南京
社区版块
存档分类
最新评论

java class version info howto

    博客分类:
  • JAVA
阅读更多


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
51       0           1.7

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.


分享到:
评论

相关推荐

    《Pearson.Java.How.To.Program.late.objects.version.10th.Edition》 高清完整英文PDF版

    Java How to Program (Late Objects), Tenth Edition is intended for use in the Java programming course. It also serves as a useful reference and self-study tutorial to Java programming. The Deitels’ ...

    Java 7 Concurrency Cookbook

    of how to use the new Java 7 Phaser class to synchronize tasks divided into phases. Chapter 4, Thread Executors will teach the readers to delegate the thread management to executors. They allow ...

    java反编工具java反编工具

    HOW TO USE DJ JAVA DECOMPILER: To decompile a single JAVA class file you can: 1.Select Open and load your desired class file. 2.Double-click the CLASS file you want to decompile. 3.Drag-and-drop ...

    javacv-platform-1.3.3-src

    To learn how to use the API, since documentation currently lacks, please refer to the Sample Usage section below as well as the sample programs, including two for Android (FacePreview.java and Record...

    Java邮件开发Fundamentals of the JavaMail API

    Instructions on how to download and install the JavaMail API are contained in the course. In addition, you will need a development environment such as the JDK 1.1.6+ or the Java 2 Platform, Standard...

    libsvm-3.17

    (how to cite LIBSVM) Our goal is to help users from other fields to easily use SVM as a tool. LIBSVM provides a simple interface where users can easily link it with their own programs. Main features...

    jclazz-1.2.2

    * Decompiler can be used to reproduce Java source code from compiled Java class file. It uses debug information to produce Java code which is nearly the same as original source file. Nevertheless...

    Learn.Java.for.Android.Development_Apress.2010+src

    Tools: You will learn how to use the JDK''s javac (compiler), java (application launcher), javadoc (Java documentation generator), and jar (Java archive creator, updater, and extractor) tools....

    UE(官方下载)

    How to configure syntax highlighting to highlight different file types automatically Project Settings Advanced Project Features - Using the UltraEdit/UEStudio project settings dialog Scripting ...

    Applying UML and Patterns-Latest Version 3

    Written for the developer with previous programming and design experience, Applying UML and Patterns combines UML, software patterns, and Java to illustrate the author's own design strategy....

    GWT in Action

    Chapter 16 shows you how to test your GWT code with JUnit and how to deploy your finished application to the server. You’ll learn how to organize your deployed code to reduce clutter on the server. ...

    pja_2.5.zip

    or when GDI resources are low on Windows, it is impossible to compute off-screen images with java.awt.Graphics methods under a JDK version , even if your program doesn't need to display these images....

    article-regex-primer.rar_The Few

    Pattern is a must to see how the Java regex patterns aredi erent from other languages such as Perl. Most of the functions discussed herin are from thejava.util.regex. Matcher class with a few from...

    jcompiler:使用 javax.tools.JavaCompiler 创建动态应用的演示项目

    jcompiler demo code of . # simple chinese version: how to run mvn install exec:java -Dexec.mainClass=examples.plotter.Plotter

    Visual C++ 编程资源大全(英文源码 控件)

    (35KB)&lt;END&gt;&lt;br&gt;22,edstream.zip this sample shows how to use the StreamIn() and StreamOut() members of the CRichEditCtrl class in MFC. (36KB)&lt;END&gt;&lt;br&gt;23,findrich.zip RICHFIND is a dialog-based ...

    VB编程资源大全(英文源码 控制)

    1.x/6.0 (Java) &lt;END&gt;&lt;br&gt;6 , ocxex.zip "This is a quick example I made to show you how to use Events and properties in a OCX."&lt;END&gt;&lt;br&gt;7 , news.exe This control aids as a complete Newsgroup ...

    stanford chinese segmentor

    Tokenization of raw text is a standard pre-processing step for many NLP tasks. For English, tokenization usually involves punctuation ... An example of how to train the segmenter is now also available.

    apktool documentation

    versionInfo - Used to repopulate the version information in AndroidManifest.xml since newer aapt requires version information to be passed via parameter compressionType - Used to determine the ...

    nao机器人java语音源码

    This summarises how to use the method. /// /// &lt;param name="name"&gt; The name of the method. /// &lt;returns&gt; A string that summarises the usage of the method. public String getUsage( String ...

    pentaho-kettle-master.zip

    How to build Pentaho Data Integration uses the maven framework. Pre-requisites for building the project: Maven, version 3+ Java JDK 1.8 This settings.xml in your /.m2 directory Building it ...

Global site tag (gtag.js) - Google Analytics