To get the version of the Java runtime environment (JRE) in which your Java program is running, you can use the System.getProperty()
method and pass it the "java.version" property as an argument. This method returns a string containing the version of the JRE.
Here's an example of how you can get the Java version in a Java program:
import java.lang.System; // ... String javaVersion = System.getProperty("java.version");
In this example, the javaVersion
variable holds the version of the JRE as a string.
You can also use the System.getProperties()
method to get a list of all system properties, including the Java version. This method returns a Properties
object containing the key-value pairs of the system properties. To get the Java version, you can use the getProperty()
method of the Properties
object and pass it the "java.version" property as an argument.