aspose file tools*
The moose likes Beginning Java and the fly likes Two versions of Java installed Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Two versions of Java installed" Watch "Two versions of Java installed" New topic
Author

Two versions of Java installed

jignesh soni
Ranch Hand

Joined: Dec 10, 2007
Posts: 150
I have two versions installed on my computer
j2re1.4.2_04 and j2re1.4.2_12

When I look in the path variable, I dont see path set for any java file at all.

1) How can I figure out which java version is in use ?

2) If path variable is not set for jre, can jre process any programs ? Over here I am not using jre to execute programs from command line, but only for downloading some file.

3) We need to have path variable explicitly set for jre if I want to run a program on my local machine, but is it required to set a path variable if I am only downloading files ?

Thanks
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 10916
    
  12

on Unix, you can do "which javac".

alternately, you can do "javac -version" and get something like

I:\>javac -version
javac 1.5.0_12
javac: no source files
Usage: javac <options> <source files>
where possible options include:
blah blah blah...


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
jignesh soni
Ranch Hand

Joined: Dec 10, 2007
Posts: 150
OS is Windows server 2003.

I tried javac -version. It did not give any results.

So how to find out which version is in use ?

thanks
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 10916
    
  12

well, you should have gotten SOMETHING whey you typed that command... but maybe you only have the JRE, not the JDK.

try "java -version"
jignesh soni
Ranch Hand

Joined: Dec 10, 2007
Posts: 150
When I run "java -version", I get output "java version 1.4.2_12"
whats the difference between javac and java ? which one is used when ?

have 3 questions in my post, can you please answer questions 2 and 3 ?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36508
    
  16
Somebody has already suggested you might have a JRE and no JDK; if you have a JRE or JDK (the JRE is part of the JDK) you will get a sensible result from java -version. If you have no JDK (or an incorrect PATH) you don't get a sensible answer from javac -version; on Windows you get "javac is not recognized as . . ."
jignesh soni
Ranch Hand

Joined: Dec 10, 2007
Posts: 150
Thanks.
Any inputs for other two questions mentioned in first post ?

If there is no jdk, it means I dont have javac. Does it mean that I can not compile source files but I can run byte code ?
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 10916
    
  12

javac is used to compile java source into a class file. if you are not writing any java, you don't need it.

java is the executable that takes a class file and runs it.

you do not need a path variable set to run ANYTHING. the path simply tells the OS "Look in THESE places when you are trying to find a program to run". if you explicitly tell the OS each time where it is, that works just as well. in other words, with no entry in the path, you'd* have to type

C:\Program Files\Java\jdk1.5.0_12\bin\java

if you have it set correctly, you'd only have to type

java

and the OS would look in all those places listed in your path, which would hopefully include "C:\Program Files\Java\jdk1.5.0_12\bin\"

What does downloading a file have to do with a JRE? unless you are using some application to manage the download that uses java... then it depends on what that application needs.

*Note: This is how it is on my machine... yours might differ slightly
jignesh soni
Ranch Hand

Joined: Dec 10, 2007
Posts: 150
Thanks.

I am trying to download a file and the error message I get is "Java is not available on this machine. Please contact your administrator."

So I think this application software in which I am trying to download file is using java.

Would anyone know, what this problem can be and how to solve it ?

thanks
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 10916
    
  12

do you have the documentation for the software you are using to download? it might tell you what you need. or, maybe you could edit your path to point to one version or the other... but without the documentation, you don't really know what version you need, do you?

There's probably not TOO much different between the 4.2.04 and the 4.2.12, so it's possible either would work. I'd probably start with the newer one, all things considered.
jignesh soni
Ranch Hand

Joined: Dec 10, 2007
Posts: 150
I am not aware of the documentation.

I am getting this error on my machine only. When I log on to other machine, I am able to perform the download.
Path variable is not used at all to specify path in which java.exe file is there.
Is it possible that java.exe file is not on my machine ?

thanks
[ October 29, 2008: Message edited by: jignesh soni ]
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 10916
    
  12

you should be able to find out. you said in your first post you have two versions installed. if so, you would have a java.exe.

why do you think you have j2re1.4.2_04 and j2re1.4.2_12 installed? you should be able to go to those directories, and find the bin directory. on my machine, i have

C:\Program Files\Java\jre1.6.0_05\bin

in there, there is a java.exe.
jignesh soni
Ranch Hand

Joined: Dec 10, 2007
Posts: 150
I can see on my current machine java.exe installed.
Previous machine, where I used to work is on a different location and the user of that machine is complaining that he can not download files using the application.

So is it possible that java.exe file is not on that machine ? I can not check his machine now.

Any ideas what can this be ? other question, if I want to switch to version j2re1.4.2_4 from j2re1.4.2_12 , how to do that ?

thanks
[ October 29, 2008: Message edited by: jignesh soni ]
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 10916
    
  12

of course it's possible. the only way to tell is to look at the machine itself.

generally, when the OS tries to find an executable, it looks in the local directory first. then, it goes to the PATH variable, and starts searching all the directories listed there, in the order they are listed. If the _12 is listed first, that's the one it will use (because it finds it there and stops looking). to force the use of the older version, simply put the _4 directory in the path before the _12.
jignesh soni
Ranch Hand

Joined: Dec 10, 2007
Posts: 150
Thanks Fred.

one thing is still not clear. If I dont have java.exe of either version configured in the environment variables and jre1.4.2_12 version is active which I can find out by using "java -version". So how to make jre1.4.2_4 version active without it being configured in environment variable ?


