`
dbaspider
  • 浏览: 264548 次
  • 性别: 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.


分享到:
评论

相关推荐

    abe.jar工具,解决Don't know how to process version 5

    在遇到“Don't know how to process version 5”的错误时,这通常意味着Abe.jar不支持当前APK的版本格式,这可能是由于APK格式的更新或Abe.jar自身的版本过旧。 首先,让我们深入了解一下Java和Android的关系。Java...

    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 ...

    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...

    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...

    How to Use Hibernate JPA

    - 在实体类中使用`@Version`注解来实现乐观锁。 - 或者在执行更新操作时使用`LockModeType.PESSIMISTIC_WRITE`来实现悲观锁。 #### 建立 Updateuser 功能 1. **创建 UpdateUser 功能** - 创建`UserService`类,...

    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...

    Class-4---First-Java-Program.rar_Java编程_Java_

    "How to Install JDK.doc" 提供了详细步骤,JDK是Java编程的基础,包含了编译器、调试器和其他必要的工具。在Windows环境下,你需要下载与操作系统版本匹配的JDK安装包,然后按照安装向导进行操作。安装过程中记得...

    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....

    java英文笔试

    **Answer**: Single inheritance in Java refers to a situation where one class inherits from only one other class. This is the default form of inheritance supported by Java. For example, if Class B ...

    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 ...

    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....

    How-to-install-openjdk-on-ubuntu.rar_Ubuntu!_openjdk

    java -version ``` 这将显示你系统上安装的Java版本信息。 4. 设置默认Java版本: 如果你安装了多个Java版本,可能需要设置默认版本。首先列出所有可选的Java版本: ``` sudo update-alternatives --list java ```...

    TestNG_Maven_how_to

    public class MyTest { @Parameters({"param1", "param2"}) public void testMethod(String param1, int param2) { // 测试逻辑 } } ``` 要在Maven中传递这些参数,可以使用`systemPropertyVariables`配置: ```...

    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 ...

    GWT in Action

    This chapter covers the use of the GWT module's XML configuration file to manage resources, alter project layout, invoke class replacement and generation, and include server components. It also ...

Global site tag (gtag.js) - Google Analytics