English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
In this example, we will learn how to use Java programs to get the current name and version of the operating system.
class Main { public static void main(String[] args) { //Get the name of the operating system 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 obtain other system properties. For example,
//Return the version of the operating system // 10.0 System.getProperty("os.version");
Here, the key os.version returns the version of the operating system.