0

As per the documentation here link

To find out which java executable the first one found in your PATH, execute:

which java

This command returns the following three paths in my machine

C:\>which java
C:\Windows\system32\java.EXE
C:\Program Files (x86)\Java\jre7\bin\java.EXE
C:\Windows\System32\java.EXE

There is no java.exe in C:\Windows\System32. I have java (Java SE 7 Update 25) installed in the location C:\Program Files (x86)\Java\jre7\ This is also confirmed by running "where java"

C:\>where java
C:\Program Files (x86)\Java\jre7\bin\java.exe

I have set Path=C:\Program Files (x86)\Java\jre7\bin; in environment variables. This path is not used in any environment variable.

What I want to know is, how and why does which java return C:\Windows\System32\java.EXE and that too twice?

Since there is no native which command in Windows, I just found out that a which.exe had been created to mimic "which" with the following script

@for %%a in (%PATH%) do @if exist %%a\%1 (
 for /f %%b in ('dir /b %%a\%1') do @echo %%a\%%b
)

@rem for %a in (%PATH%) do @if exist %a\which* dir /b /w %a\which*
4
  • 1
    Does Windows have a which command? What is the output of which which? And what is where? Never heard of useful utilities on Windows. Do you use Cygwin?
    – T-Bull
    Jun 25, 2013 at 8:40
  • Ya, he must be using Cygwin. 'Which' is a unix command - stackoverflow.com/questions/304319/… Jun 25, 2013 at 8:45
  • @T-Bull I investigated after your comment and found out, that an exe has been created with the following script to mimic "which" command. @for %%a in (%PATH%) do @if exist %%a\%1 ( for /f %%b in ('dir /b %%a\%1') do @echo %%a\%%b ) @rem for %a in (%PATH%) do @if exist %a\which* dir /b /w %a\which* and "which which" returns a path to this which.exe
    – ontherocks
    Jun 25, 2013 at 8:55
  • @ontherocks: Oh, that's interesting, I'll check that out. By the way, the line beginning with @rem is not operative, because rem is the comment marker in batch files (i.e. that line is commented out).
    – T-Bull
    Jun 25, 2013 at 9:04

3 Answers 3

1

The java.exe in system32 seems odd, but when you there is no java.exe its fine. What is even more strange that there is no "which" command on my Windows7, just where. It is possible that the "which" comes from some other path on PATH?

1
1

Your OS must be Windows 7 64-bit. And your jre and which command are 32-bit application. The 64-bit operating system uses the %SystemRoot%\system32 directory for its 64-bit library and executable files. This is done for backward compatibility reasons, as many legacy applications are hardcoded to use that path. When executing 32-bit applications, WoW64 transparently redirects 32-bit DLLs to %SystemRoot%\SysWoW64, which contains 32-bit libraries and executables. Therefore C:\Windows\system32\java.EXE for 32-bit application is actually C:\Windows\SysWoW64\java.EXE.

0

On my system, I have java.exe in C:\WINDOWS\system32, too. And javaw.exe and javaws.exe. Turns out, those are the exact same files that I have in C:\Program Files\Java\jdk7\bin. So it seems likely that the Java installer copied them to the system directory in order to prevent path issues.

2
  • It seems I too have java.exe in system32. I am not able to view it in explorer even though I have "Show hidden files, folders, and drives" checked and "Hide protected operating system files (recommended)" unchecked. They only show up in command prompt. Are you able to see them in explorer?
    – ontherocks
    Jun 25, 2013 at 11:05
  • Yes, it's just a normal file here. Maybe it's because I run WinXP on that box and use an account with admin rights. Explorer is configured to show all files anyway (standard procedure whenever a new user is created).
    – T-Bull
    Jun 25, 2013 at 14:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.