This week's book giveaways are in the AI and JavaScript forums.
We're giving away four copies each of GANs in Action and WebAssembly in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of GANs in ActionE this week in the AI forum
or WebAssembly in Action in the JavaScript 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 ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
Sheriffs:
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Joe Ess
  • salvin francis
  • fred rosenberger

find javac version that compiled my class

 
Greenhorn
Posts: 1
  • 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
 
Rancher
Posts: 43011
76
  • 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.
 
Marshal
Posts: 67412
257
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
. . . and welcome to JavaRanch, Eric
 
Ranch Hand
Posts: 148
  • 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
Posts: 43011
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

You can use javap -verbose MyClass to find the JVM version information.


Neat!
 
We're being followed by intergalactic spies! Quick! Take this tiny ad!
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!