Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (4k points)
reshown by

How can I know if the JVM in which my application works is 32 bit or 64-bit? Precisely, what functions or properties I can practice to detect this within the program? How can I determine if the JVM in which my application works is 32 bit or 64-bit? Particularly, what functions or properties I can use to detect this inside the program?

1 Answer

0 votes
by (46k points)

You can recover the system property that indicates the bitness of this JVM with:

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

Potential results are:

"32" – 32-bit JVM

"64" – 64-bit JVM

"unknown" – Unknown JVM

As illustrated 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 instance where this could be important is if your Java code depends on local libraries, and you want to settle whether to load the 32- or 64-bit version of the libraries on startup.

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Browse Categories

...