Java get build version

Class 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

A version 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:

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.
Читайте также:  Html выглядит по разному

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 than 10.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 than 10.0.2.1 .

Version strings

A version 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)?
  • $PRE , matching ([a-zA-Z0-9]+) — A pre-release identifier. Typically ea , for a potentially unstable early-access release under active development, or internal , for an internal developer build.
  • $BUILD , matching (0|62*) — The build number, incremented for each promoted build. $BUILD is reset to 1 when any portion of $VNUM is incremented.
  • $OPT , matching ([-a-zA-Z0-9.]+) — Additional build information, if desired. In the case of an internal build this will often contain the date and time of the build.

A version string 10-ea matches $VNUM = «10» and $PRE = «ea» . The version string 10+-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 methods compareTo() and compareToIgnoreOptional() should be used consistently with the corresponding methods equals() and equalsIgnoreOptional() .

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

This is a value-based class; programmers should treat instances that are equal as interchangeable and should not use instances for synchronization, or unpredictable behavior may occur. For example, in a future release, synchronization may fail.

Method Summary

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.

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.

Parses the given string as a valid version string containing a version number followed by pre-release and build information.

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.

Methods declared in class java.lang.Object

Method Details

parse

Parses the given string as a valid version string containing a version number followed by pre-release and build information.

feature

interim

update

patch

major

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 the feature() method in preference to this method. For compatibility, this method returns the value of the feature element.

minor

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 the interim() method in preference to this method. For compatibility, this method returns the value of the interim element, or zero if it is absent.

security

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 the update() method in preference to this method. For compatibility, this method returns the value of the update element, or zero if it is absent.

version

Returns an unmodifiable List of the integers represented in the version number. The List always contains at least one element corresponding to the feature version number.

pre

build

optional

compareTo

Compares this version to another. Each of the components in the version 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.

compareToIgnoreOptional

Compares this version to another disregarding optional build information. Two versions are compared by examining the version string as described in compareTo(Version) with the exception that the optional build information is always ignored. This method provides ordering which is consistent with equalsIgnoreOptional() .

toString

equals

Determines whether this Version is equal to another object. Two Version s are equal if and only if they represent the same version string.

equalsIgnoreOptional

Determines whether this Version is equal to another disregarding optional build information. Two Version s are equal if and only if they represent the same version string disregarding the optional build information.

hashCode

Report a bug or suggest an enhancement
For further API reference and developer documentation see the Java SE Documentation, which contains more detailed, developer-targeted descriptions with conceptual overviews, definitions of terms, workarounds, and working code examples. Other versions.
Java is a trademark or registered trademark of Oracle and/or its affiliates in the US and other countries.
Copyright © 1993, 2023, Oracle and/or its affiliates, 500 Oracle Parkway, Redwood Shores, CA 94065 USA.
All rights reserved. Use is subject to license terms and the documentation redistribution policy.
DRAFT 21-ea+31-LTS-2444

Источник

Как проверить версию Java

Проверьте версию Java, Проверьте версию java терминал mac, Как проверить версию java в программе, Класс версии Java 10, Сборка версии Java, Как проверить версию java, java-версия, пример java-версии.

Иногда нам нужно проверить версию Java во время выполнения программы Java. Мы могли бы разрабатывать наш проект на локальной машине, но развертывать его на удаленном сервере, поэтому нам нужно проверить версию java, чтобы убедиться, что наша программа будет работать нормально.

Как проверить версию Java?

Мы можем легко проверить версию java с помощью командной строки. Мы можем использовать любую из следующих команд для печати версии java.

$java -version $java --version

java -версия выведет версию в поток ошибок и завершит работу.

java —version выведет свою версию в поток вывода и завершит работу.

Обратите внимание, что каталог JDK или JRE bin должен находиться в переменной PATH, иначе вы получите сообщение об ошибке, так как команда java не найдена .

У меня на MacBook установлены Java 8 , Java 9 и Java 10, поэтому давайте посмотрим, каков результат выполнения команды проверки версии java.

Вывод Java Версии 10

$ java -version java version "10.0.1" 2018-04-17 Java(TM) SE Runtime Environment 18.3 (build 10.0.1+10) Java HotSpot(TM) 64-Bit Server VM 18.3 (build 10.0.1+10, mixed mode) $

Обратите внимание , что версия имеет форму $FEATURE.$INTERIM.$UPDATE.$PATCH , поэтому из приведенных выше выходных данных мы можем сделать вывод, что функция равна 10, Промежуточная-0, Обновление равно 1, а исправление равно 0.

Во второй строке то, что вы видите после+, называется номером сборки. Таким образом, сборка составляет 10. Обратите внимание, что это соглашение об именовании появилось в самой Java 10. Так что в старых версиях Java все будет немного по-другому.

Вывод Java Версии 9

$ java -version java version "9" Java(TM) SE Runtime Environment (build 9+181) Java HotSpot(TM) 64-Bit Server VM (build 9+181, mixed mode) $

Вывод Java Версии 8

$ cd /Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/bin/ $ ./java -version java version "1.8.0_131" Java(TM) SE Runtime Environment (build 1.8.0_131-b11) Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode) $

Вывод Java версии 11

$ java -version openjdk version "11.0.1" 2018-10-16 OpenJDK Runtime Environment 18.9 (build 11.0.1+13) OpenJDK 64-Bit Server VM 18.9 (build 11.0.1+13, mixed mode) $

Можем ли мы проверить версию java программно?

Что делать, если мы хотим убедиться, что наш код работает на совместимой версии java, и, возможно, выйти из приложения, если это не так. Мы также можем проверить версию java в программе. Ниже приведены фрагменты кода, в которых показано, как программно проверить версию java.

Код проверки версии Java для Java 10

Version version = java.lang.Runtime.version(); System.out.println("Java Version = "+version); System.out.println("Java Version Feature Element = "+version.feature()); System.out.println("Java Version Interim Element = "+version.interim()); System.out.println("Java Patch Element Version = "+version.patch()); System.out.println("Java Update Element Version = "+version.update()); System.out.println("Java Version Build = "+version.build().get()); System.out.println("Java Pre-Release Info = "+version.pre().orElse("NA"));
Java Version = 10.0.1+10 Java Version Feature Element = 10 Java Version Interim Element = 0 Java Patch Element Version = 0 Java Update Element Version = 1 Java Version Build = 10 Java Pre-Release Info = NA

Обратите внимание, что вывод программы совпадает с выводом команды java-версия .

Код проверки версии Java для Java 9

Version version = java.lang.Runtime.version(); System.out.println("Java Version = "+version); System.out.println("Java Major Version = "+version.major()); System.out.println("Java Minor Version = "+version.minor()); System.out.println("Java Security Version = "+version.security()); System.out.println("Java Version Build = "+version.build().get()); System.out.println("Java Version Pre-Release Info = "+version.pre().orElse("NA"));

Версия класс был впервые представлен в Java 9, в версии java 10 основные, второстепенные и свойства безопасности были устаревшими. Если мы выполним приведенный выше фрагмент кода для Java 9, мы получим следующий вывод:

$ java JavaVersion Java Version = 9+181 Java Major Version = 9 Java Minor Version = 0 Java Security Version = 0 Java Version Build = 181 Java Version Pre-Release Info = NA

Версия Java Проверьте код для версий Java 8 или ниже

Для Java 8 или ниже мы можем использовать свойства системы, чтобы получить подробную информацию о версии Java.

System.out.println(System.getProperty("java.version")); System.out.println(System.getProperty("java.specification.version"));

Источник

Оцените статью