Win a copy of Succeeding with AI this week in the Artificial Intelligence and Machine Learning forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Junilu Lacar
  • Tim Cooke
  • Jeanne Boyarsky
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Piet Souris
  • salvin francis
  • fred rosenberger
  • Frits Walraven

How to find which version of java was used to compile particular java class.

Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a compiled java class file say, which i have taken from somewhere else. Now I would like to know with which java (JDK) version that class file was compiled.

Is there any way to find out above thing (JDK version used for compiling)?

Thanks in advance.
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not sure is this will help you. Every class file has a format. the first 4 bytes have the magic number and the next 4 represent the version. Please search for class file format for more details. Don't know of any utility that gives this info straightaway.

Java Cowboy
Posts: 16084
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, that is not really possible.

See this thread for a discussion of the same question.
Pras Tiwari
Ranch Hand
Posts: 186
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Got one utility that reads bytes from .class file and interpret it:-

try {
String filename = "C:\\pal\\WTP_Workspace\\JavaSocketBridge\\src\\Test.class";
DataInputStream in = new DataInputStream(new FileInputStream(
int magic = in.readInt();
if (magic != 0xcafebabe) {
System.out.println(filename + " is not a valid class!");
int minor = in.readUnsignedShort();
int major = in.readUnsignedShort();
System.out.println(filename + ": " + major + " . " + minor);
} catch (IOException e) {
System.out.println("Exception: " + e.getMessage());

Here the combination of major and minor version will reveal the java version against which class has been compiled.

Possible major/minor value are :

Can you shoot lasers out of your eyes? Don't look at this tiny ad:
Try Free Java/.NET Libraries for Word Excel PowerPoint and PDF
    Bookmark Topic Watch Topic
  • New Topic