thanks
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 10916
    
  12

you should not have 'java.exe' in your environment variable. you would have the directory that contains the .exe.

if you type "java -version" and get meaningful results, the OS has to find it SOMEHOW. The only way I know is for it to use the PATH. Note that in windows, you have both your 'user' variables, AND SYSTEM variables. I would think that the directory would HAVE to be in one of them to find the executable. If it's really not in either, then I have no idea what to tell you.
jignesh soni
Ranch Hand

Joined: Dec 10, 2007
Posts: 150
There are four java.exe files.
One is under path c:\Program Files\Java\j2re1.4.2_04\bin,
second is under path c:\Program Files\java\j2re1.4.2_12\bin ,
third is under path c:\WINDOWS\system32 and
fourth is under bin.

Of these four java.exe files path there is one path under SYSTEM variable "path" and that directory path is C:\WINDOWS\system32. But at the same time there are other directory paths mentioned under the same variable.

This is how "path" variable is mentioned in System variables
"%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Cbem;C:\Program Files\Tools\;C:\Program Files\Microsoft SQL Server\90\Tools\binn\;C:\Program Files\H-P\OV\sd 3.5\client\bin"
Is it this "path" variable which specifies path of java.exe ?
How to find out what version does this java.exe belong to ?
In system32 directory there are many files. How is java.exe picked from so mane exe and dll files ?
Can you have more than one directory paths specified under one same variable name and these directory paths point to different exe files ?

Can anyone please explain this ?

thanks.

[ October 29, 2008: Message edited by: jignesh soni ]
[ October 29, 2008: Message edited by: jignesh soni ]
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36508
    
  16
You appear to have one of those four java.exe files accessible via your PATH environment variable, that in system32. So if you simply write java you get the java.exe in system32.
I suggest that, if you can install programs on your machine, you go to the download site and install the most recent version. Make sure to note the folder name you install it in for setting your PATH. Also suggest you uninstall the two versions of Java1.4.2.
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9043
    
  10
"javac -version" only works on 1.5 and higher. For 1.4.2_x you need to type
"javac -J-version" to get the version of the jdk currently in use.


JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 10916
    
  12

here is what my path looks like on my work computer:

I:\>echo %path%
C:\Program Files\ThinkPad\Utilities;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\Intel\DMIX;C:\Program Files\ATI hnologies\ATI.ACE\;C:\Program Files\Altiris\Software Virtualization Agent\;C:\Program Files\IBMThinkVantage\Client Security Solution;C:\Program Files\IBM\WebSphere MQ\bin;C:\Program Files\Java\jdk1.5.0_12\bin;c:\apache-ant-1.7.0\bin;C:\nastel\AutoPilotEE\bin;C:\Program Files\nastel\apwmq\bin;C:\Program Files\jEdit


as you can see, it has MANY directories. if i clean it up, it looks like this:

I:\>echo %path%
C:\Program Files\ThinkPad\Utilities;
C:\WINDOWS\system32;
C:\WINDOWS;
C:\WINDOWS\System32\Wbem;
C:\Program Files\Intel\DMIX;
C:\Program Files\ATI hnologies\ATI.ACE\;
C:\Program Files\Altiris\Software Virtualization Agent\;
C:\Program Files\IBMThinkVantage\Client Security Solution;
C:\Program Files\IBM\WebSphere MQ\bin;
C:\Program Files\Java\jdk1.5.0_12\bin;
c:\apache-ant-1.7.0\bin;
C:\nastel\AutoPilotEE\bin;
C:\Program Files\nastel\apwmq\bin;
C:\Program Files\jEdit


You can have as many directories in there as you want. You can even have directories that DON'T EXIST.

This is nothing more than a list of places to look for stuff. They don't 'point to exe files', as you say. In fact, the PATH variable is not specific to java. it is used by the OS when it needs to find a program - whether it is java, perl, ftp or anything. I could easily have 15 entries in the path that all point to different directories with different java.exe files.

the OS goes through the list IN ORDER, saying "is the file i need here? no? how about the next one? how about the next one? how about the next one...?" If it finds the file it needs, it stops looking. so, to specifically address your question:

1) Is it this "path" variable which specifies path of java.exe ?
sort of. It is a list of places to look. Just like if your mom said "Go find your shoes. Look in your bedroom first. Then the office. then the kitchen. then the front yard". You look in your bedroom and don't find your shoes. so you go to the office, and there they are. you don't bother looking in the kitchen or front yard. If your mom then says "Go find your coat", you'll again start in the bedroom, then go to the officd, then the kitchen, then the front yard.

2) How to find out what version does this java.exe belong to ?
As soon as ANY java.exe is found, it stops looking and uses that one. So, if on your machine you have 8 directories listed in the path that all have a java.exe, the FIRST one is the one that will be used. the binary itself knows what version it is.

3) How is java.exe picked from so mane exe and dll files ?
the OS knows it's looking for a file called "java.exe". it scans each directory looking for that file. the same way as if you did a "dir java.exe" - it knows how to find a match.

4) Can you have more than one directory paths specified under one same variable name and these directory paths point to different exe files ?
Yes. But the FIRST directory listed that has a file that matches is the one that will be used every time.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Two versions of Java installed
 
Similar Threads
showing wrong jre
UnsupportedClassVersionError
Cannot run program from another directory other than c:\Sun\SDK\jdk\bin
JVM
Which Files to Download from Sun