java.lang.Runtime.Version Java Examples
The following examples show how to use
java.lang.Runtime.Version.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Basic.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
private static void test(String s, Integer major, Integer minor, Integer sec, String pre, Integer build, String opt) { Version v = testParse(s); testStr(v.toString(), s); testInt(v.major(), major); testInt(v.minor(), minor); testInt(v.security(), sec); testStr((v.pre().isPresent() ? v.pre().get() : ""), pre); testInt((v.build().isPresent() ? v.build().get() : 0), build); testStr((v.optional().isPresent() ? v.optional().get() : ""), opt); testVersion(v.version(), s); }
Example #2
Source File: VersionSchema.java From demo-java-x with MIT License | 6 votes |
public static void main(String[] args) { printSystemProperty("java.version"); printSystemProperty("java.runtime.version"); printSystemProperty("java.vm.version"); printSystemProperty("java.specification.version"); printSystemProperty("java.vm.specification.version"); Version version = Runtime.version(); System.out.println(); System.out.println("Reported by runtime: " + version); switch (version.major()) { case 9: System.out.println("Modularity!"); break; case 10: System.out.println("Value Types!"); break; } }
Example #3
Source File: JarFileSystem.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
JarFileSystem(ZipFileSystemProvider provider, Path zfpath, Map<String,?> env) throws IOException { super(provider, zfpath, env); lookup = path -> path; // lookup needs to be set before isMultiReleaseJar is called // because it eventually calls getEntry if (isMultiReleaseJar()) { int version; Object o = env.get("multi-release"); if (o instanceof String) { String s = (String)o; if (s.equals("runtime")) { version = Runtime.version().major(); } else { version = Integer.parseInt(s); } } else if (o instanceof Integer) { version = (Integer)o; } else if (o instanceof Version) { version = ((Version)o).major(); } else { throw new IllegalArgumentException("env parameter must be String, Integer, " + "or Version"); } lookup = createVersionedLinks(version < 0 ? 0 : version); setReadOnly(); } }
Example #4
Source File: CheckJavaVersion.java From journaldev with MIT License | 5 votes |
public static void main(String[] args) { // Java 10 Onwards 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")); /** Version class introduced in 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")); */ // For Java 8 or lower, use System Property //System.out.println(System.getProperty("java.version")); //System.out.println(System.getProperty("java.specification.version")); }
Example #5
Source File: Java10Version.java From journaldev with MIT License | 5 votes |
public static void main(String[] args) { 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")); }
Example #6
Source File: VersionApi.java From demo-java-x with MIT License | 5 votes |
public static void main(String[] args) { Version version = Runtime.version(); // these were all deprecated in Java 10 System.out.println(version.major() + "." + version.minor() + "." + version.security()); // use these instead System.out.println(version.feature() + "." + version.interim() + "." + version.update() + "." + version.patch()); }
Example #7
Source File: MultiReleaseJarTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@DataProvider(name="versions") public Object[][] createVersions() { return new Object[][] { {Version.parse("8"), 8}, {Version.parse("9"), 9}, {Version.parse("10"), 10}, {Version.parse("11"), 10}, {Version.parse("100"), 10} }; }
Example #8
Source File: Basic.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
private static void checkCompare(Version v0, Version v1, int expected, int actual) { if (Integer.signum(expected) == Integer.signum(actual)) { pass(); } else { fail(String.format("compare() (actual = %s) (expected = %s)", actual, expected), v0.toString(), v1.toString()); } }
Example #9
Source File: Basic.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
private static void testHashCode(Version v0, Version v1, boolean eq) { int h0 = v0.hashCode(); int h1 = v1.hashCode(); if (eq) { testInt(h0, h1); } else if (h0 == h1) { fail(String.format("hashCode() %s", h0), Integer.toString(h0), Integer.toString(h1)); } else { // !eq && (h0 != h1) pass(); } }
Example #10
Source File: Basic.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
private static void testEquals(Version v0, Version v1, boolean eq) { if (eq == v0.equals(v1)) { pass(); } else { fail("equals() " + Boolean.toString(eq), v0.toString(), v1.toString()); } }
Example #11
Source File: Basic.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
private static void testEqualsNO(Version v0, Version v1, boolean eq) { if (eq == v0.equalsIgnoreOptional(v1)) { pass(); } else { fail("equalsIgnoreOptional() " + Boolean.toString(eq), v0.toString(), v1.toString()); } }
Example #12
Source File: Basic.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
private static void testEHC(String s0, String s1, boolean eq, boolean eqNO, int cmp, int cmpNO) { Version v0 = Version.parse(s0); Version v1 = Version.parse(s1); testEquals(v0, v1, eq); testEqualsNO(v0, v1, eqNO); testHashCode(v0, v1, eq); testCompare(v0, v1, cmp); testCompareNO(v0, v1, cmpNO); }
Example #13
Source File: Basic.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
private static void testVersion() { Version current = Runtime.version(); String javaVer = System.getProperty("java.runtime.version"); // java.runtime.version == $VNUM(\-$PRE)?(\+$BUILD)?(-$OPT)? String [] jv = javaVer.split("\\+"); String [] ver = jv[0].split("-"); List<Integer> javaVerVNum = Arrays.stream(ver[0].split("\\.")) .map(Integer::parseInt) .collect(Collectors.toList()); if (!javaVerVNum.equals(current.version())) { fail("Runtime.version()", javaVerVNum.toString(), current.version().toString()); } else { pass(); } Optional<String> javaVerPre = (ver.length == 2) ? Optional.ofNullable(ver[1]) : Optional.empty(); if (!javaVerPre.equals(current.pre())) { fail("testCurrent() pre()", javaVerPre.toString(), current.pre().toString()); } else { pass(); } testEHC(current.toString(), javaVer, true, true, 0, 0); }
Example #14
Source File: Basic.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
private static void tryCatch(String s, Class<? extends Throwable> ex) { Throwable t = null; try { Version.parse(s); } catch (Throwable x) { if (ex.isAssignableFrom(x.getClass())) { t = x; } else x.printStackTrace(); } if ((t == null) && (ex != null)) fail(s, ex); else pass(); }
Example #15
Source File: TaskFactory.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
TaskFactory(JShell state) { this.state = state; this.compiler = ToolProvider.getSystemJavaCompiler(); if (compiler == null) { throw new UnsupportedOperationException("Compiler not available, must be run with full JDK 9."); } Version current = Version.parse(System.getProperty("java.specification.version")); if (INITIAL_SUPPORTED_VER.compareToIgnoreOptional(current) > 0) { throw new UnsupportedOperationException("Wrong compiler, must be run with full JDK 9."); } this.fileManager = new MemoryFileManager( compiler.getStandardFileManager(null, null, null), state); }
Example #16
Source File: Basic.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
private static void testCompareNO(Version v0, Version v1, int compare) { int cmp = v0.compareToIgnoreOptional(v1); checkCompare(v0, v1, compare, cmp); }
Example #17
Source File: Basic.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
private static void testCompare(Version v0, Version v1, int compare) { int cmp = v0.compareTo(v1); checkCompare(v0, v1, compare, cmp); }
Example #18
Source File: MultiReleaseJarTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
@Test(dataProvider="versions") public void testVersions(Version value, int expected) throws Throwable { versionEnv.put("multi-release", value); runTest(versionEnv, expected); }
Example #19
Source File: VersionApi.java From demo-java-x with MIT License | 4 votes |
public static void main(String[] args) { Version version = Runtime.version(); // these were all deprecated in Java 10 System.out.println(version.major() + "." + version.minor() + "." + version.security()); }
Example #20
Source File: Basic.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
private static Version testParse(String s) { Version v = Version.parse(s); pass(); return v; }