how to check jre version using java application
Solution 1
You can use System.getProperty(String key); method with "java.version"
as key.
String version = System.getProperty("java.version");
Example output:
1.6.0_30
The available keys can find at here.
Solution 2
static public void main(String[] arg) throws IOException
{
PrintStream out = System.out;
Properties pro = System.getProperties();
Set set = pro.entrySet();
Iterator<Map.Entry<String , String >> itr = set.iterator();
while(itr.hasNext())
{
Map.Entry ent = itr.next();
out.println(ent.getKey() + " -> " + ent.getValue() + "\n");
}
}
Use System.getProperty("java.version")
or System.getProperty("java.runtime.version")
to get installed version of java.
The above code snipped helps you find out more details such as java vendor name , OS etc.
Solution 3
System.getProperty("java.version")
Note: It will return current jvm's version, jvm on which this code is executing, If you have java6 & java7 installed on your computer and you are running this code on java 7 it will show you version 7
rahul
Updated on July 18, 2022Comments
-
rahul almost 2 years
i have made an application in JDK7, but the jre6 is still using in the market, and if i send my jar file to someone with jre6, it wont work, is there a way that application checks the jre version and if it doesn't compat then ask user to update..
-
rahul about 12 yearswill that work if jre is mismatching...cause in my case the jre file just gives the splash screen and closes itself if i use jre6.. i need some fool proof solution!!
-
rahul about 12 yearswill that work if jre is mismatching...cause in my case the jre file just gives the splash screen and closes itself if i use jre6.. i need some fool proof solution!!
-
rahul about 12 yearswill that work if jre is mismatching...cause in my case the jre file just gives the splash screen and closes itself if i use jre6.. i need some fool proof solution!!
-
Sibster about 12 yearsI cant verify it atm but if you put this in a class that gets loaded before any jre7 specific classes are loaded it should work
-
rahul about 12 yearsits not showing any exception...the program wont run...i had made an exception error dialog box.....but nothing works..
-
rahul about 12 yearsits not giving any exception....its just not running...i have made a error dialog in case of any exception....so i havent shown anything....