Issue
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
Solution
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.
The list of backports of JDK-8293124 Update OS detection code to recognize Windows 11 suggests this should have been fixed in Java 8 update 8u311, 8u321, and 8u331. But given I still get the old result in 1.8.0_332 (Temurin) and 1.8.0_345 (Temurin), either this fix was reverted or only available in specific builds (e.g. Oracle's). It also lists the - not yet released - openjdk8u362, so maybe this fix will arrive in 1.8.0_362.
Answered By - Mark Rotteveel
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.