aspose file tools*
The moose likes Java in General and the fly likes Java -Version Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Java -Version Problem" Watch "Java -Version Problem" New topic
Author

Java -Version Problem

Prash Singh
Ranch Hand

Joined: Aug 23, 2009
Posts: 103

Dear All,
I am facing a weird problem.
I have windows Xp installed in C:drive and Windows 7 in E: drive.
In Xp I am using Jdk 1.4 and in win-7 i am using Jdk 6.
The problem is when I am using Windows-7, then on the Cmd prompt,
when ever I launch java -version, it shows of Jdk 1.4 .

I have properly modified the path variable.

Please suggest me what to do?

Thanks in Advance.
sam salo
Greenhorn

Joined: Jun 08, 2010
Posts: 9
Multi booting OS’s can have wired problems.
I did this on windows 2008.

I would think when you logon to the windows 7 machine, you would go to the control panel/ system /Environment Variable
Check if the JAVA_HOME is defined and what value it has.
Check the path variable and verify that no Java point to the C Ddrive.

How did you set the path variable? make sure that there is no overlapping, system will pickup the first parameters in the path.


David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Prash Singh wrote:I have properly modified the path variable.

I doubt it; if you had it'd be running the correct version. Maybe posting your PATH variable would help--I've never heard of setting the path variable one way and having the system run something completely different.
Prash Singh
Ranch Hand

Joined: Aug 23, 2009
Posts: 103

OK.
This is the actual scenario.


E:\>echo %java_home%
E:\Program Files (x86)\Java\jdk1.6.0_18

E:\>java -version
java version "1.4.2_03"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_03-b02)
Java HotSpot(TM) Client VM (build 1.4.2_03-b02, mixed mode)

E:\>javac Hello.java

E:\>java Hello
Exception in thread "main" java.lang.UnsupportedClassVersionError: Hello (Unsupported major.minor version 50.0)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)

E:\>type Hello.java
class Hello
{
public static void main(String args[])
{
System.out.println("Hello");
}
}
E:\>path
PATH=E:\Program Files (x86)\JavaFX\javafx-sdk1.3\bin;E:\Program Files (x86)\JavaFX\javafx-sdk1.3\emulator\bin;E:\ora
clexe\app\oracle\product\10.2.0\server\bin;E:\oracle\product\10.1.0\db_1\bin;E:\oracle\product\10.1.0\db_1\jre\1.4.2
\bin\client;E:\oracle\product\10.1.0\db_1\jre\1.4.2\bin;E:\Windows\system32;E:\Windows;E:\Windows\System32\Wbem;E:\W
indows\System32\WindowsPowerShell\v1.0\;E:\Program Files (x86)\Java\jdk1.6.0_18\bin;E:\Program Files (x86)\Smart Pro
jects\IsoBuster;E:\Program Files (x86)\MySQL\MySQL Server 5.0\bin;;E:\Windows\system32\gs\gs8.13\bin



I hope this will make you understand the problem better.

and If I set path at the CMD prompt, it works fine.

Please suggest what could be the problem , and how to resolve it.
Thanks in Advance
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19696
    
  20

Prash Singh wrote:Exception in thread "main" java.lang.UnsupportedClassVersionError: Hello (Unsupported major.minor version 50.0)

That means that you've compiled the class with a version 6 JDK and are running it with a lower version JRE (1.4 in this case). Either switch to a version 6 JRE or use the -target compiler flag to compile specifically for Java 1.4. You'll miss out on the nice features of Java 5.0 and beyond though, so I suggest you follow my first advice.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Prash Singh
Ranch Hand

Joined: Aug 23, 2009
Posts: 103



Dear Rob Prime,
But How could it be that, version 4 is detected?
Its on different O.S.


Ninad Kulkarni
Ranch Hand

Joined: Aug 31, 2007
Posts: 791

@ Prash Singh

E:\>path
PATH=E:\Program Files (x86)\JavaFX\javafx-sdk1.3\bin;E:\Program Files (x86)\JavaFX\javafx-sdk1.3\emulator\bin;E:\ora
clexe\app\oracle\product\10.2.0\server\bin;E:\oracle\product\10.1.0\db_1\bin;E:\oracle\product\10.1.0\db_1\jre\1.4.2
\bin\client;E:\oracle\product\10.1.0\db_1\jre\1.4.2\bin;E:\Windows\system32;E:\Windows;E:\Windows\System32\Wbem;E:\W
indows\System32\WindowsPowerShell\v1.0\;E:\Program Files (x86)\Java\jdk1.6.0_18\bin;E:\Program Files (x86)\Smart Pro
jects\IsoBuster;E:\Program Files (x86)\MySQL\MySQL Server 5.0\bin;;E:\Windows\system32\gs\gs8.13\bin


Rob Prime is correct

I think from above given path value if go from left that is starting from PATH=E: the first available jre is 1.4.2 and later you will find jdk1.6.0_18 then in this case whenever jre 1.4.2 is reached then look for jre is haulted and jre 1.4.2 is selected as java version.
If you want to run jre 1.6 then jdk1.6 should appear before jre 1.4.2

Correct me if I am wrong.


SCJP 5.0 - JavaRanch FAQ - Java Beginners FAQ - SCJP FAQ - SCJP Mock Tests - Tutorial - JavaSE7 - JavaEE6 -Generics FAQ - JLS - JVM Spec - Java FAQs - Smart Questions
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Prash Singh wrote:

Dear Rob Prime,
But How could it be that, version 4 is detected?
Its on different O.S.
Only quote when you're quoting; not your own post.

Look at your path.
sam salo
Greenhorn

Joined: Jun 08, 2010
Posts: 9
I think that you have Oracle middle ware/components installed on the E drive, and the system is using the JRE that comes with oracle, just take the Oracle Path away to see what will happen;
E:\oracle\product\10.1.0\db_1\jre\1.4.2\bin;E
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Java -Version Problem