Java program to determine the name and version of the operating system
Here's a Java program to determine the name and version of the operating system:
public class Main { public static void main(String[] args) { String osName = System.getProperty("os.name"); String osVersion = System.getProperty("os.version"); System.out.println("Operating system name: " + osName); System.out.println("Operating system version: " + osVersion); } }Source:www.theitroad.com
This program uses the System.getProperty
method to retrieve the values of two system properties: "os.name" and "os.version". These properties contain the name and version of the operating system, respectively. We then print these values to the console using System.out.println
.
When you run this program, you will see output similar to the following:
Operating system name: Windows 10 Operating system version: 10.0
Note that the values of these system properties may differ depending on the operating system that the program is running on.