Java Program to get Operating System name and version

Java 8Object Oriented ProgrammingProgramming

Use the System.getProperty() method in Java to get the Operating System name and version.

It’s syntax is −

String getProperty(String key)

Above, the key is the name of the system property. Since, we want the OS name and version, therefore we will add the key as −

Operating System name - os.name
Operating System version - os.version

The following is an example −

Example

 Live Demo

public class Demo {
   public static void main(String []args){
      System.out.println("OS Name: " + System.getProperty("os.name"));
      System.out.println("OS Version: " + System.getProperty("os.version"));
   }
}

Output

OS Name: Linux
OS Version: 3.10.0-862.9.1.el7.x86_64
raja
Published on 21-Dec-2018 15:42:54
Advertisements