How can I tell if the JVM in which my application runs is 32 bit or 64-bit? Specifically, what functions or properties I can used to detect this within the program?
For Windows
, you can check the Java
home location. If it contains (x86)
it is 32-bit
otherwise 64-bit
:
public static boolean is32Bit()
{
val javaHome = System.getProperty("java.home");
return javaHome.contains("(x86)");
}
public static boolean is64Bit()
{
return !is32Bit();
}
Example paths:
C:\Program Files (x86)\Java\jdk1.8.0_181\bin\java.exe # 32-bit
C:\Program Files\Java\jdk-10.0.2\bin\java.exe # 64-bit
Windows
only solution?If you need to know which bit version you're running on, you're likely fiddling around with native code on Windows
so platform-independence is out of the window anyway.