English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Java Basic Tutorial

Java Flow Control

Java Array

Java Object-Oriented (I)

Java Object-Oriented (II)

Java Object-Oriented (III)

Java Exception Handling

Java List

Java Queue (Queue)

Java Map Collection

Java Set Collection

Java Input/Output (I/O)/O)

Java Reader/Writer

Other Java Topics

Java Program to Get the Name and Version of the Operating System

Java Examples Comprehensive

In this example, we will learn how to use Java programs to get the current name and version of the operating system.

Example: java getting the 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,

//Returns the version of the operating system
// 10.0
System.getProperty("os.version");

Here, the key os.version returns the version of the operating system.

Java Examples Comprehensive