Although latest version of JDK is already JDK 1.6, many servers in production might be still running with JRE 1.4. It is irritating to get error when running a Java program that compile with newer version of JDK.
So it will be good if there is a way to check the Java class file is compiled into which version.
And this is not difficult. The command is as below (if the class file you want to inspect is MyClass.class):
javap -verbose MyClassAnd below is the example output:
Compiled from "MyClass.java"
public class MyClass extends java.lang.Object
SourceFile: "MyClass.java"
minor version: 0
major version: 50
Constant pool:
const #1 = class #2; // MyClass
const #2 = Asciz MyClass;
const #3 = class #4; // java/lang/Object
const #4 = Asciz java/lang/Object;
.
.
Below is the details of JDK version (source: Check the class version):
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.6Update 3 Oct 2014:
J2SE 8 = 52 (0x34 hex),
J2SE 7 = 51 (0x33 hex),
source: http://en.wikipedia.org/wiki/Java_class_file#General_layout
21 comments:
The amazingly useful javap strikes again. Thanks!
Thanks for the info. Really useful. Saved my 15 minutes of grief today (more time for google reader ;)
Ajay
thanks for the information, this is exactly what I'm looking for.
Also, on Linux/Unix, you can do
$ file Foo.class
Foo.class: compiled Java class data, version 48.0
With some class files, you would get back 10 pages of output from javap.
:)
Thanks a lot. It was very useful.
thanks for the useful info
thank you and Google, it really helps me.
Really useful tip.
Thank you very much for the helpful info.
The java application I want to introspect says "minor 3 major 3". Hopefully it has been compiled using java 1.0.
Thank you. It very useful. Good tip.
awesome information. the blog post that keeps informing huh? kinda like the present that keeps on giving. ok I'm talking rubbish
thanks dude
Awesome info! Thank you so much. Clear, concise and CORRECT!
it's always good to have these help online. Every time we forget, or don't know, always can find such helpful resources. Cool.
Thanks.
God Bless you :). Such simple tips save time, effort and frustration.
very useful , good post
Nice tip, easy to find version of class file. By the way I have also shared few points about class file here
Thanks. It's very useful
Thanks. It helps me
Thank you very much..postings are helpful.
Thanks for the info. Helped me a lot.
Post a Comment