HiveBrain v1.2.0
Get Started
← Back to all entries
snippetjavaCritical

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

Submitted by: @import:stackoverflow-api··
0
Viewed 0 times
programhowwithinfromrunningjvmcantellbit

Problem

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?

Solution

You retrieve the system property that marks the bitness of this JVM with:

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


Possible results are:

  • "32" – 32-bit JVM



  • "64" – 64-bit JVM



  • "unknown" – Unknown JVM



As described in the HotSpot FAQ:

When writing Java code, how do I distinguish between 32 and 64-bit operation?

There's no public API that allows you to distinguish between 32 and 64-bit operation. Think of 64-bit as just another platform in the write once, run anywhere tradition. However, if you'd like to write code which is platform specific (shame on you), the system property sun.arch.data.model has the value "32", "64", or "unknown".

An example where this could be necessary is if your Java code depends on native libraries, and you need to determine whether to load the 32- or 64-bit version of the libraries on startup.

Code Snippets

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

Context

Stack Overflow Q#2062020, score: 339

Revisions (0)

No revisions yet.