How to get the current OS name and version in Java

1 Answer

0 votes
public class OSInfo {
    public static void main(String[] args) {
        // Get the operating system name
        String osName = System.getProperty("os.name");

        // Get the operating system version
        String osVersion = System.getProperty("os.version");

        // Get the operating system architecture
        String osArch = System.getProperty("os.arch");

        System.out.println("Operating System: " + osName);
        System.out.println("Version: " + osVersion);
        System.out.println("Architecture: " + osArch);
    }
}




/*
run:

Operating System: Linux
Version: 6.6.72+
Architecture: amd64

*/

 



answered Mar 27, 2025 by avibootz

Related questions

1 answer 95 views
1 answer 100 views
1 answer 102 views
1 answer 105 views
1 answer 111 views
1 answer 74 views
1 answer 94 views
...