Java Program to Display the Name and Version of Operating System

In this Java program, we will learn to display operating system name and version using System properties. In Java, you can use the System class to get information about the operating system. Specifically, you can use the getProperty() method to get the os.name and os.version properties, which provide the name and version of the operating system, respectively.

Here is an example of how you can use the System class to determine the name and version of the operating system.


Java Program to Display the Name and Version of Operating System

public class OperatingSystemExample {
  public static void checkOperatingSystem() {
    String osName = System.getProperty("os.name");
    String osVersion = System.getProperty("os.version");
    System.out.println("OS name: " + osName);
    System.out.println("OS version: " + osVersion);
  }

  public static void main(String[] args) {
    checkOperatingSystem();
  }
}
Output
OS name: Mac OS X
OS version: 12.6.2

In this example, the checkOperatingSystem method uses the System.getProperty() method to get the value of the os.name and os.version properties. Then, it prints the name and version of the operating system to the console. The main method first calls the checkOperatingSystem method.

As you can see, the checkOperatingSystem method doesn't take any inputs, it uses the System.getProperty() method to get the name and version of the operating system, and then it prints them to the console. The output will vary depending on the system on which the code is running. It's worth noting that the os.name property will return the name of the operating system and the os.version will return the version of the operating system.