Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How can we change tha java version to use?

 
Anas Nashroel
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I installed jdk 1.4 and 1.5 on windows. I set JAVA_HOME to refer to jdk 1.5 installation folder. When I type java -version, it refers to jdk 1.5 installation.
and then, I downloaded and installed jdk 1.6. When the installation was finished, I type java -version in command prompt, and it refers to jdk 1.6 version. But strangetly, I looked at path environment variables, and I couldn't find path that leads to jdk 1.6 installation folder. The path is to jdk 1.5 installation folder.
So, how can i set the java version to use in windows ??
Thanks in advance
 
Paul Campbell
Ranch Hand
Posts: 338
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Anas Nashroel:
Hi, I installed jdk 1.4 and 1.5 on windows. I set JAVA_HOME to refer to jdk 1.5 installation folder. When I type java -version, it refers to jdk 1.5 installation.
and then, I downloaded and installed jdk 1.6. When the installation was finished, I type java -version in command prompt, and it refers to jdk 1.6 version. But strangetly, I looked at path environment variables, and I couldn't find path that leads to jdk 1.6 installation folder. The path is to jdk 1.5 installation folder.
So, how can i set the java version to use in windows ??
Thanks in advance


In your windows environment variables:

Change CLASSPATH to be your 1.6 installation path... likely something like "C:\Program Files\Java\jdk1.6.0_06\bin" <== don't forget the quotes.

If you do not have a CLASSPATH environment variable, create one.

Change your PATH variable to have %CLASSPATH%; as the first entry.

You will likely need to reboot before the variables become useful.

But first I would uninstall your 1.4 and 1.5 installations and compile with the source options javac -source 1.4 when you want use 1.4 and javac -source 1.5 when you want to compile as the 1.5 jdk.

[ October 14, 2008: Message edited by: Paul Campbell ]
[ October 14, 2008: Message edited by: Paul Campbell ]
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Change CLASSPATH

Isn't it PATH ?
 
Paul Campbell
Ranch Hand
Posts: 338
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Christophe Verre:

Isn't it PATH ?


The PATH variable is one windows environment variable (the main search path)... if you create a CLASSPATH environment variable you can use the %CLASSPATH% in your PATH variable... why do that instead of just doing the PATH variable? I just really prefer touching the path variable as little as possible and avoid modifying it (other than adding the %CLASSPATH% system variable).

I should update my original post for clarity though... and in the vein of a picture is worth a thousand words...



[ October 14, 2008: Message edited by: Paul Campbell ]
[ October 14, 2008: Message edited by: Paul Campbell ]
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The PATH variable tells the operating system where to look for executable files.
The CLASSPATH variable tells the Java compiler and JRE where to look for class files.
They are totally unrelated - putting the path to the JDK bin directory in the CLASSPATH will not tell the OS where to find the javac program.
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Anas Nashroel:
I looked at path environment variables, and I couldn't find path that leads to jdk 1.6 installation folder. The path is to jdk 1.5 installation folder.
So, how can i set the java version to use in windows ??
Thanks in advance


When you say you looked at the environment variables, did you echo the PATH variable to a command prompt or did you look at the environment variables in the system properties dialog ? If the latter did you check in both the user and system variables ? It's possible to set a PATH variable in both which Windows then combines to form the complete PATH variable.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49447
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Joanne is right (as usual); you don't need to do anything with your CLASSPATH, at least if you are using a recent version of Java.
Probably the easiest way to use a particular version of Java is to set the PATH from the shell/terminal/command line; there are old posts telling you how to do it here and here.
Put the PATH to the version of Java you wish to use first; remember it starts with the drive letter (often C) on Windows and / on Unix/Linux and ends with bin. That way your new path PATH will only apply to that one shell/terminal/command line.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
putting the path to the JDK bin directory in the CLASSPATH will not tell the OS where to find the javac program.

Exactly.
 
Paul Campbell
Ranch Hand
Posts: 338
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Joanne Neal:
The PATH variable tells the operating system where to look for executable files.
The CLASSPATH variable tells the Java compiler and JRE where to look for class files.
They are totally unrelated - putting the path to the JDK bin directory in the CLASSPATH will not tell the OS where to find the javac program.


I totally agree... and adding %CLASSPATH% as the first entry in the PATH variable does that.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49447
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The CLASSPATH is where the JVM looks for other executable .class files, so you don't want to confuse CLASSPATH and PATH.
Last thing you want in your PATH is your CLASSPATH.
 
Paul Campbell
Ranch Hand
Posts: 338
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Campbell Ritchie:
The CLASSPATH is where the JVM looks for other executable .class files, so you don't want to confuse CLASSPATH and PATH.
Last thing you want in your PATH is your CLASSPATH.


Point taken... after reading and re-reading... I get where I had this wrong. Thank you.
[ October 15, 2008: Message edited by: Paul Campbell ]
 
Campbell Ritchie
Sheriff
Pie
Posts: 49447
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Paul Campbell:
Point taken...



You have to be very wary about saying CLASSPATH; every time you do hundreds of greenhorns go changing their computer's environment setting unnecessarily.
 
Harish Vembu
Ranch Hand
Posts: 33
Java MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Though the answers to the original post were given, I am not able to get the desired Java version somehow.


I have installed JDK 1..6 and JDK 1.4 on my windows XP machine on different paths

Here is what I have in my environment variables

PATH : C:\Program Files\PHP\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:
\WINDOWS\system32\WindowsPowerShell\v1.0;C:\j2sdk1.4.2_19\bin;%ANT_HOME%\bin;C:\
Program Files\PHP\php.ini;C:\j2sdk1.4.2_19\bin;C:\ant-1.5.2\bin;

I have the highlighted the one for JDK 1.4 bin directory in path.

I have JAVA_HOME user variable set to C:\jdk1.6.0_23 which I am not using in PATH.

When I use Java -version I always get version 6 regardless of me changing the PATH to respective JDK bin directory.

I am wary of setting CLASSPATH variable in PATH as advised on this forum.


Please clarify. Appropriate reply would be much appreciated.


Thanks & Best Regards

Harish
 
Rob Spoor
Sheriff
Pie
Posts: 20552
57
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's because it's finding C:\WINDOWS\system32\java.exe first. This is a wrapper that uses the registry to find and launch your Java 6 JVM.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49447
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Move your Java™ installation folders earlier in the PATH string than the System folder Rob mentioned.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49447
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Another way to do it is to invoke java with its full PATH
C:\java\myPrograms:> C:\j2sdk1.4.2_19\bin\java Foo
If there are spaces in the PATH, you may need quotes "" around the C;\...\java String.
 
Harish Vembu
Ranch Hand
Posts: 33
Java MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Thanks Rob and Ritchie. Your answers are spot on.

It really helped.

I was also thinking on those lines of system 32 which is causing to always use JDK 6 version.

I prefixed the path environment variable with JDK 1.4 path and it worked.

 
Campbell Ritchie
Sheriff
Pie
Posts: 49447
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome
 
Campbell Ritchie
Sheriff
Pie
Posts: 49447
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Compsci Student,
Your post was moved to a new topic.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic