How to get operating system name and version in java

This example shows you to get the operating system information from java programme.

To get the operating system information throw java programme, you can use the some system property like ‘os.name’, ‘os.version’, ‘os.arch’.

Below is the example code of getting operating system information from java.

package com.java.connect.lang;
 
//How to get operating system name and version in java
public class OpertingSystemInformationExample {
    public static void main(String[] args) {
        // The key 'os.name' for getting operating system name
        String name = "os.name";
        // The key 'os.version' for getting operating system version
        String version = "os.version";
        // The key 'os.arch' for getting operating system architecture
        String architecture = "os.arch";
 
        System.out.println("Operating system name : "
                + System.getProperty(name));
        System.out.println("Operating system version : "
                + System.getProperty(version));
        System.out.println("Operating system architecture: "
                + System.getProperty(architecture));
    }
}

The output of the above example in my system as:

Operating system name : Windows NT (unknown)
Operating system version : 6.1
Operating system architecture: x86