27

I need to determine whether a particular system has 32-bit Java installed. I'm doing a remote query that only gives me access to the filesystem and registry, so I cannot attempt to run java.exe, or run any Java code.

I also want to make sure I detect both IBM and Sun Java, as well as any other distributions, which seem to put things in different places on the filesystem and in the registry.

The best I've come up with is to check for C:\Windows\SysWOW64\java.exe. Is this a reliable way to test for the presence of 32-bit Java, or are there certain versions that won't put java.exe in that folder?

Update: I'm still looking for a more robust answer to this. Just to be clear, I don't have access to a command prompt. Also, I want to detect Java no matter who the publisher is, what version number is installed, and no matter what path the user chose to install it on.

C:\Windows\SysWOW64\java.exe seems to fit these requirements, but I'd love some confirmation from someone more knowledgeable that every Java installer will indeed put that executable there.

Chris Vasselli
  • 13,064
  • 4
  • 46
  • 49

6 Answers6

49

This seems to provide the info on Windows:

1.) Open a windows command prompt.

2.) Key in: java -XshowSettings:all and hit ENTER.

3.) A lot of information will be displayed on the command window. Scroll up until you find the string: sun.arch.data.model.

4.) If it says sun.arch.data.model = 32, your VM is 32 bit. If it says sun.arch.data.model = 64, your VM is 64 bit.

Aaron Dellutri
  • 491
  • 4
  • 3
  • 3
    No need to show all settings. `java -XshowSettings:properties -version` is enough (`-version` is to prevent the “no argument” error). See [Non-Standard Options section](https://docs.oracle.com/javase/8/docs/technotes/tools/unix/java.html#BABHDABI) in documentation. – Franklin Yu May 01 '18 at 19:23
  • 1
    And how can I replace my exact current version with the 64-bit one? – Seymour Jun 15 '18 at 13:49
  • Thank you, that was useful. It's quite odd and awkward, that `java -version` only doesn't give this out. – Giorgi Tsiklauri Jul 17 '19 at 07:11
11

Do you have access to the command prompt ?

Method 1 : Command Prompt

The specifics of the Java installed on the system can be determined by executing the following command java -version

Method 2 : Folder Structure

In case you do not have access to command prompt then determining the folder where Java.

32 Bit : C:\Program Files (x86)\Java\jdk1.6.0_30

64 Bit : C:\Program Files\Java\jdk1.6.0_25

However during the installation it is possible that the user might change the installation folder.

Method 3 : Registry

You can also see the version installed in registry editor.

  1. Go to registry editor

  2. Edit -> Find

  3. Search for Java. You will get the registry entries for Java.

  4. In the entry with name : DisplayName & DisplayVersion, the installed java version is displayed

woodvi
  • 1,898
  • 21
  • 27
Kakarot
  • 4,252
  • 2
  • 16
  • 18
  • I don't have access to the command prompt. I'm also concerned that those paths have version numbers in them, and the fact that a user could change that path at install time. – Chris Vasselli Jan 11 '12 at 20:14
  • I can't seem to find the registry entries you're referring to. Where are they in the registry? – Chris Vasselli Jan 11 '12 at 21:06
  • HKEY_LOCAL_MACHINE/Software/Microsoft/Windows/CurrentVersion/Uninstall – Kakarot Jan 11 '12 at 21:20
  • It looks like I could check HKEY_LOCAL_MACHINE/Software/Wow6432Node/Microsoft/Windows/CurrentVersion/Uninstall and look for something with the name Java in it, but this solution doesn't seem very robust. What if something else includes Java in their name? Alternatively I could check for specific names of the different versions of java, but that seems very error-prone as well, in case it ever changes or there are new publishers of Java. Unfortunately, all of these methods seem somewhat error-prone. I think what I need is a common file or registry key that every Java installation will set. – Chris Vasselli Jan 11 '12 at 22:41
  • The right registry path to check JRE for Sun/Oracle Java on Windows OS is here: `HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment\{CurrentVersion}\JavaHome` where `CurrentVersion` is a key value stored in `HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment\ `. JRE uses this for its system property `java.home` instead of `JAVA_HOME`. However, this registry won't help you determine it is a 32-bit or 64-bit except you apply #method3 on `JavaHome` key value. For JDK, it the same but at different registry path `HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Development Kit` – ee. Jan 12 '12 at 03:01
  • Damnit. So I didn't have a JRE installed all the time. Who knew that `D:\Program Files` wouldn't be valid :( Well ok you could fix that easily enough, but then: Who tells you that the JRE was installed in the default location? I think the simplest solution without registry and all is to use the `java_home` environment variable. That should be set when installing (or is that part of the jdk install? no idea) – Voo Jan 17 '12 at 17:37
  • Oh forgot the part about reliably finding out if the file is 32 or 64bit then. As long as it's only windows, you know for sure that it's using the PE format, so you can just write a simple Win32 c program that parses the file header and checks for itself. We're interested in the `IMAGE_FILE_HEADER` part and especially `Machine` there. – Voo Jan 17 '12 at 17:49
  • 4
    For method 2, wouldn't 32 bit be the x86 folder? – Adam Johns Sep 09 '13 at 02:56
5

Check this key for 32 bits and 64 bits Windows machines.

 HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment

and this for Windows 64 bits with 32 Bits JRE.

 HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\JavaSoft\Java Runtime Environment

This will work for the oracle-sun JRE.

Daniel De León
  • 13,196
  • 5
  • 87
  • 72
3

just write "java -d64 -version" or d32 and if you have It installed it will give a response with current version installed

1

If it is not Oracle's Java, you may not be able to tell. When I install Oracle Java 64-bit, the files go into C:\Program Files\Java, but when I install a 32-bit version, they default to C:\Program Files (x86)\Java instead. Of course, the person who installed Java could have overridden those defaults.

0

I tried both the 32-bit and 64-bit installers of both Oracle and IBM Java on Windows, and the presence of C:\Windows\SysWOW64\java.exe seems to be a reliable way to determine that 32-bit Java is available. I haven't tested older versions of these installers, but this at least looks like it should be a reliable way to test, for the most recent versions of Java.

Chris Vasselli
  • 13,064
  • 4
  • 46
  • 49