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

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("os.name");
    System.out.println(operatingSystem);

  }
}

Output

Windows 10

In the above example, we have used the getProperty() method of the System class. Here, we have passed the os.name 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
System.getProperty("os.version");

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

To learn more, visit the Java System Class.

Did you find this article helpful?

Our premium learning platform, created with over a decade of experience and thousands of feedbacks.

Learn and improve your coding skills like never before.

Try Programiz PRO
  • Interactive Courses
  • Certificates
  • AI Help
  • 2000+ Challenges