Join our newsletter for the latest updates.

Java Program to Determine the name and version of the operating system

In this example, we will learn to get the name and version of operating system in which the program run using Java.

To understand this example, you should have the knowledge of the following Java programming topics:

Example: Determine the Operating System

class Main {
  public static void main(String[] args) {

    // get the name of operating system
    String operatingSystem = System.getProperty("");



Windows 10

In the above example, we have used the getProperty() method of the System class. Here, we have passed the key as an argument to the method.

The method returns the property of the system specified by the key.

There are other keys that can be used to get other system properties. For example,

// returns the version of Operating system
// 10.0

Here, the key os.version returns the version of the operating system.

To learn more, visit the Java System Class.