Sunday, February 9, 2014

Get OS name and OS architecture (actually JVM architecture) using Java code

To get OS name (something like Windows 7, Linux, ...) and OS architecture (like amd64, x86, i386, ...), we can call the method System.getProperty() with parameter of "os.name" and "os.arch".

example:
Get OS name and OS architecture (actually JVM architecture)
Get OS name and OS architecture (actually JVM architecture)

package javaosarch;

public class JavaOsArch {

    public static void main(String[] args) {
        System.out.println("OS name : "+System.getProperty("os.name"));
        System.out.println("OS arch : "+System.getProperty("os.arch"));
    }
    
}

But, please note that System.getProperty("os.arch") actually return JVM architecture, not OS architecture. read more: Beware when detecting 32 and 64 bit OS's in Java

No comments:

Post a Comment