Home > Software design >  System.getProperty("os.name") and System.getProperty("os.version") returning win
System.getProperty("os.name") and System.getProperty("os.version") returning win

Time:06-18

System.getProperty("os.name") and System.getProperty("os.version") returning windows 10, 10.0, in windows 11 machine

If anyone knows Java code to get the Windows version without using any command, please help or attach Java code here.

openjdk version "1.8.0_322"
OpenJDK Runtime Environment Corretto-8.322.06.1 (build 1.8.0_322-b06)
OpenJDK 64-Bit Server VM Corretto-8.322.06.1 (build 25.322-b06, mixed mode)
class Demo
{
    public static void main(String g[])
    {
        System.out.println(" os name = " System.getProperty("os.name"));
        System.out.println(" os version = " System.getProperty("os.version"));
    }
}

output:

os name = Windows 10
os version = 10.0

CodePudding user response:

On Java 11 (11.0.15) and Java 17 (17.0.3), System.getProperty("os.name") returns Windows 11, but "os.version" still reports 10.0, because that is actually the version that Microsoft (still) uses for Windows 11.

For example, Windows System Information reports:

OS Name Microsoft Windows 11 Pro
Version 10.0.22000 Build 22000

This is similar to what is shown in your screenshot.

Java 8 (1.8.0_332) does unfortunately still report Windows 10. I have looked at the available system properties and environment variables in Java 8, but there doesn't seem to be a property or environment variable that allows you to detect you're using Windows 11 instead of Windows 10.

  • Related