Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

multiple Java -version confusion

 
Charles Everhart
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy Y'all

New to Java, just picked up the Head first Java 2nd edition and have been playing with the code.

I have downloaded jdk1.6 and have on my computer the following path.
"C:\Program Files\Java\jdk1.6.0_07\bin"

If I enter "java -version" I get the following return value
'java version "1.6.0_07"
Java(TM) SE Runtime Environment (build 1.6.0_07-b06)
Java HotSpot(TM) Client VM (build 10.0-b23, mixed mode, sharing)'

I can enter my code into a .java file in the "bin" folder, compile and run it and it works.

Here is my issue, if I try to run my program in a seperate folder (I added a folder "C:\Program Files\Java\jdk1.6.0_07\bin\Samples" to store programs in) I get a "(Unsupported major.minor version 50.0)" error. I researched the error and found it was because my versions didn't match.

I did a 'java -version" in my "C:\Program Files\Java\jdk1.6.0_07\bin\Samples" and it returned:
'java version "1.3.1_01"
Java(TM) SE Runtime Environment (build 1.3.1_01)
Java HotSpot(TM) Client VM (build 1.3.1_01, mixed mode)'

Why did the "C:\Program Files\Java\jdk1.6.0_07\bin\Samples" and the
"C:\Program Files\Java\jdk1.6.0_07\bin" return different versions?

I also looked at the "C:\Program Files\Java\jdk1.6.0_07\sample" and it also returned a 1.3.1_01 version.

Also, is it possible to change the 1.3 version to a 1.6 version....and how.



Thanks so much for your help
 
Minal Silimkar-Urankar
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can check your classpath and path variable, whether the java 6 in the path or not?
 
Mark Vedder
Ranch Hand
Posts: 624
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The issue is that when you where in the "C:\Program Files\Java\jdk1.6.0_07\bin" and ran the java command, windows was picking up the executable from the current working directory. So it was running
"C:\Program Files\Java\jdk1.6.0_07\bin\java.exe". But when you changed directory into the Samples directory and java.exe was no longer in your current working directory, it picked up the java executable from another directory in your PATH environment variable. So in your PATH is a the bin directory of a Java 1.3.1 installation. So you will need to update your PATH environment variable to point to the newer version.

Take a look at the windows installation instructions to see how to set your PATH. You can also search this forum for help since that question is asked a lot. If you are still having problems, post a reply and we can help you out.
 
Mark Vedder
Ranch Hand
Posts: 624
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Charles Everhart:

I can enter my code into a .java file in the "bin" folder, compile and run it and it works.


p.s. You should not put your source files in the bin directory, or anywhere in the JDK (or its children) for that matter. This will cause problems in the long run. Create a "projects" or "development" or "dev" directory somewhere and do your work in there

p.p.s - Welcome to JavaRanch... sorry, I usually start my replies to new ranchers with that; but forgot to in my haste.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic