Java Program to get Operating System name and version

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

Updated on: 30-Jul-2019

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started