// shall I write some keywords here to boost search engine ranking?

Wednesday, November 21, 2007

Determine Java class file version

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 MyClass
And 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.6
Update 3 Oct 2014:

J2SE 8 = 52 (0x34 hex),
J2SE 7 = 51 (0x33 hex),

source: http://en.wikipedia.org/wiki/Java_class_file#General_layout

22 comments:

Peter said...

The amazingly useful javap strikes again. Thanks!

Ajay said...

Thanks for the info. Really useful. Saved my 15 minutes of grief today (more time for google reader ;)

Ajay

Frank said...

thanks for the information, this is exactly what I'm looking for.

Rob_E said...

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

Hanuathena said...

Thanks a lot. It was very useful.

Kaushal said...

Wonderful

arjun said...

thanks for the useful info

Khoa Ho said...

thank you and Google, it really helps me.

Prashanth M.S said...

Really useful tip.

Anonymous said...

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.

dariusgeo said...

Thank you. It very useful. Good tip.

chrome said...

awesome information. the blog post that keeps informing huh? kinda like the present that keeps on giving. ok I'm talking rubbish

thanks dude

Anonymous said...

Awesome info! Thank you so much. Clear, concise and CORRECT!

Jackie said...

it's always good to have these help online. Every time we forget, or don't know, always can find such helpful resources. Cool.

Jackie said...

Thanks.

Bali said...

God Bless you :). Such simple tips save time, effort and frustration.

Anonymous said...

very useful , good post

Javin @ replace string in java said...

Nice tip, easy to find version of class file. By the way I have also shared few points about class file here

satyanarayana said...

Thanks. It's very useful

satyanarayana said...

Thanks. It helps me

Anonymous said...

Thank you very much..postings are helpful.

Rohit said...

Thanks for the info. Helped me a lot.