Switch to full style
Java2 codes,problems ,discussions and solutions are here
Post a reply

Hows does Windows find Java?

Thu Oct 30, 2008 9:50 pm

I have two verisons of Java installed, the JRE 1.5 under C:\Program
Files\Java\jre1.5.0_11
and JDK 1.6 under c:\Java\jdk1.6.0

How can I switch between using the two?

I thought it would work if i set JAVA_HOME to one of them,

e.g JAVA_HOME= C:\Program Files\Java\jre1.5.0_11
and then set PATH=%PATH%;%JAVA_HOME%\bin

then when I wanted to switch I could just set JAVA_HOME to
c:\Java\jdk1.6.0

But no, it doesn't work when i type java -version it still finds
version 1.5.0_11, which BTW I installed after installing the jdk 1.6.0.

SO it seems Windows is using some other method than searching PATH to
find JAVA. Is it in the registry? And does anyone know how I can
override this if it is?



Re: Hows does Windows find Java?

Thu Oct 30, 2008 9:51 pm

We need <classpath> be set to the path of the libraries for compiling and
running the class.
We need <path> to be set to the the path of executables for commands like
java and javac be understood.

U can define JAVA_HOME and then classpath and path are Java_Home/bin or lib

Re: Hows does Windows find Java?

Tue Jan 03, 2012 5:18 am

Java installation puts four files into c:\windows\system32 folder:
java.exe
javaw.exe
javacpl.cpl
javaws.exe

So when you type "java -version" in cmd and jre\bin or jdk\bin folder is not set in the PATH before windows\system32, it executes java from there.
It looks into "HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment" to find JAVA_HOME and path to configuration files.

Hope this information helps you to understand magic with "java -version" command.

Post a reply
  Related Posts  to : Hows does Windows find Java?
 find the similarity between two Strings in Java     -  
 Find entity by id     -  
 find a string     -  
 Find MAC Address     -  
 Not to find nativeEncoder class jar     -  
 find the difference between dates in asp.net     -  
 how to find size without using sizeof     -  
 cannot find symbol constructor     -  
 How to find server IP, PORT using String     -  
 Unable to find javax.servlet     -