Sign up ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Possible Duplicate:
Cannot execute Java program: UnsupportedClassVersionError

I'm a newbie to Ubuntu and Im looking to run Java code from the command line. Ive checked that path as well. The interesting thing is the code compiles but fails to run


user@ubuntu:~/py-scripts$ javac' works well.

but when I do .

`user@ubuntu:~/py-scripts$ java Main

I get the following error

Exception in thread "main" java.lang.UnsupportedClassVersionError: Main : Unsupported major.minor version 51.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(
at Method)
at java.lang.ClassLoader.loadClass(
at sun.misc.Launcher$AppClassLoader.loadClass(
at java.lang.ClassLoader.loadClass(
 Could not find the main class: Main. Program will exit.'
share|improve this question

marked as duplicate by Lekensteyn, James Apr 9 '12 at 19:24

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

What version of Java are you running? Run "java -version" and see what you get. – Kelley Apr 6 '12 at 14:53
can you post your – Tachyons Apr 6 '12 at 15:09
@tachyons ,@Kelley public class Main { public static void main (String[] args) { System.out.println ("Hello, world."); } } and java version:OpenJDK Runtime Environment (IcedTea6 1.11pre) (6b23~pre11-0ubuntu1.11.10.2) OpenJDK 64-Bit Server VM (build 20.0-b11, mixed mode) – KodeSeeker Apr 6 '12 at 15:12
whats the result of ls ? – Tachyons Apr 6 '12 at 15:18
verify that Main.class exit in your directory ,else change your directory to home folder – Tachyons Apr 6 '12 at 15:18

1 Answer 1

If you have multiple versions of the JRE/JDK installed (e.g. versions 6 and 7), you should make sure that the JRE you're running (using java) uses a version that is class-compatible with what you've used to compile the class (e.g. JRE 7 for classes compiled with JDK 6 or 7, but not JRE 6 for classes compiled with JDK 7).

You can keep multiple versions installed and choose which one is used by java and javac using update-alternatives --config java and update-alternatives --config javac (as documented here).

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.