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?

3
  • check typing echo %CLASSPATH% in cmd Commented Feb 12, 2015 at 9: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, Commented Feb 12, 2015 at 9:50
  • Check the answer from Denis The Menace for this question: stackoverflow.com/questions/4681090/…. Windows does some magic by putting Java executables in its system folder. Commented Feb 12, 2015 at 9:50

2 Answers 2

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%.

Sign up to request clarification or add additional context in comments.

Comments

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

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.