• Post Reply Bookmark Topic Watch Topic
  • New Topic

Given a class file, which JDK was used?  RSS feed

 
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Bartender
Posts: 9443
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have a look at the Java Virtual Machine Specification, Class File Format. The major and minor version are what you are looking for.
 
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Renato Losio
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys, thanks for the info! Very useful indeed.

Thanks again.

Renato
 
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
...
 
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look at the 5th, 6th, 7th and 8th byte in the class file to derive the major and minor version number.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!