What is the difference in properties java.runtime.version and java.version
Asked Answered
Q

3

11

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?

Quarters answered 28/3, 2019 at 13:36 Comment(1)
I’m not sure you can rely on java.runtime.version anymore, considering it is not documented. I would avoid it altogether.Solan
J
9
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.

Jeth answered 28/3, 2019 at 13:40 Comment(0)
P
3

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.

Plata answered 28/3, 2019 at 13:44 Comment(0)
M
2

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

Multifaceted answered 28/3, 2019 at 13:44 Comment(1)
I'm not 100% sure but I think this might be a false assumption... As I run the app with only JRE (no JDK) both are working. I think fantaghirocco and Aniket Sahrawat are correct with their answer and the documentation VGR linked supports thisQuarters

© 2022 - 2024 — McMap. All rights reserved.