Module java.base
Package java.lang

Class Runtime.Version

  • All Implemented Interfaces:
    Comparable<Runtime.Version>
    Enclosing class:
    Runtime

    public static final classRuntime.VersionextendsObjectimplementsComparable<Runtime.Version>
    A representation of a version string for an implementation of the Java SE Platform. A version string consists of a version number optionally followed by pre-release and build information.

    Version numbers

    Aversion number,$VNUM, is a non-empty sequence of elements separated by period characters (U+002E). An element is either zero, or an unsigned integer numeral without leading zeros. The final element in a version number must not be zero. When an element is incremented, all subsequent elements are removed. The format is:

     [1-9][0-9]*((\.0)*\.[1-9][0-9]*)*

    The sequence may be of arbitrary length but the first four elements are assigned specific meanings, as follows:

     $FEATURE.$INTERIM.$UPDATE.$PATCH
    • $FEATURE — The feature-release counter, incremented for every feature release regardless of release content. Features may be added in a feature release; they may also be removed, if advance notice was given at least one feature release ahead of time. Incompatible changes may be made when justified.

    • $INTERIM — The interim-release counter, incremented for non-feature releases that contain compatible bug fixes and enhancements but no incompatible changes, no feature removals, and no changes to standard APIs.

    • $UPDATE — The update-release counter, incremented for compatible update releases that fix security issues, regressions, and bugs in newer features.

    • $PATCH — The emergency patch-release counter, incremented only when it's necessary to produce an emergency release to fix a critical issue.

    The fifth and later elements of a version number are free for use by platform implementors, to identify implementor-specific patch releases.

    A version number never has trailing zero elements. If an element and all those that follow it logically have the value zero then all of them are omitted.

    The sequence of numerals in a version number is compared to another such sequence in numerical, pointwise fashion;e.g., 10.0.4 is less than10.1.2. If one sequence is shorter than another then the missing elements of the shorter sequence are considered to be less than the corresponding elements of the longer sequence;e.g.,10.0.2 is less than10.0.2.1.

    Version strings

    Aversion string,$VSTR, is a version number $VNUM, as described above, optionally followed by pre-release and build information, in one of the following formats:

         $VNUM(-$PRE)?\+$BUILD(-$OPT)?     $VNUM-$PRE(-$OPT)?     $VNUM(+-$OPT)?

    where:

    • $PRE, matching([a-zA-Z0-9]+) — A pre-release identifier. Typicallyea, for a potentially unstable early-access release under active development, orinternal, for an internal developer build.

    • $BUILD, matching (0|[1-9][0-9]*) — The build number, incremented for each promoted build.$BUILD is reset to1 when any portion of $VNUM is incremented.

    • $OPT, matching([-a-zA-Z0-9.]+) — Additional build information, if desired. In the case of aninternal build this will often contain the date and time of the build.

    A version string10-ea matches$VNUM = "10" and$PRE = "ea". The version string10+-ea matches$VNUM = "10" and$OPT = "ea".

    When comparing two version strings, the value of$OPT, if present, may or may not be significant depending on the chosen comparison method. The comparison methodscompareTo() andcompareToIgnoreOptional() should be used consistently with the corresponding methodsequals() andequalsIgnoreOptional().

    Ashort version string,$SVSTR, often useful in less formal contexts, is a version number optionally followed by a pre-release identifier:

         $VNUM(-$PRE)?

    This is avalue-based class; use of identity-sensitive operations (including reference equality (==), identity hash code, or synchronization) on instances ofVersion may have unpredictable results and should be avoided.

    Since:
    9
    • Method Detail

      • feature

        public int feature()
        Returns the value of thefeature element of the version number.
        Returns:
        The value of the feature element
        Since:
        10
      • interim

        public int interim()
        Returns the value of theinterim element of the version number, or zero if it is absent.
        Returns:
        The value of the interim element, or zero
        Since:
        10
      • update

        public int update()
        Returns the value of theupdate element of the version number, or zero if it is absent.
        Returns:
        The value of the update element, or zero
        Since:
        10
      • patch

        public int patch()
        Returns the value of thepatch element of the version number, or zero if it is absent.
        Returns:
        The value of the patch element, or zero
        Since:
        10
      • major

        @Deprecated(since="10")public int major()
        Deprecated.
        As of Java SE 10, the first element of a version number is not the major-release number but the feature-release counter, incremented for every time-based release. Use thefeature() method in preference to this method. For compatibility, this method returns the value of thefeature element.
        Returns the value of the major element of the version number.
        Returns:
        The value of the feature element
      • minor

        @Deprecated(since="10")public int minor()
        Deprecated.
        As of Java SE 10, the second element of a version number is not the minor-release number but the interim-release counter, incremented for every interim release. Use theinterim() method in preference to this method. For compatibility, this method returns the value of theinterim element, or zero if it is absent.
        Returns the value of the minor element of the version number, or zero if it is absent.
        Returns:
        The value of the interim element, or zero
      • security

        @Deprecated(since="10")public int security()
        Deprecated.
        As of Java SE 10, the third element of a version number is not the security level but the update-release counter, incremented for every update release. Use theupdate() method in preference to this method. For compatibility, this method returns the value of theupdate element, or zero if it is absent.
        Returns the value of the security element of the version number, or zero if it is absent.
        Returns:
        The value of the update element, or zero
      • version

        public List<Integer> version()
        Returns an unmodifiableList of the integers represented in theversion number. TheList always contains at least one element corresponding to thefeature version number.
        Returns:
        An unmodifiable list of the integers represented in the version number
      • pre

        public Optional<String> pre()
        Returns the optionalpre-release information.
        Returns:
        The optional pre-release information as a String
      • optional

        public Optional<String> optional()
        Returnsoptional additional identifying build information.
        Returns:
        Additional build information as a String
      • compareTo

        public int compareTo​(Runtime.Version obj)
        Compares this version to another.

        Each of the components in theversion is compared in the following order of precedence: version numbers, pre-release identifiers, build numbers, optional build information.

        Comparison begins by examining the sequence of version numbers. If one sequence is shorter than another, then the missing elements of the shorter sequence are considered to be less than the corresponding elements of the longer sequence.

        A version with a pre-release identifier is always considered to be less than a version without one. Pre-release identifiers are compared numerically when they consist only of digits, and lexicographically otherwise. Numeric identifiers are considered to be less than non-numeric identifiers.

        A version without a build number is always less than one with a build number; otherwise build numbers are compared numerically.

        The optional build information is compared lexicographically. During this comparison, a version with optional build information is considered to be greater than a version without one.

        Specified by:
        compareTo in interface Comparable<Runtime.Version>
        Parameters:
        obj - The object to be compared
        Returns:
        A negative integer, zero, or a positive integer if thisVersion is less than, equal to, or greater than the givenVersion
        Throws:
        NullPointerException - If the given object isnull
      • compareToIgnoreOptional

        public int compareToIgnoreOptional​(Runtime.Version obj)
        Compares this version to another disregarding optional build information.

        Two versions are compared by examining the version string as described incompareTo(Version) with the exception that the optional build information is always ignored.

        This method provides ordering which is consistent withequalsIgnoreOptional().

        Parameters:
        obj - The object to be compared
        Returns:
        A negative integer, zero, or a positive integer if thisVersion is less than, equal to, or greater than the givenVersion
        Throws:
        NullPointerException - If the given object isnull
      • toString

        public String toString()
        Returns a string representation of this version.
        Overrides:
        toString in class Object
        Returns:
        The version string
      • equals

        public boolean equals​(Object obj)
        Determines whether thisVersion is equal to another object.

        TwoVersions are equal if and only if they represent the same version string.

        Overrides:
        equals in class Object
        Parameters:
        obj - The object to which thisVersion is to be compared
        Returns:
        true if, and only if, the given object is a Version that is identical to thisVersion
        See Also:
        Object.hashCode(),HashMap
      • equalsIgnoreOptional

        public boolean equalsIgnoreOptional​(Object obj)
        Determines whether thisVersion is equal to another disregarding optional build information.

        TwoVersions are equal if and only if they represent the same version string disregarding the optional build information.

        Parameters:
        obj - The object to which thisVersion is to be compared
        Returns:
        true if, and only if, the given object is a Version that is identical to thisVersion ignoring the optional build information