In Java, we can use the os.name
system property to find the OS name and version. We can also use the os.version
system property to get the version.
To access the system properties, we can call System.getProperty
with the property name that we need to access.
class GetOSDetails {public static void main( String args[] ) {//Operating system nameSystem.out.println("Your OS name -> " + System.getProperty("os.name"));//Operating system versionSystem.out.println("Your OS version -> " + System.getProperty("os.version"));//Operating system architectureSystem.out.println("Your OS Architecture -> " + System.getProperty("os.arch"));}}
In the code above, we:
accessed the OS name
. We used the System.getProperty
method to pass the os.name
string as the argument.
also accessed OS version
and OS architecture
through the os.version
and os.arch
system properties respectively.
In addition, we can:
use java.version
to access Java version.
use java.home
to access Java installation.
use user.name
to access user account name.
class GetSystemProperties {public static void main( String args[] ) {//JRE version numberSystem.out.println(System.getProperty("java.version"));//Installation directory for Java Runtime Environment (JRE)System.out.println(System.getProperty("java.home"));//User account nameSystem.out.println(System.getProperty("user.name"));}}