• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

finding javac version used to compile a class

 
Ranch Hand
Posts: 317
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Or just javap -verbose; the class version info is at the top.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic