This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
If you use Windows, than the classpath can be found: start -- settings -- system -- advanced -- environment variables than adjust the CLASSPATH definition. After that, you can check it: open the console, and type: java -version It will show the actual java version your system run
Note that the CLASSPATH setting will have no effect on which version of the runtime is used.
What you want to set is your PATH environment variable. It can be as simple as set PATH=C:\j2sdk1.4.2\bin;%PATH% for 1.4 or you might set it permanently in the Windows dialog.
To test which version JVM will be started, use: java -version To test which version compiler will be started, use: javac -J-version To determine the version at runtime, use: String version = System.getProperty("java.version");
In Windows, I have a batch file which has all of my jvm's listed. All are REMarked out except the one I want to run with. For example, to test myProgram, a jar file, in a JVM of my choice, I just remove the REM from the version of the JVM I want to use:
At the command prompt I just enter the name of the batch file to run:
Now it will launch in 1.4.2_04. No problem.
Give a man a fish, he'll eat for one day. Teach a man to fish, he'll drink all your beer.
Cheers, Jeff (SCJP 1.4, SCJD in progress, if you can call that progress...)
As Jeff shows, the best way to ensure which version of Java you run is by specifying the full path to the java executable. If you don't like the command line, I think you can set up your IDE to run with several different versions of the JDK. Unfortunately, I don't know the details as I haven't tried to do this before.
p.s. If you write and compile your programs with JDK 1.4, they should still run on JDK 1.5 as-is. However, the opposite isn't true unless you use the "-target 1.4" option.