This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Java in General and the fly likes which jdk was used to compile this class? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "which jdk was used to compile this class?" Watch "which jdk was used to compile this class?" New topic
Author

which jdk was used to compile this class?

seb petterson
Ranch Hand

Joined: Mar 04, 2005
Posts: 118
I am just wondering how I can find out which jdk (vendor and version) was used to compile a certain class.

Seb
Jean-Sebastien Abella
Ranch Hand

Joined: Jul 29, 2005
Posts: 60
first 4 bytes of file is 0xCAFEBABE
then next 4 is the version....
have a look at this web site
ClassFile specification
seb petterson
Ranch Hand

Joined: Mar 04, 2005
Posts: 118
Originally posted by Jean-Sebastien Abella:
first 4 bytes of file is 0xCAFEBABE
then next 4 is the version....
have a look at this web site
ClassFile specification


Thank you, so if the next four bytes are: 0000 002e what version is that? 1.4.3.2?

Do you know if the vendor is hiding there somewhere too?
[ August 12, 2005: Message edited by: seb petterson ]
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
As a shortcut you can get the info Jean-Sebastien just referred to using javap:

javap -verbose ClassName

The major and minor version appear near the beginning of the output. Unfortunately the numbers that you get here are not the same as the JDK version. E.g. for a file compiled using JDK 1.5.0_04, I get the class file version as 49.0. I these numbers correlate to specific JDKs. However it's difficult to find the documentation allowing us to determine exactly what this correlation is. There's some info in a footnote here, with a partly-updated version here (found via Clarifications and Amendments to the Java Virtual Machine Specification). The relevant info is in the footnote on p. 95: "For k >= 2 implementations of version 1.k of the Java 2 platform can support class file formats of versions in the range 45.0 through 44+k.0 inclusive." Yeesh. Couldn't they just put a nice table somewhere?

Anyway, that basically means that JDK 1.2 compiles to class file format 46.0; JDK 1.3 is 47.0; 1.4 is 48.0 and 49.0. (Unless you compile using the -target modifier to specify a different version.) I'm not sure if the minor version (the .0) is really used any more; seems like the answer is no. You can experiment using different versions of JDK 1.4.X to verify this.

I don't think there's any way to identify the vendor of the compiler from the class file, or to tell the difference between JDK 1.5.0_01 and JDK 1.5.0_04, for example.

Of course, if we had a knowledgeable compiler author on hand in the forum this week, they may be able to provide better info.
[ August 12, 2005: Message edited by: Jim Yingst ]

"I'm not back." - Bill Harding, Twister
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
0000 002e is hexadecimal for 2*16 + 14 = 46. Looks like it was compiled using JDK 1.2. (Which was actually called an SDK I guess, but never mind.)
 
wood burning stoves
 
subject: which jdk was used to compile this class?