Why is java -version returning a different version to the one defined in JAVA_HOME?

My JAVA_HOME is set to C:\bea\jdk150_10\bin (Java 1.5). However, when I run java -version I get the following:

java version "1.6.0_22"
Java(TM) SE Runtime Environment (build 1.6.0_22-b04)
Java HotSpot(TM) Client VM (build 17.1-b03, mixed mode, sharing)

How can I use the 1.5 version?


As Mikel has mentioned, In your machine java is taken from C:\Windows\System32\java.exe.

Change the Path in the System Environment variables as mentioned by John T.

And modify it have the C:\bea\jdk150_10\bin before %SystemRoot%\system32 in the path.


Run

where java

at your command prompt.

On my system, it printed something quite unexpected:

C:\Users\Mikel>where java
C:\Windows\System32\java.exe

Verifying there really is a Java there:

C:\Users\Mikel>c:\windows\system32\java.exe -version
java version "1.6.0_22"
Java(TM) SE Runtime Environment (build 1.6.0_22-b04)
Java HotSpot(TM) Client VM (build 17.1-b03, mixed mode, sharing)

So one solution is to ensure your preferred Java is in the PATH before C:\Windows\System32.

I also tried looking in the Java control panel to see if it manages the version in C:\Windows\System32, but I could only view the settings, not edit them. Maybe it works for you?