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

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have install java in my computer. when i doing compile java program it is successfully done but when i try to run program it show error like

Exception in thread "main" java.lang.UnsupportedClassVersionError: Example2 : 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: Example2. Program will exit.

what should i do??

share|improve this question
we need information like what is your program and how are you trying to run it. – Raja Jun 14 '13 at 16:56
With only that information is hard to point out the exact problem. How have you installed Java (apt-get/Software Center/Oracle installer)? Which Java version you have (java -version)? Ubuntu version and arch? Check you are not compiling your app with a newer version of the JRE you are using to run the program (ex: compiling with OpenJDK7 and running with Oracle JDK6). – Salem Jun 14 '13 at 17:11
java version "1.6.0_27" OpenJDK Runtime Environment (IcedTea6 1.12.5) (6b27-1.12.5-0ubuntu0.11.10.1) OpenJDK Client VM (build 20.0-b12, mixed mode, sharing) – Keyur Jun 14 '13 at 17:31

if i'm not mistaking this error is thrown if your virtual machine tries to run a program with different minor and major versions. Your number is 51.0 which means that your program is supported by J2SE and you try to run it with a newer version.
To fix your problem you should make sure that you got the newest version of the Java JRE

share|improve this answer
i have install both JDK&JRE 6 and 7 version. class Example2 { public static void main(String args[]) { int num; num = 100; System.out.println("This is num: " + num); num = num * 2; System.out.print("The value of num * 2 is "); System.out.println(num); } } this is my simple program – Keyur Jun 14 '13 at 17:17
so your problem is that you compiled your program with v6 and try to run it with v7. But I'm not quite sure how to change the wrong path on ubuntu... :( edit: your program is fine there is no mistake with it. – link1510 Jun 14 '13 at 17:20
than what should i do?? – Keyur Jun 14 '13 at 17:26

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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