jagadeesh
jagadeesh

Reputation: 91

java runtime error in ubuntu

jagadeesh@jagadeesh-PC:~$ cd Programs
jagadeesh@jagadeesh-PC:~/Programs$ javac demo.java
jagadeesh@jagadeesh-PC:~/Programs$ java demo
Exception in thread "main" java.lang.UnsupportedClassVersionError: demo : Unsupported major.minor version 51.0
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:634)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:277)
    at java.net.URLClassLoader.access$000(URLClassLoader.java:73)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:212)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
Could not find the main class: demo. Program will exit.
jagadeesh@jagadeesh-PC:~/Programs$ echo $CLASSPATH

jagadeesh@jagadeesh-PC:~/Programs$ 

I am sure that classpath is not set. Could any one please give me the detailed explanation about classpath,javahome etc. I encountered these terms in various sites but i couldn't undertand them clearly. I'd like to be explained about the paths that should be included in classpath and how to do it. Thank you.

Upvotes: 3

Views: 756

Answers (3)

Tariq
Tariq

Reputation: 2569

A Java Class compiled on JDK version 7 can not be executed using JRE version 6 or any, that is less than 7. Try finding versions of both JDK and JRE installed on your system. For more help See this:

How To find JDK/JRE version on linux

Upvotes: 1

Jon Skeet
Jon Skeet

Reputation: 1500145

No, I don't think it's a classpath issue. I think it's much more likely that your javac is version 7, but java is version 6.

Run javac -version and java -version to check. Then work out where you're running each from, using which javac and which java. Then either run Java 7 explicitly, or upgrade so that you're running Java 7 everywhere, or use javac -source 1.6 -target 1.6 demo.java

Upvotes: 2

Andreas Florath
Andreas Florath

Reputation: 4612

The classpath has nothing to do with your problem:

The problem is, that you compiled the java source code with another compiler (javac) as the JVM (java) you want to try to run the code with.

It looks that the javac emits class files which cannot be interpreted by your JVM.

Upvotes: 1

Related Questions