0

I know how to check whether the JVM is 32 or 64-bit is running on a current Machine using java program. But is there any possibility to know if the OS on current machine is 32-bit or 64-bit.

Please let me know how to determine using Java Program.

  • You may want to check out this link https://stackoverflow.com/questions/228477/how-do-i-programmatically-determine-operating-system-in-java – Matt Nov 07 '17 at 15:01

2 Answers2

1
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";

This question was answered by ChrisH.

Alex Blasco
  • 793
  • 11
  • 22
  • 1
    Here is the link to the answer : https://stackoverflow.com/questions/4748673/how-can-i-check-the-bitness-of-my-os-using-java-j2se-not-os-arch/5940770#5940770 – asyard Aug 18 '20 at 07:50
0

You can run

System.getProperty("os.arch")

to retrieve the systems architecture. My Windows 64bit system will return amd64 as os.arch value.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Korashen
  • 2,144
  • 2
  • 18
  • 28
  • Well... https://docs.oracle.com/javase/tutorial/essential/environment/sysprop.html states `"os.arch" Operating system architecture ` – Korashen Nov 07 '17 at 15:07