📜  Java9 Version-String Scheme

📅  最后修改于: 2020-10-14 00:44:33             🧑  作者: Mango

Java 9新版本字符串方案

Java版本字符串是一种包含版本特定信息的格式。此版本字符串包含主要,次要,安全性和修补程序更新版本。

在Java 9中,引入了一个新的版本字符串方案,如下所示。

$MAJOR.$MINOR.$SECURITY.$PATCH

$MAJOR

此版本号显示Java版本的重大更改。当发生重大变化时,它会增加。就像Java 8到Java 9一样。每个主要版本都包含现有功能的新功能。

$ MINOR

此版本号显示Java版本中的较小更改,并随每个较小的更新而增加。这些更新可以是错误修复,对标准API的修订等。如果将更新发布到Java 9,则版本字符串格式将为Java 9.1(包含主要版本和次要版本号)。

$SECURITY

此版本号表示安全更新,并且每个新的安全更新都会增加。安全更新可能是关键修复程序和安全问题。如果对Java 9发布了任何安全更新,则版本字符串格式将类似于:Java 9.1.5(包含主要版本,次要版本和安全版本号)。

$ PATCH

对于每个安全性和高优先级的客户修复程序,此版本号都会增加,这些版本已一起测试。如果将修补程序发布到Java 9,则版本字符串格式将为Java 9.1.5.1(包含主要,次要,安全性和修补程序发布编号)。

注意:如果任何$ SECURITY,$ MINOR或$ MAJOR版本号递增,则每次$ PATCH版本号重置为零。

如果$ MAJOR版本号增加,则$ MINOR和$ SECURITY版本号将设置为零。但是,当$ MINOR版本号增加时,后续的$ SECURITY版本号不必设置为零。

在Java 9中,添加了Runtime.Version类以获取Java版本信息。此类包含方法并具有以下签名。

Java Runtime.Version类Signature(签名)

public static final class Runtime.Version extends Object implements Comparable

Java Runtime.Version类方法

Modifier and Type Method Description
Optional build() It returns the build number.
int compareTo(Runtime.Version obj) It compares this version to another.
int compareToIgnoreOptional(Runtime.Version obj) It compares this version to another disregarding optional build information.
boolean equals(Object obj) It determines whether this Version is equal to another object.
boolean equalsIgnoreOptional(Object obj) It determines whether this Version is equal to another disregarding optional build information.
int hashCode() It returns the hash code of this version.
int major() It returns the major version number.
int major() It returns the minor version number or zero if it was not set.
Optional optional() It returns optional additional identifying build information.
static Runtime.Version parse(String s) It parses the given string as a valid version string containing a version number followed by pre-release and build information.
Optional pre() It returns the optional pre-release information.
int security() It returns the security version number or zero if it was not set.
String toString() It returns a string representation of this version.
List version() It returns an unmodifiable List of the integer numerals contained in the version number.

Java Runtime.Version示例

public class VersionInfoExample {
public static void main(String[] args) {
Runtime.Version version = Runtime.version();      // Getting runtime version instance
System.out.println("Current version is "+version);   // Getting current Java version
System.out.println("Major version number "+version.major()); // Getting major version number
System.out.println("Minor version number "+version.minor()); // Getting minor version number
System.out.println("Security version number "+version.security()); // Getting security version number
System.out.println("Pre-released information "+version.pre()); // Getting pre-release version information
System.out.println("Build Number "+version.build()); // Getting Optional build number
}
}

输出:

Current version is 9.0.1+11
Major version number 9
Minor version number 0
Security version number 1
Pre-released information Optional.empty
Build Number Optional[11]