问题
How can I identity whether the installed version of Java is 64 bit
or 32 bit
?
回答1:
You can get the os.arch
property:
String osArch = System.getProperty("os.arch");
This will tell you the architecture of the OS, so not exactly the one of the VM.
Sun's JREs have the following properties (values from my machine) that may be useful:
sun.arch.data.model : 32
sun.cpu.isalist : pentium_pro+mmx pentium_pro pentium+mmx pentium i486 i386 i86
But have in mind that these will not work on VMs from other vendors. So you may want to find such properties of other VMs as well, so that you are not vendor-dependent.
回答2:
Enter java -version on the command line. If it's 64-bits it will say so, otherwise it's 32-bits.
E.g.
64 bits Oracle / Mac OS X
$ java -version
java version "1.6.0_20"
Java(TM) SE Runtime Environment (build 1.6.0_20-b02-279-10M3065)
Java HotSpot(TM) 64-Bit Server VM (build 16.3-b01-279, mixed mode)
32 bits Oracle / Mac OS X (client)
$ java -version
java version "1.6.0_20"
Java(TM) SE Runtime Environment (build 1.6.0_20-b02-279-10M3065)
Java HotSpot(TM) Client VM (build 16.3-b01-279, mixed mode, sharing)
32 bits Oracle / Mac OS X (server)
$ java -server -version
java version "1.6.0_20"
Java(TM) SE Runtime Environment (build 1.6.0_20-b02-279-10M3065)
Java HotSpot(TM) Server VM (build 16.3-b01-279, mixed mode)
64 bits OpenJDK Ubuntu
$ java -version
java version "1.6.0_20"
OpenJDK Runtime Environment (IcedTea6 1.9.1) (6b20-1.9.1-1ubuntu3)
OpenJDK 64-Bit Server VM (build 17.0-b16, mixed mode)
32 bits Soylatte Mac OS X
$ java -version
java version "1.6.0_03-p3"
Java(TM) SE Runtime Environment (build 1.6.0_03-p3-landonf_19_aug_2008_14_55-b00)
Java HotSpot(TM) Client VM (build 1.6.0_03-p3-landonf_19_aug_2008_14_55-b00, mixed mode)
32 bits OpenJDK Mac OS X
$ java -version
openjdk version "1.6.0-internal"
OpenJDK Runtime Environment (build 1.6.0-internal-landonf_17_may_2009_13_58-b00)
OpenJDK Client VM (build 11.0-b17, mixed mode)
64 bits IBM Linux
$ java -version
java version "1.6.0"
Java(TM) SE Runtime Environment (build pxa6460sr8fp1-20100624_01(SR8 FP1))
IBM J9 VM (build 2.4, JRE 1.6.0 IBM J9 2.4 Linux amd64-64 jvmxa6460sr8ifx-20100609_59383 (JIT enabled, AOT enabled)
回答3:
I have both 32-bit and 64-bit versions of Java installed, but java -version only says 64-bit server (mixed mode). So this won't work if you have multiple (and previous) versions of Java installed.
There's another way to check I just realized: for Windows, if you have the 32-bit version installed then it will be in c:\Program Files (x86)\java\jre7 (or whatever the version of Java is installed). I see I also have a jre6 folder, which is a bit disconcerting because I thought I had already uninstalled it.
And for the 64-bit version, it will be in c:\Program Files\java (where all the 64-bit applications are installed).
来源:https://stackoverflow.com/questions/4574090/installed-jvm-is-64-bit-or-32-bit