How to find Java version used to compile a class and JRE version of IDE?

 There are many ways to find Java version used to compile a class (i.e class file version). One way is to use the  utility  “javap” which is included with the Java SDK as given below.

To  find Java version used to compile:

In UNIX / Linux :

To find major version  :    javap -verbose ClassName | grep major
To find minor version   :    javap -verbose ClassName | grep minor

Suppose to find the java version of the class ToLowerCase, give the following command in Linux

For eg.  :  javap -verbose ToLowerCase| grep major
output :  major version: 52

In Windows:

To find major version  :  javap -verbose ClassName | findstr major
To find minor version :   javap -verbose ClassName | find minor

For eg. :     javap -verbose ToLowerCase| findstr major
output :  major version: 52

Note : no need to give the .class extension with the file name.

You can also use the following command in Linux to check class version

$ file Proper1.class
output: ToLowerCase.class : compiled Java class data, version 52

if you use JDK 1.8 to compile the file, then the major version will be 52.  You can use the below table map  to find actual Java Version for the equivalent Major & Minor version

Java  Version Major Minor
1.1 45 3
1.2 46 0
1.3 47 0
1.4 48 0
1.5 49 0
1.6 50 0
1.7 51 0
1.8 52 0

To find Java Runtime Environment version:

There are many ways to check the Java Runtime Environment version.

a) For   Standalone, you can use the below command

 F:\Eclipse\JavaApps\bin\com\javaonline>java -version
java version “1.8.0_20”
Java(TM) SE Runtime Environment (build 1.8.0_20-b26)
Java HotSpot(TM) 64-Bit Server VM (build 25.20-b23, mixed mode)

b)  If you are using IDE like Eclipse or WSAD or RAD, you can see the Java Runtime version of the IDE in many ways .

1.     Add the below method to your code and  calling the same will give you  the Java Runtime version:


public static void getJavaVersion()
{
System.out.println(System.getProperty("java.runtime.version"));
} 

2. In Eclipse , Using menu   Help >About Eclipse > Installation Details>Configuration tab. Find out the  line that contains : java.runtime.version=..

jre version jre version2 jre version1

You may also like

Leave a Reply