kushal
kushal

Reputation: 43

How can I determine java version installed on a system through java code?

How can I determine java version installed on a system through java code, if its not latest then download and install the required jre?

Upvotes: 0

Views: 173

Answers (5)

vainolo
vainolo

Reputation: 6987

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).

Upvotes: 4

barbiepylon
barbiepylon

Reputation: 911

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.

Upvotes: 0

QuantumBadger
QuantumBadger

Reputation: 196

It shouldn't be necessary to check the JRE version, since the bytecode will only run in a JRE at least as recent as the one it was compiled for.

Upvotes: 0

Jainathan Leung
Jainathan Leung

Reputation: 1157

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.

Upvotes: 0

trainoasis
trainoasis

Reputation: 6720

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

Upvotes: 0

Related Questions