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

Tutoriel de base Java

Java 流程控制

Java 数组

Java 面向对象(I)

Java 面向对象(II)

Java 面向对象(III)

Gestion des exceptions Java

Java 列表(List)

Java Queue(队列)

Java Map集合

Java Set集合

Java 输入输出(I/O)

Java Reader/Writer

Java 其他主题

Java 程序获取操作系统的名称和版本

Java instance大全

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

Example: Java to get 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,

//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.

Java instance大全