Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference in properties java.runtime.version and java.version

For logging purposes I'm getting the Java version written in log while Java program is running.

I found out that I can get the version with

System.getProperty("java.runtime.version") -> 1.8.0_202-b08

and

System.getProperty("java.version") -> 1.8.0_202

Result obviously is missing the "build" information in other but are there any other difference besides the result? Any certain cases when I should be using the first option rather than the second?

like image 453
Jokkeri Avatar asked Mar 28 '19 13:03

Jokkeri


People also ask

Does JDK and JRE need to be same version?

If you Open your JDK folder (C:\Program Files\Java\jdk1. 8.0_152) , you can find JRE there. Coming to your Question; No it is not necessary to have both JDK and JRE of same version as we don't use both at the same time.

What is Java system properties?

Java™ system properties determine the environment in which you run your Java programs. They are similar to system values or environment variables in IBM® i. Starting an instance of a Java virtual machine (JVM) sets the values for the system properties that affect that JVM.

How do I find the Java version in runtime?

Use the system property java. version . Use the version() method of the Runtime class in Java.

Can JDK and JRE be different versions?

The JDK and JRE versions can be different on the same computer. Multiple JDK and JRE versions are allowed on the same computer; it is better to find out which version is configured in the system classpath to run or compile the Java program.


3 Answers

System Property Name | System Property Content  | Where Displayed in java version Output
---------------------|--------------------------|---------------------------------------
java.version         | product version          | Line one displays the product version
---------------------|--------------------------|---------------------------------------
java.runtime.version | product version          | Line one displays the product version
                     | product build identifier | Line two displays the build identifier

From the J2SE SDK/JRE Version String Naming Convention documentation:

  • The content of the java.runtime.version system property can be expanded (beyond that of the java.version system property) to include the build id.

It seems that the property value can therefore be equal to the java.runtime content or differentiate by the build id as already pointed out in the question.

Anyway, as previously stated in a comment to the question, the java.runtime.version property doesn't appear among the currently documented system properties.

like image 51
fantaghirocco Avatar answered Oct 25 '22 16:10

fantaghirocco


One is JDK version, java.version and as the name suggest other is JRE version, R for the runtime

like image 31
Rohail Usman Avatar answered Oct 25 '22 16:10

Rohail Usman


java.version is a product version information of Java Runtime environment(JRE). JRE is an implementation of the Java Virtual Machine which actually executes Java programs.

java.runtime.version is a product version along with build identifier of JRE.

like image 21
Aniket Sahrawat Avatar answered Oct 25 '22 16:10

Aniket Sahrawat