Home » Java programming language

How to detect the OS (operating system) name in Java?

Java os.name property example: Here, we are going to learn how to detect and print the operating system (OS) name in Java?
Submitted by IncludeHelp, on September 18, 2019

To detect the OS (operating system) name in Java, we use the getProperties() method, which is defined in System class, while calling the method, we need to pass the property name to get the OS (operating system name).

The property to get the OS name is: "os.name"

The method call is: System.getProperties("os.name");

Java code to detect and print the OS (operating system) name

// Java program to demonstrate the example of 
// getProperties() method of System Class

import java.lang.*;
import java.util.Properties;

public class Main {
    public static void main(String[] args) {
        String os_name = null;
        os_name = System.getProperty("os.name");
        System.out.println("OS name is: " + os_name);
    }
}

Output

OS name is: Linux


Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.