wood burning stoves*
The moose likes Beginning Java and the fly likes How  to use different java versions on my machine Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How  to use different java versions on my machine" Watch "How  to use different java versions on my machine" New topic

How to use different java versions on my machine

nitude gupta
Ranch Hand

Joined: Sep 04, 2008
Posts: 34
I have both 1.5 and 1.6 installed on my system.
I checked on console all programs were executed using 1.6 using command javac -version
But I want to run using 1.5...Is there any explicit cmd thorugh which I can change version at compile time..

Thank you in advance
Jhakda Velu
Ranch Hand

Joined: Feb 26, 2008
Posts: 166
If you are compiling from command prompt and your JDK 5 and 6 are in C:\Java5 and C:\Java6 respectively, then you can try this from command prompt
C:\Java5\bin\javac abc.java for 1.5
C:\Java6\bin\javac abc.java for 1.6 (or without it as its your default version)
I ***think*** it should work.

If using IDE, select the JDK of choice while creating project.


If I become filthy rich, I'll sponsor research for painless dental treatment at Harvard Medical School. Thats why,I'm learning Java.I have 32 teeth, 22 are man made.
Ankit Garg

Joined: Aug 03, 2008
Posts: 9291

nitude, Jhakda is right. You can install multiple versions of Java on your system at the same time. Usually setting the path environment variable to point to one of the version of java is the preferred way of using a specific java version but you can use the solution Jhakda gave too...

SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Harshit Rastogi
Ranch Hand

Joined: Apr 15, 2008
Posts: 131
you need to set the classpath pointing to the jdk directory which you want to use (1.5 or 1.6)

<a href="http://technologiquepanorama.wordpress.com" target="_blank" rel="nofollow">My Techie Blog</a><br /><a href="http://www.java-questions.com" target="_blank" rel="nofollow">Java Questions</a>
Vijitha Kumara

Joined: Mar 24, 2008
Posts: 3816

Harshit Rastogi wrote:you need to set the classpath pointing to the jdk directory which you want to use (1.5 or 1.6)

Wrong. Don't set the classpath to jdk. It's the PATH system variable which points to bin directory of the jdk used.

[How to ask questions] [Twitter]
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 37950
You write something like
set PATH=C:\program files\java\jdk1.4.2_12\bin;%PATH%

at the command line (that syntax only works for Window: for *nix try export PATH=/usr/java/jdk1.4.2_12/bin:$PATH). I think it is "Set" but may be mistaken. Windows is case-insensitive, *nix is case-sensitive.
That should reset your PATH for that terminal/command prompt only. Putting a particular JDK first in the PATH forces the computer to use that particular version of the java.exe program.
I agree. Here's the link: http://aspose.com/file-tools
subject: How to use different java versions on my machine
Similar Threads
Need some Guidance in using Java 1.6 with ANT
Applet not using the latest installed JRE but using the one selected in Java control panel
Java Beans naming convention for getter and setter methods
Which Version is Latest Stable ?
java version