How can I tell if the JVM my application runs in is 32 bit or 64-bit? Specifically, what function or preference do I access to detect this within the program?
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
For
Windows
, you can check theJava
home location. If it contains(x86)
it is32-bit
otherwise64-bit
:Example paths:
Why care about a
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.Update Again:
I installed 32-bit JVM and retried it again, looks like the following does tell you JVM bitness, not OS arch:
This was tested against both SUN and IBM JVM (32 and 64-bit). Clearly, the system property is not just the operating system arch.
Sun has a Java System property to determine the bitness of the JVM: 32 or 64:
You can use
to determine if its 32/64 from the program.
From the Sun HotSpot FAQ:
The only good reason is if your java code is dependent upon native libraries and your code needs to determine which version (32 or 64bit) to load on startup.
On Linux, you can get ELF header information by using either of the following two commands:
o/p: ELF 64-bit LSB executable, AMD x86-64, version 1 (SYSV), for GNU/Linux 2.4.0, dynamically linked (uses shared libs), for GNU/Linux 2.4.0, not stripped
or
o/p: Class: ELF64
Just type
java -version
in your console.If a 64 bit version is running, you'll get a message like:
A 32 bit version will show something similar to:
Note
Client
instead of64-Bit Server
in the third line. TheClient/Server
part is irrelevant, it's the absence of the64-Bit
that matters.If multiple Java versions are installed on your system, navigate to the /bin folder of the Java version you want to check, and type
java -version
there.You can try on the command line:
If it's not a 64-bit version, you'll get a message that looks like:
Consult the help options of the JVM for more info
java -help