3
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.

3 Answers 3

2

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

Sign up to request clarification or add additional context in comments.

4 Comments

Could you please tell me how can i upgrade my java version?
@jagadeesh: Not offhand, no - but I'd look at how you generally upgrade software.
I found java6 & java7 files in /usr/lib/jvm. I think java6 files are being used by default. How can i change it to java7?
i just installed jdk1.7 using command sudo apt-get install openjdk-7-jdk. Thats it.
1

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.

Comments

1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.