How can I tell if I'm running in 64-bit JVM or 32-bit JVM (from within a program)?

BobMcGee picture BobMcGee · Jan 14, 2010 · Viewed 666.7k times · Source

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?

Answer

gpampara picture gpampara · Jan 14, 2010

For certain versions of Java, you can check the bitness of the JVM from the command line with the flags -d32 and -d64.

$ java -help
...
    -d32          use a 32-bit data model if available
    -d64          use a 64-bit data model if available

To check for a 64-bit JVM, run:

$ java -d64 -version

If it's not a 64-bit JVM, you'll get this:

Error: This Java instance does not support a 64-bit JVM.
Please install the desired version.

Similarly, to check for a 32-bit JVM, run:

$ java -d32 -version

If it's not a 32-bit JVM, you'll get this:

Error: This Java instance does not support a 32-bit JVM.
Please install the desired version.

These flags were added in Java 7, deprecated in Java 9, removed in Java 10, and no longer available on modern versions of Java.