srh
srh

Reputation: 1671

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.

Upvotes: 5

Views: 22085

Answers (3)

IInspectable
IInspectable

Reputation: 51510

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:

  1. 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.
  2. 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.
  3. Move past the signature and note the next 2 bytes (little endian order). This value denotes the machine type of the binary image.
  4. 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 <path\to\executable\image> | findstr machine

This will produce the following output (x86 and x64, respectively):

         14C machine (x86)

or

        8664 machine (x64)

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.

Upvotes: 0

Mureinik
Mureinik

Reputation: 312344

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)

Upvotes: 9

Reimeus
Reimeus

Reputation: 159874

You could check os.arch

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

Upvotes: 3

Related Questions