Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java check latest version programmatically

Tags:

java

Goal: check java's version on a machine (I can get this from java -version). Compare it with latest available from java website

I would like to know if there is any way I can check for latest Java releases assuming that I have JRE/JDK installed on a machine.

If I can do this through Java itself, my solution would become platform independent. I could use java.net.URL class to send a request to Java website and get the HTML, however the response would be dynamic as Oracle can change their website and styles and possibly will have maintenance issues in long run.

I have looked at javatester.org, but I would not want it through an applet but through command line (which I can add to a script).

Through javacpl.exe, I can schedule periodic checks, but I would like to do it on demand.

like image 522
Chris Avatar asked Oct 18 '12 10:10

Chris


People also ask

How do I know if I have the latest Java version?

The Java version can be found in the Java Control Panel. Under the General tab in the Java Control Panel, the version is available through the About section. A dialog appears (after clicking About) showing the Java version.

What is the current JVM version?

Update (June 23, 2022): Java 17 is the latest version of Java available offering long term support (LTS). While most applications today are using Java 8 or 11, here are some reasons to consider upgrading to Java 17...

Is JVM version same as Java version?

The java. vm. version is the jvm version number, something like "25.0-b70" whereas the java. version is the normal java language version you're used to seeing "1.8.


2 Answers

The answer is actually quite simple. http://java.com/en/download/testjava.jsp issues a request to http://java.com/applet/JreCurrentVersion2.txt. That file currently contains a single version number: '1.7.0_11'...which is the latest and greatest, indeed.

Java code example

try (BufferedReader br = new BufferedReader(new InputStreamReader(new URL(
    "http://java.com/applet/JreCurrentVersion2.txt").openStream()))) {
  String fullVersion = br.readLine();
  String version = fullVersion.split("_")[0];
  String revision = fullVersion.split("_")[1];
  System.out.println("Version " + version + " revision " + revision);
} catch (IOException e) {
  // handle properly
}

Update 2014-03-20

Eventhough Java 8 was recently released http://java.com/applet/JreCurrentVersion2.txt currently still returns 1.7.0_51.

Update 2016-07-13

Looks like we need to come back to this every few months... Currently you need to scan http://java.com/en/download/installed8.jsp for a JavaScript variable latest8Version. So, you could run curl -s https://java.com/en/download/installed8.jsp | grep latest8Version.

Update 2018-08-19

http://javadl-esd-secure.oracle.com/update/baseline.version is another hot spot as mentioned in some other answer.

like image 67
Marcel Stör Avatar answered Sep 29 '22 19:09

Marcel Stör


An URL very similar to the now defunct "JreCurrentVersion2.txt":

http://javadl-esd-secure.oracle.com/update/baseline.version

The contents of the link look like this:

1.8.0_111
1.7.0_121
1.6.0_131
1.5.0_99
1.4.2_43

You can easily parse the contents to find the latest JRE versions.

like image 42
Juck Keng Lam Avatar answered Sep 29 '22 19:09

Juck Keng Lam