vr3w3c9
vr3w3c9

Reputation: 1178

how can we change java version to use

I have multiple java versions installed in my machine(os Windows 8). I have java 1.6, 1.7 & 1.8 installed in my machine. I have set the path environment variables only for version 1.6 as Java_Home & for 1.8 as Java_Home8.

But strangely when i type java -version in command prompt, and it refers to jdk 1.7 version. But strangetly, I looked at path environment variables, and I couldn't find path that leads to jdk 1.7 installation folder.I have not created any seperate path variables for jdk 7. I have also not included it in path as well. But still when i open the command prompt and type java -version, it still points to java 7. Below are the contents of the path variable

%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\Program Files\Java\jre1.8.0_60\bin;C:\Program Files\Java\jre1.6.0_07\bin;%M2%;C:\Program Files\Microsoft SQL Server\100\Tools\Binn\;C:\Program Files\Microsoft SQL Server\100\DTS\Binn\;C:\Program Files\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE\;C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\PrivateAssemblies\;C:\Program Files\TortoiseSVN\bin;C:\Program Files\Java\jdk1.6.0_07\bin;C:\Program Files\Windows Kits\8.1\Windows Performance Toolkit\;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\;

Can someone explain how this happens. My assumption is that when i execute the java -version command, it refers to the version provided in the path variables. But it does not happen that way. Can you please explain the reason for the same and how it picks/displays the java 7 version.

Upvotes: 1

Views: 2942

Answers (2)

Seelenvirtuose
Seelenvirtuose

Reputation: 20618

Java installers on Windows also place a java.exe, a javaw.exe, and a javaws.exe into the directory

C:\Windows\System32

At least, Java 7 did that. Java 8 places the same files into

C:\ProgramData\Oracle\Java\javapath

and also puts this directory into the PATH environment variable.

The above mentioned system directoy is the first directory mentioned in your PATH variable: %SystemRoot%\system32. So you can put as many Java binary directories into the PATH variable as you want ... Simply calling java ... will always start the program from the system directory - and this will be Java 7, I guess.

Solution? Delete them from the system directory. Oh, and clean up your PATH variable a bit. There is more than one Java directory mentioned. Usually, you only need one. And if you temporarily need another Java, refer to @slartidan's answer for how to do.

Upvotes: 3

slartidan
slartidan

Reputation: 21576

In Windows usually the last setup of a JRE is registered in the PATH environment variable.

JAVA_HOME is used by many launchers, etc. but does not change the windows apllication starts (for example when double clicking a jar file or typing java in a command prompt).

I recommend to always specify the full path of java, like this:

C:\Program Files\Java\jdkxy\bin\java - version

or

%JAVA_HOME8%\bin\java -version

A good side effect of this is, that you don't even have to install java anymore. Just copy one of your java folders to any other PC and run java with the fully qualified path.

Upvotes: 0

Related Questions