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.
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With