File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
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
Author

finding javac version used to compile a class

peter cooke
Ranch Hand

Joined: Mar 16, 2004
Posts: 314
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
Sheriff

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

http://www.rgagnon.com/javadetails/java-0544.html


"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
sscce.org
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Mar 22, 2005
Posts: 41060
    
  43
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.


Ping & DNS - my free Android networking tools app
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: finding javac version used to compile a class
 
Similar Threads
compilation
Regarding Sun Java System Application Server9.1 Issue with JVM5
Specific match rule
Collections Frame work
why can't some people play my game