- How to find if java.exe is 32-bit or 64-bit?
- 3 Answers 3
- Installed jvm is 64 bit or 32 bit [duplicate]
- 3 Answers 3
- 64 bits Oracle / Mac OS X
- 32 bits Oracle / Mac OS X (client)
- 32 bits Oracle / Mac OS X (server)
- 64 bits OpenJDK Ubuntu
- 32 bits Soylatte Mac OS X
- 32 bits OpenJDK Mac OS X
- 64 bits IBM Linux
- Linked
- Related
- Hot Network Questions
- Find out 32 bit or 64-bit java JDK version in Java
- Check 32 bit or 64 bit for Java installation
- Java program to check 32 bit JVM or 64 Bit JVM
- Wrap up
How to find if java.exe is 32-bit or 64-bit?
I have a laptop with Windows 7 Professional 64-bit operating system. It has a C:\ProgramData\Oracle\Java\javapath folder which contains java.exe . How can I know if this JVM is 32-bit or 64-bit? I right-click on it and open Properties window and under Detail tab the File version is 8.0.1210.13 . But there is no information if it is 32-bit or 64-bit.
Make sure that you know what is always in your path because «java -cp . » will use that one. Not the hardcoded one
3 Answers 3
You can run C:\ProgramData\Oracle\Java\javapath\java.exe -version . Among the details it prints out, you should see whether it’s a 32 or 64 bit version.
A 32 bit version will return something about a «Client VM» or «Server VM», and a 64 bit version will state so explicitly.
E.g., the output of my machine (admittedly, a Fedora 25, but the principle should stand):
openjdk version "1.8.0_121" OpenJDK Runtime Environment (build 1.8.0_121-b14) OpenJDK 64-Bit Server VM (build 25.121-b14, mixed mode)
@srh: Obviously, if you want a specific java.exe , do C:\ProgramData\Oracle\Java\javapath\bin\java -version instead.
@srh, naturally, you should explicitly run it on the executable you want to evaluate, not count on the PATH. I’ll edit my answer to make it clearer, though.
I get this result java version «1.8.0_121» Java(TM) SE Runtime Environment (build 1.8.0_121-b13) Java HotSpot(TM) Client VM (build 25.121-b13, mixed mode, sharing) . So as per your answer it is 32-bit?
System.out.println(System.getProperty("os.arch"));
32 bit architecture is typically represented by x86_32 or just x86 , 64 bit architecture by x86_64
That determines the architecture of the host OS. It is a lucky coincidence, that this returns the desired value for all combinations of host OS bitnesses and JVM bitnesses on Windows. Specifically, if a 32-bit JVM is running in the WoW64 emulator the OS will lie to it about its architecture, and report a 32-bit architecture. This is really more of a code-by-coincidence strategy than a genuine solution.
@IInspectable at least on Windows, os.arch is not the host OS. It is the process arch. Try it, or read stackoverflow.com/a/37028080/280534
@KevinSmyth: As per documentation, the «os.arch» property returns the «Operating system architecture». Your link talks about a JVM implementation, that simply takes shortcuts to implement, what I explained in my previous comment. It reports the bitness of the calling process, because that’s exactly what the OS would report, even if a lie. This solution fails in case a competing JVM implementation chooses to report the true OS architecture.
To reliably determine the bitness of an executable image you’ll need tool support. This can be as simple as a hex editor, to inspect the contents of the PE Image. You can determine the machine type of the binary by following these steps:
- Move to location 0x3c, and note the value of the 4 bytes there (little endian order). Those are the offset from the beginning of the file to the PE Signature.
- Move to the location noted in step 1, and verify, that the 4 bytes have the values 0x50 0x45 0x00 0x00 ( PE\0\0 ). That’s the signature of a PE image. If the values are different, this is not an executable image.
- Move past the signature and note the next 2 bytes (little endian order). This value denotes the machine type of the binary image.
- Compare the value against the supported Machine Types:
- 0x014c corresponds to x86 (32 bits).
- 0x8664 corresponds to x64 (64 bits).
While simple and reliable, it takes a certain amount of care. There are easier ways, using other tools. In case you have Visual Studio installed, you can use DUMPBIN to have it report the machine type by executing the following command at the command prompt:
dumpbin.exe /HEADERS | findstr machine
This will produce the following output (x86 and x64, respectively):
If you don’t have Visual Studio or don’t want to install it, you could use Process Explorer to determine the bitness of a running process. To do so, right-click the respective process in the Process treeview, and select Properties. . On the Image tab you’ll see the process’ bitness spelled out.
Installed jvm is 64 bit or 32 bit [duplicate]
Indeed, at runtime (from within the Java code that is running on the JVM you need to know about) or from scripts that check what’s installed on your OS. Depending on the answer of that, two completely different answers are possible 😉
I would suggest you write code which doesn’t depend on the version installed. Why do you need to know this?
3 Answers 3
Enter java -version on the command line. If it’s 64-bits it will say so, otherwise it’s 32-bits.
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)
$ java -version, this doesn’t show me if it is a 32 bit VM or not, on executing the command, i got the following: java version «1.6.0_20» Java(TM) SE Runtime Environment (build 1.6.0_20-b02) Java HotSpot(TM) Client VM (build 16.3-b01, mixed mode, sharing)
Then it’s the 32 bit VM 😉 If it’s 64-bits, it explicitly says so. Same Java version on a 32 bit machine will show: 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) Note that server or client doesn’t make the difference. Execute with -server on a 32 bit machine and it will still not say «32-bit»
One doesn’t know. What the command prints is implementation dependent. At least the Sun JDK (checked Windows/Linux) and Mac OS X JDK (which is a Sun modified version anyway) print this. I quickly checked Soylatte and OpenJDK on 32 bits, and on 32 bits they don’t print the number of bits.
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.
right, i got a way to identify the JVM version as well. ‘System.getProperty(«sun.arch.data.model»)’ thanks for ur information
note that this will not work with other VMs by other vendors. So take your time to see their properties for identifying the arch.
@KarthickRagunath Are you sure of the JVM version you’re running? Because «os.arch» is intended to return the JVM version, not the underlying OS
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).
Linked
Related
Hot Network Questions
Site design / logo © 2023 Stack Exchange Inc; user contributions licensed under CC BY-SA . rev 2023.7.21.43541
By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.
Find out 32 bit or 64-bit java JDK version in Java
I have encountered one of the issues with java installation that is not compatible with my 32-bit machine.
This blog post is helpful for to check the JVM version to install the latest java version install.
Check 32 bit or 64 bit for Java installation
32 bit is 4 bytes of size, whereas 64 bit is 8 bytes of size. That means 64-bit takes more memory than 32 machines.
Most of the time, if your code compiles with the 32-bit JDK version, then you need to execute these class files in a 32-bit machine/64-bit machine only. This will compile and execute fine, but in some cases, if there is machine-specific code, you are in trouble with issues, so careful while installing JDK versions.
32-bit JVM is not compatible with other 64-bit hosts/frameworks as I have encountered issues with the installation of tomcat 64 bit on java 32 bit.
Java program to check 32 bit JVM or 64 Bit JVM
I am listing down the ways to find out the 32 bit vs 64 bit.
As per Sun Specification There is no public API to find out the 32-bit or 64 bit.
There are many ways to find out whether the 32bit version or not.
One way is as sun.arch.data.model is one of the system properties in JVM which has 32 bit or 64 bit or unknown, so we have to write a simple program to read the property value.
Here is a sample code to find out bit version
public class BitVersionDemo public static void main(String args[]) System.out.println("version =" + System.getProperty("sun.arch.data.model")); > > Output
that means My machine installed the JDK version with 32-bit.
so if your system is installed java 64 bit, by running the java -d32 command it gives the following message.
bash-3.2$ java -d32 -version Running a 32-bit JVM is not supported on this platform. By giving the -d64 command, the following information is displayed.
bash-3.2$ java -d64 -version java version "1.12.0_1" Java(TM) SE Runtime Environment (build 1.6.0_27-b07) Java HotSpot(TM) 64-Bit Server VM (build 20.2-b06, mixed mode)
On windows, “java -d32 -version” is giving an error so you can write the above sample to find out the version
If you want to know what the reference size is you can use Unsafe.addressSize(). Note: this is usually 4 as most 64-bit JVM will be using 32-bit references for up to 32 GB of heap.
Wrap up
To sum up, We learned how to find the installed JDK version on 64-bit or 32-bit using the java program and command line.