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(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: Example2. Program will exit.

what should i do??

  • we need information like what is your program and how are you trying to run it. – rɑːdʒɑ 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

  • 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 clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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