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 -
Operating System version - os.version

The following is an example −


 Live Demo

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


OS Name: Linux
OS Version: 3.10.0-862.9.1.el7.x86_64
Published on 21-Dec-2018 11:12:54