3

After searching all over the web, I am not able to solve my problem of Java execution. When using command prompt to run my "first" Java program, I am faced with the errors of Unsupported class version and Main class not found. Program will exit.

I have 2 versions of Java on my PC, Java 6 and 7. I have set the path of the JDK 7 in path environment variables and classpath too. I know the problem: I have javac -version as 1.7.02 and java version as 1.6.02, but how to change it and fix the problem?

Please elaborate the problem in easy and understandable language!

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Garfield
  • 29
  • 1

2 Answers2

3

You have to run your program with the same or higher version of java that yxou compiled it with.

So you can either compile your program with Java 6 on your PC or run it with java 7.

To run your program with java 7 just use the complete path to your java runtime environment. for instance

c:\jdk7\bin\jawaw.exe yourprogram

How to tell your system which Java version to use is explained here: Why does java -version returns old version?

Community
  • 1
  • 1
juergen d
  • 201,996
  • 37
  • 293
  • 362
  • Yes but the problem is he doesn't know how to change the version of his java executable. The problem is probably this: he has installed JDK 7 and Java 6 JRE and doesn't know how to change java command to use JDK 7 – palto Jan 24 '12 at 15:14
  • What iff i wand to run a program save at my desktop...i put the desktop path and compile it it workss...how to run it from there?? – Garfield Jan 24 '12 at 15:28
  • Tried the steps posted at the link..Not working:((( @juergen d – Garfield Jan 24 '12 at 15:35
  • if it is a jar file you can look here: http://stackoverflow.com/questions/1238145/how-to-run-a-jar-file – juergen d Jan 24 '12 at 15:38
0

JRE [java command] come with your JDK 1.7, and you must change your JAVA_HOME variable to your JDK 1.7 folder.for this work read this article

mehdi shahdoost
  • 1,469
  • 5
  • 17
  • 27