5

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.

srh
  • 1,661
  • 4
  • 30
  • 57
  • Not *exact* duplicate but take a look at: http://stackoverflow.com/a/2062263 – Pshemo Apr 17 '17 at 16:00
  • Make sure that you know what is always in your path because "java -cp ....." will use that one. Not the hardcoded one – bichito Apr 17 '17 at 16:08

3 Answers3

9

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)
Basil Bourque
  • 303,325
  • 100
  • 852
  • 1,154
Mureinik
  • 297,002
  • 52
  • 306
  • 350
  • this depends on whichever JVM is on path first; – srh Apr 17 '17 at 15:53
  • 2
    @srh: Obviously, if you want a specific `java.exe`, do `C:\ProgramData\Oracle\Java\javapath\bin\java -version` instead. – T.J. Crowder Apr 17 '17 at 15:53
  • 2
    @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. – Mureinik Apr 17 '17 at 15:54
  • 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? – srh Apr 17 '17 at 16:01
  • @srh yes. That's a 32 bit Java. – Mureinik Apr 17 '17 at 16:02
3

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

Reimeus
  • 158,255
  • 15
  • 216
  • 276
  • 1
    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 Apr 17 '17 at 21:07
  • 1
    @IInspectable at least on Windows, `os.arch` is not the host OS. It is the *process* arch. Try it, or read https://stackoverflow.com/a/37028080/280534 – Kevin Smyth Jul 11 '18 at 16:08
  • @KevinSmyth: As per [documentation](https://docs.oracle.com/javase/7/docs/api/java/lang/System.html#getProperties()), 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. – IInspectable Jul 12 '18 at 11:16
0

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.

IInspectable
  • 46,945
  • 8
  • 85
  • 181