Get Operating System name in Java

Single statement is enough for getting OS name in Java. So simple.

Get OS Name



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

System.getProperty("os.name"): This method is used for getting the value of specified property in Java. The os.name property means the name of the OS.

Sample Output


Windows NT (unknown)

My OS is Windows 8 Release Preview, it does not properly detect it. Works for other operating systems.


Posted by at on

Tags: java.lang, System Properties,