Popular Tutorials
Start Learning JavaCertification Courses
Created with over a decade of experience and thousands of feedback.
Java Program to Determine the name and version of the operating system
In this example, we will learn to get the name and version of operating system in which the program run using Java.
To understand this example, you should have the knowledge of the following Java programming topics:
Example: Determine the Operating System
class Main {
public static void main(String[] args) {
// get the name of operating system
String operatingSystem = System.getProperty("os.name");
System.out.println(operatingSystem);
}
}
Output
Windows 10
In the above example, we have used the getProperty() method of the System class. Here, we have passed the os.name key as an argument to the method.
The method returns the property of the system specified by the key.
There are other keys that can be used to get other system properties. For example,
// returns the version of Operating system
// 10.0
System.getProperty("os.version");
Here, the key os.version returns the version of the operating system.
To learn more, visit the Java System Class.
Did you find this article helpful?