File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

find javac version that compiled my class

 
Eric Krieger
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can use System.getProperty( "java.version" ) to find and display the JRE under which my program is running, but is there a straightforward way [I am a java newbie] to find the JDK version of 'javac' that was used to compile my .java file ? I am using Sun java exclusively.

-Eric
 
Ulf Dittmer
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, that's not possible. What is possible, however is to find out for which version of Java the code was compiled; in other words, which JRE version is needed to run it. Frequently that's sufficient information.

If it is in your case, have a look at the bytes 6 and 7 (counting from 0) in the class file. They encode the targeted JRE version. See the table in this Wikipedia entry for details of what the numbers mean.

You can change the targeted JRE version during compilation by using javac's "-source" and "-target" switches.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47300
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
. . . and welcome to JavaRanch, Eric
 
Bill Cruise
Ranch Hand
Posts: 148
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use javap -verbose MyClass to find the JVM version information.

Example output:

Compiled from "MyClass.java"
public class MyClass extends java.lang.Object
SourceFile: "MyClass.java"
minor version: 0
major version: 50

Constant pool:
const #1 = class #2; // MyClass
const #2 = Asciz MyClass;
const #3 = class #4; // java/lang/Object
const #4 = Asciz java/lang/Object;
.
.

Use this table to decode the major/minor version:

[ July 14, 2008: Message edited by: Bill Cruise ]
 
Ulf Dittmer
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use javap -verbose MyClass to find the JVM version information.

Neat!
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic