Display the Operating System name in Java


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

It’s syntax is −

String getProperty(String key)

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

os.name

Example

 Live Demo

public class Demo {
    public static void main(String[] args) {
       System.out.print("Operating System: ");
       System.out.println(System.getProperty("os.name"));
    }
}

Output

Operating System: Linux

karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know

Updated on: 26-Jun-2020

3K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements