English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
In this example, we will learn how to use a Java program to get the current operating system's name and version.
class Main { public static void main(String[] args) { //Get the operating system's name String operatingSystem = System.getProperty("os.name"); System.out.println(operatingSystem); } }
Output Result
Windows 10
In the above example, we used the getProperty() method of the System class. Here, we pass the os.name key as a parameter to this method.
This method returns the system property specified by the key.
There are other keys that can be used to get other system properties. For example,
//Return the operating system's version // 10.0 System.getProperty("os.version");
Here, the key os.version returns the operating system's version.