How can I determine java version installed on a system through java code, if its not latest then download and install the required jre?
5 Answers
The first question is easy, use System.getProperty to get java.version:
System.getProperty("java.version")
The second part, I would instead show the user a popup dialog and ask him to download the latest (or required) version from Oracle (or some other source).
Comments
If you have windows you can check the version by using this script:
DOS script to check if the default java installed version is greater than 1.x
Comments
System.getProperty(); allows you to access such information. http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/System.html java.version is one such property. You can't programmatically reinstall the java environment. All you can do is ask the user to do it themselves, maybe give them a link to the download if you want.
Comments
As adChilds said in a comment, to get the current java version installed use System.getProperty("java.version") which returns a string or null.
As for the second question, one way you could do this is by packaging the installation executable for the version that you want with your application and then executing it through code.
System.getProperty("java.version");Also agree with millimoose.public bool isJavaInstalled() { return true; }