aspose file tools
The moose likes Beginning Java and the fly likes Given a class file, which JDK was used? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Given a class file, which JDK was used?" Watch "Given a class file, which JDK was used?" New topic
Author

Given a class file, which JDK was used?

Renato Losio
Ranch Hand

Joined: Nov 23, 2005
Posts: 99
Hello.

Given a class file, is there a quick way to know which JDK should be used to run it?

Basically I would like to know if it's compiled for JDK 5 or also support 1.4

Cheers,

Renato


Renato Losio - www.arsenio.it - renatoweb@arsenio.it
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8259

Have a look at the Java Virtual Machine Specification, Class File Format. The major and minor version are what you are looking for.


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18670
A quick way to get this info is with the javap tool (which comes with the JDK):

javap -verbose MyClass

gives you something like:

The major and minor version are what you want. These are described in the link Joe gave, specifically in footnote 1 - except unfortunately that only covers up through JDK 1.2, the most current release aat the time the JVM spec 2nd edition came out. The most current info is accessible through "Maintenance Infoormation", which eventually leads here. Footnote 1 now reads:

"1 The Java virtual machine implementation of Sun�s JDK release 1.0.2 supports
class file format versions 45.0 through 45.3 inclusive. Sun�s JDK releases 1.1.X can support class file formats of versions in the range 45.0 through 45.65535 inclusive. 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. "

Which means:

JDK 1.2 uses major version 46
JDK 1.3 uses major version 47
JDK 1.4 uses major version 48
JDK 1.5 uses major version 49
JDK 1.6 uses major version 50


"I'm not back." - Bill Harding, Twister
Renato Losio
Ranch Hand

Joined: Nov 23, 2005
Posts: 99
Hi guys, thanks for the info! Very useful indeed.

Thanks again.

Renato
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14669
    
  11

javap ? This is cool. Except that when I tried it on file compiled with 1.4, I have :
Compiled from "DoubleComboJSON.java"
public class ajax.DoubleComboJSON extends javax.servlet.http.HttpServlet
SourceFile: "DoubleComboJSON.java"
minor version: 0
major version: 0
Constant pool:
...


[My Blog]
All roads lead to JavaRanch
Tony Morris
Ranch Hand

Joined: Sep 24, 2003
Posts: 1608
Look at the 5th, 6th, 7th and 8th byte in the class file to derive the major and minor version number.


Tony Morris
Java Q&A (FAQ, Trivia)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Given a class file, which JDK was used?
 
Similar Threads
Version of a class !!
clarifications please...
Class files related
How to find which version of java was used to compile particular java class.
How many class' are there in JDK?