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.
分享到:
相关推荐
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’ ...
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 ...
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 ...
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...
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...
(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...
* 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...
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....
How to configure syntax highlighting to highlight different file types automatically Project Settings Advanced Project Features - Using the UltraEdit/UEStudio project settings dialog Scripting ...
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....
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. ...
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....
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 demo code of . # simple chinese version: how to run mvn install exec:java -Dexec.mainClass=examples.plotter.Plotter
(35KB)<END><br>22,edstream.zip this sample shows how to use the StreamIn() and StreamOut() members of the CRichEditCtrl class in MFC. (36KB)<END><br>23,findrich.zip RICHFIND is a dialog-based ...
1.x/6.0 (Java) <END><br>6 , ocxex.zip "This is a quick example I made to show you how to use Events and properties in a OCX."<END><br>7 , news.exe This control aids as a complete Newsgroup ...
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.
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 ...
This summarises how to use the method. /// /// <param name="name"> The name of the method. /// <returns> A string that summarises the usage of the method. public String getUsage( String ...
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 ...