public class Version extends Object implements Comparable<Version>
$VNUM, is a non-empty sequence of non-negative integer numerals, without leading or trailing zeroes, separated by period characters (U+002E); i.e., it matches the regular expression
^[1-9][0-9]*(((\.0)*\.[1-9][0-9]*)*)*$. The sequence may be of arbitrary length but the first three elements are assigned specific meanings, as follows:
$MAJOR --- The major version number,
incremented for a major release that contains significant new features as
specified in a new edition of the Java SE Platform Specification,
e.g., JSR 337
for Java SE 8. Features may be removed in a major release, given
advance notice at least one major release ahead of time, and incompatible
changes may be made when justified. The
$MAJOR version number of
JDK 8 was
$MAJOR version number of JDK 9
$MINOR --- The minor version number,
incremented for a minor update release that may contain compatible bug
fixes, revisions to standard APIs mandated by a Maintenance Release of
the relevant Platform Specification, and implementation features outside
the scope of that Specification such as new JDK-specific APIs, additional
service providers, new garbage collectors, and ports to new hardware
$MINOR is reset to zero when
$SECURITY --- The security level,
incremented for a security-update release that contains critical fixes
including those necessary to improve security.
$SECURITY is reset
to zero only when
$MAJOR is incremented. A higher
$SECURITY for a given
$MAJOR value, therefore,
always indicates a more secure release, regardless of the value of
The fourth and later elements of a version number are free for use by downstream consumers of the JDK code base. Such a consumer may, e.g., use the fourth element to identify patch releases which contain a small number of critical non-security fixes in addition to the security fixes in the corresponding security release.
The version number does not include trailing zero elements;
$SECURITY is omitted if it has the value zero, and
$MINOR is omitted if both
the value zero.
The sequence of numerals in a version number is compared to another
such sequence in numerical, pointwise fashion; e.g.,
is less than
9.10.0. If one sequence is shorter than another then
the missing elements of the shorter sequence are considered to be zero;
9.1.2 is equal to
18.104.22.168 but less than
A version string
$VSTR consists of a version number
$VNUM, as described above, optionally followed by pre-release and
build information, in the format
A pre-release identifier. Typically
ea, for an early-access
release that's under active development and potentially unstable, or
internal, for an internal developer build.
When comparing two version strings, a string with a pre-release
identifier is always less than one with an equal
$VNUM but no such
identifier. Pre-release identifiers are compared numerically when they
consist only of digits, and lexicographically otherwise. Numeric
identifiers are less than than non-numeric identifiers.
(0|[1-9][0-9]*) --- The build number, incremented for each promoted build.
$BUILD is reset to
1 when any portion of
When comparing two version strings with equal
$PRE components, a string without a
component is always less than one with a
$BUILD numbers are compared numerically.
--- Additional build information, if desired. In the case of an
internal build this will often contain the date and time of the
When comparing two version strings the value of
present, is always ignored.
A short version string (
$SVSTR), often useful in less
formal contexts, is simply
$VNUM optionally ended with
|Modifier and Type||Method and Description|
Returns the build number.
Compares this version to another.
Determines whether this
Returns the hash code of this version.
Returns the major version number.
Returns the minor version number or zero if it was not set.
Returns optional additional identifying build information.
Returns the optional pre-release information.
Returns the security version number or zero if it was not set.
Returns a string representation of this version.
s- A string to interpret as a version
IllegalArgumentException- If the given string cannot be interpreted a valid version
NullPointerException- If the given string is
NumberFormatException- If an element of the version number or the build number cannot be represented as an
public static Version current()
System.getProperty("java.version")as a Version.
System.getProperty("java.version")as a Version
public int major()
public int minor()
public int security()
Listof the integer numerals contained in the version number. The
Listalways contains at least one element corresponding to the major version number.
public int compareTo(Version ob)
Two versions are compared 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 zero. If the version numbers are equal, then 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 lexiographically otherwise. Numeric identifiers are considered to be less than non-numeric identifiers. A version without a build value is always less than one with a build value; otherwise build numbers are compared numerically. The optional build information is always ignored.
A version is not comparable to any other type of object.
public String toString()
public boolean equals(Object ob)
Versionis equal to another object.
Versions are equal if and only if they represent the
same version string.
This method satisfies the general contract of the
public int hashCode()
This method satisfies the general contract of the
Copyright © 2005, 2015, Oracle and/or its affiliates. All rights reserved.