How to find the version a Java class was compiled with?

I wanted to lookup the Java version a class was compiled with. I was getting an error:

java.lang.UnsupportedClassVersionError: (MyClass) bad major version at offset=6

Thanks to StackOverflow I found out the following command I did not know before:

javap -verbose MyClass

The major version tells the Java version used. Here are some example values:

* Java 1.2 uses major version 46
* Java 1.3 uses major version 47
* Java 1.4 uses major version 48
* Java 5 uses major version 49
* Java 6 uses major version 50

I am blogging this for future reference.

Vasanth Dharmaraj is a Java Architect currently working for Western Union living in the Bay Area. He is interested in programming, gadgets, formula one... You can follow him on Twitter.

Posted in Java

Ads By Google