Search code examples
javasystem-properties

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?


Solution

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