Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 665
jagadeesh Avatar asked May 11 '26 03:05

jagadeesh


2 Answers

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

like image 160
Jon Skeet Avatar answered May 13 '26 17:05

Jon Skeet


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.

like image 21
Andreas Florath Avatar answered May 13 '26 18:05

Andreas Florath



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!