How to find the JVM version from a program?
System.getProperty("java.version")
returns what you need.
You can also use JMX if you want:
ManagementFactory.getRuntimeMXBean().getVmVersion()
How to find the JVM version from a program ... with even more details?
I don't have IBM Java, only Oracle Java. When I do java -version
I get:
java version "1.8.0_91"
Java(TM) SE Runtime Environment (build 1.8.0_91-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.91-b14, mixed mode)
I can reproduce that exact output with this code:
System.out.printf("java version \"%s\"%n" +
"%s (build %s)%n" +
"%s (build %s, %s)%n",
System.getProperty("java.version"),
System.getProperty("java.runtime.name"),
System.getProperty("java.runtime.version"),
System.getProperty("java.vm.name"),
System.getProperty("java.vm.version"),
System.getProperty("java.vm.info"));
There might be other information added by IBM Java. Why not try dumping all system properties and see for yourself:
new TreeMap<>(System.getProperties()).entrySet().forEach(e ->
System.out.printf("%s = %s%n", e.getKey(), e.getValue())
);
Determine java version used to call a program
You should use System.getProperty("java.version")
. This will give you the version of the currently running JVM as a String
, And you can then check for a prefix like 1.5
or 1.6
, and you have the version of Java.
Also check this question, and the docs for System.getProperty(...)
.
Hope this helps.
How can I tell if I'm running in 64-bit JVM or 32-bit JVM (from within a program)?
You retrieve the system property that marks the bitness of this JVM with:
System.getProperty("sun.arch.data.model");
Possible results are:
"32"
– 32-bit JVM"64"
– 64-bit JVM"unknown"
– Unknown JVM
As described in the HotSpot FAQ:
When writing Java code, how do I distinguish between 32 and 64-bit operation?
There's no public API that allows you to distinguish between 32 and 64-bit operation. Think of 64-bit as just another platform in the write once, run anywhere tradition. However, if you'd like to write code which is platform specific (shame on you), the system property sun.arch.data.model has the value "32", "64", or "unknown".
An example where this could be necessary is if your Java code depends on native libraries, and you need to determine whether to load the 32- or 64-bit version of the libraries on startup.
How to find if the JVM installed on the machine is HotSpot or JRockit on Windows OS
You may use command java -version
from command prompt, which prints JVM information
Java: How to check jdk version?
Use this condition
Integer.parseInt(System.getProperty("java.version").split("\\.")[1]) >= 5
to check the Java version.
Getting Java version at runtime
These articles seem to suggest that checking for 1.5
or 1.6
prefix should work, as it follows proper version naming convention.
Sun Technical Articles
- J2SE SDK/JRE Version String Naming Convention
- Version 1.5.0 or 5.0?
- "J2SE also keeps the version number 1.5.0 (or 1.5) in some places that are visible only to developers, or where the version number is parsed by programs"
- "
java.version
system property"
- "
- "J2SE also keeps the version number 1.5.0 (or 1.5) in some places that are visible only to developers, or where the version number is parsed by programs"
- Version 1.6.0 Used by Developers
- "Java SE keeps the version number 1.6.0 (or 1.6) in some places that are visible only to developers, or where the version number is parsed by programs."
- "
java.version
system property"
- "
- "Java SE keeps the version number 1.6.0 (or 1.6) in some places that are visible only to developers, or where the version number is parsed by programs."
How do I check a clients Java Version?
System.getProperty("java.version");
Related Topics
Where Are Compiled Jsp Java (*_Jsp.Java) Files
Replace All Occurrences of a String Using Stringbuilder
Spring Autowiring Using @Configurable
Java Jtextfield with Input Hint
How to Force Browser to Download File
Setting Jvm Heap Size at Runtime
What Code Folding Plugins Work on Eclipse 3.6
Java: How to Convert a Utc Timestamp to Local Time
How to Store Java Objects in Httpsession
How to Set Request Encoding in Tomcat
Compiler Error When Declaring a Variable Inside If Condition and No Curly Braces
JPA Hibernate One-To-One Relationship
Rounding Bigdecimal to *Always* Have Two Decimal Places
How to Solve Circular Reference in JSON Serializer Caused by Hibernate Bidirectional Mapping
Java "Lambda Expressions Not Supported at This Language Level"
Is There a 'Block Until Condition Becomes True' Function in Java