0

I've always been under the impression that the default Java is determined by searching for the first Java executable that can be found in one of the given directories in the PATH system environment variable.

Now, when I use java -version on command line some Java on my system is called and shows version information even though no Java-path is on the PATH system environment variable.

So how does the command line decide what Java to use? I.e. where can this be configured?

Stephan
  • 1,791
  • 1
  • 27
  • 51
  • check typing echo %CLASSPATH% in cmd – ThisaruG Feb 12 '15 at 09:44
  • CLASSPATH just contains the JAR files that are used by Java and loaded by the system classloader for each JVM. It doesn't contain a path to the Java executable, – Stephan Feb 12 '15 at 09:50
  • Check the answer from Denis The Menace for this question: http://stackoverflow.com/questions/4681090/how-do-i-find-where-jdk-is-installed-on-my-windows-machine. Windows does some magic by putting Java executables in its system folder. – Magnilex Feb 12 '15 at 09:50

2 Answers2

3

There are a java.exe, a javaw.exe and a javaws.exe in your C:\Windows\System32\ folder.

Usually, that one is taken because it's before any other jdk/jre folder that you use.

You can check which java is taken by typing where java in your prompt. This will list all the java executables in order of appearance in your %PATH%.

Olivier Grégoire
  • 33,839
  • 23
  • 96
  • 137
0

It is taken from the registry. Java executable uses it to locate the default version of Java to run.

The copy of java.exe to run is found by using the PATH environment variable. If you do not change this, by default a copy will be found in the Windows directory.

You can modify the registry, or put the version of Java you want before the Windows directory in your PATH.

enter image description here

aviad
  • 8,229
  • 9
  • 50
  • 98