How can I check the bitt of my OS using Java? (J2SE, not os.arch)

I am developing a software application that checks what software you have installed, but for this I need to know whether the OS is a 32-bit or 64-bit OS. I tried System.getProperty ("os.arch"); but then I read that this command only shows the JDK / JRE bit, not the OS itself. If you could tell me how to find out which OS is used (Windows 7, Mac OS, Ubuntu, etc.), That would be just awesome C:

+20
java operating-system
Jan 20 '11 at 15:02
source share
4 answers
System.getProperty("os.arch"); 

It should be available on all platforms, see Java System Properties Guide for more information.

But 64-bit Windows platforms will lie in the JVM if it is a 32-bit JVM. In fact, 64-bit Windows will lie in any 32-bit environmental process to help older 32-bit programs run correctly on a 64-bit OS. Read the MSDN article on WOW64 for more information .

As a result, the WOW64 32-bit JVM call to System.getProperty("os.arch") will return "x86". If you want to get the real architecture of the underlying OS in Windows, use the following logic:

 String arch = System.getenv("PROCESSOR_ARCHITECTURE"); String wow64Arch = System.getenv("PROCESSOR_ARCHITEW6432"); String realArch = arch != null && arch.endsWith("64") || wow64Arch != null && wow64Arch.endsWith("64") ? "64" : "32"; 

See also:

HOWTO: Bitness Process Detection

Why% processor_architecture% always returns x86 instead of AMD64

Determine if the current version of Windows is 32-bit or 64-bit .

+41
May 09 '11 at 18:13
source share
+2
May 9 '11 at 15:07
source share

There is no way to do this without getting a specific form. Look at the last post on this page (the solution is platform specific).

The os.name property gives you the name of the operating system you are using, os.version version.

+1
Jan 20 2018-11-18T00:
source share

You can check by calling

 System.getProperty("sun.arch.data.model"); 

This line returns 32 or 64, which identifies whether the JVM is 32 or 64 bits.

-one
Jan 20 2018-11-18T00:
source share



All Articles