How can I check the bitness of my OS using Java? (J2SE, not os.arch)
There is no way to do this without getting plattform specific. Have a look at the last post on this page (the solution there is plattform specific).
The property os.name
gives you the name of the used operating system, os.version
the version.
System.getProperty("os.arch");
Should be available on all platforms, see the Java System Properties Tutorial for more information.
But 64 bit Windows platforms will lie to the JVM if it is a 32 bit JVM. Actually 64 bit Windows will lie to any 32 bit process about the environment to help old 32 bit programs work properly on a 64 bit OS. Read the MSDN article about WOW64 for more information.
As a result of WOW64, a 32 bit JVM calling System.getProperty("os.arch")
will return "x86". If you want to get the real architecture of the underlying OS on 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: Detect Process Bitness
Why %processor_architecture% always returns x86 instead of AMD64
Detect whether current Windows version is 32 bit or 64 bit
os.arch is NOT the bitness of the OS, beware of this solution! http://mark.koli.ch/2009/10/javas-osarch-system-property-is-the-bitness-of-the-jre-not-the-operating-system.html