File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes finding javac version used to compile a class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "finding javac version used to compile a class" Watch "finding javac version used to compile a class" New topic

finding javac version used to compile a class

peter cooke
Ranch Hand

Joined: Mar 16, 2004
Posts: 317
I have several provided 3rd party jar file. One class is throwing a java.lang.UnsupportedClassVersionError "Unsupported major.minor v" (sorry not permitted to post actual exception). I have only seen this when a class is compiled in a newer jdk than what is running the class.

I need to know what version of javac compiled the classes them.

javap tells me methods and variables but does not tell me what the compiler version was.

Thoughts suggestions?

CIAO Peter M. Cooke
marc weber

Joined: Aug 31, 2004
Posts: 11343

In a Java class file, the first 4 bytes are the magic number (0xCAFEBABE). The next two bytes are the respective major and minor versions.

See this page for an example of how to read these...

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
David Newton

Joined: Sep 29, 2008
Posts: 12617

Or just javap -verbose; the class version info is at the top.
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
Just to be picky: There's no way to find out the version of the Java compiler used to compile a class (which is what you're asking). The best you can do is find out the Java version for which the code has been compiled, which is not necessarily the same, but which is usually what you're interested in. Just a little something to keep in mind; check out the documentation of the "-source" and "-target" switches of the "javac" executable for more detail.
I agree. Here's the link:
subject: finding javac version used to compile a class
It's not a secret anymore!