Command Line Option to change which JDK to use

Hello All,

I am very new to Java. I downloaded Java SDK 1.4.2_13 onto my laptop. I added C:\j2sdk1.4.2_13\bin to my Classpath. I created a JAVA_HOME = C:\j2sdk1.4.2_13 in the environment variables. I receive an error while trying to run a basic program in a dos prompt. I received some help from an experienced java developer. He asked me to put in the command java -version in the dos prompt. It came back with java version 1.5.0_04. The experienced java developer said, "I needed to use the command line option in java to tell which JDK to use". He had no more time to give. He said I can look it up. Well, I don't know what he's talking about. Does anyone have some insight on what I need to do?

Thank You

[729 byte] By [mgd007a] at [2007-11-26 14:44:08]
# 1
if you setJAVA4 = C:\whatever\jdk142_x\binthen JAVA4\javac.exe Program.javaJAVA4\java.exe Program
TuringPesta at 2007-7-8 8:31:49 > top of Java-index,Java Essentials,New To Java...
# 2
Or with 1.5 and 1.6 there is the javac -source 1.4 -target 1.4flags for compiling code that is backwards compatible.
TuringPesta at 2007-7-8 8:31:49 > top of Java-index,Java Essentials,New To Java...
# 3

This

I added C:\j2sdk1.4.2_13\bin to my Classpath

is wrong. You never need to add the bin dir to your classpath. As a matter of course, you should never use the enviroment variable CLASSPATH, instead set it on the command line using

javac -cp <classpath> <filename.java>

To answer your immediate problem, either include the entire path to the java.exe you wish to use on the command line, or set the System PATH variable so that the dir for java 1.4 is listed before the dir for java 1.5. If you do this in the command window, it is only valid for that command window, and resets when the window is closed

set PATH=c:\j2sdk1.4.2_13\bin;%PATH%

java -cp <classpath> <filename.java>

~Tim

SomeoneElsea at 2007-7-8 8:31:49 > top of Java-index,Java Essentials,New To Java...