Results 1 to 5 of 5
Like Tree2Likes
  • 1 Post By eRaaaa
  • 1 Post By eRaaaa

Thread: Problem running Simple Hello world program in Ubuntu

  1. #1
    teete is offline Member
    Join Date
    Apr 2012
    Posts
    3
    Rep Power
    0

    Default Problem running Simple Hello world program in Ubuntu

    Problem running Simple Hello world program in Ubuntu...

    I have installed JDK7... copied it to /usr/lib/jvm/ directory and changed the Java Alternative

    And use javac command to compile the program and it created a hello.class file
    Java Code:
    javac hello.java
    it compiled without any error

    below is the code
    Java Code:
    class hello{ 
     public static void main(String[] args) 
     { 
     System.out.println("Hello World!"); 
     } 
    }
    But when i try to run the prgram using this command
    Java Code:
    java hello
    But i get this following errors
    Java Code:
    Exception in thread "main" java.lang.UnsupportedClassVersionError: Hello : Unsupported major.minor version 51.0
    	at java.lang.ClassLoader.defineClass1(Native Method)
    	at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
    	at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
    	at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
    	at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
    	at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
    	at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    	at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
    	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    	at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
    Could not find the main class: Hello.  Program will exit.
    At last line it says Could not find the main class: Hello. Program will exit.

    Please help me ,i'm new to Java

  2. #2
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    6

    Default Re: Problem running Simple Hello world program in Ubuntu

    UnsupportedClassVersionError: Hello : Unsupported major.minor version 51.0
    It look likes your Java Runtime version(6) is different to your JDK version(7).
    What says "java -version" in your terminal? (6?)
    You have to change it....
    teete likes this.

  3. #3
    teete is offline Member
    Join Date
    Apr 2012
    Posts
    3
    Rep Power
    0

    Default Re: Problem running Simple Hello world program in Ubuntu

    Quote Originally Posted by eRaaaa View Post
    It look likes your Java Runtime version(6) is different to your JDK version(7).
    What says "java -version" in your terminal? (6?)
    You have to change it....
    After executing that command ,i got following text

    java version "1.6.0_24"
    Java(TM) SE Runtime Environment (build 1.6.0_24-b07)
    Java HotSpot(TM) Client VM (build 19.1-b02, mixed mode, sharing)



    Im using JDK 7
    Last edited by teete; 04-24-2012 at 09:00 PM.

  4. #4
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    6

    Default Re: Problem running Simple Hello world program in Ubuntu

    Yes, that was what I suspected ->
    How do you changed the java alternative?
    sudo update-alternatives --config java ?
    Do you have selected the java 7 jre?
    How To Install Oracle Java 7 (JDK) In Ubuntu ~ Web Upd8: Ubuntu / Linux blog
    + many other sites will give you an installation guide!
    Last edited by eRaaaa; 04-24-2012 at 09:13 PM.
    teete likes this.

  5. #5
    teete is offline Member
    Join Date
    Apr 2012
    Posts
    3
    Rep Power
    0

    Default Re: Problem running Simple Hello world program in Ubuntu

    Quote Originally Posted by eRaaaa View Post
    Yes, that was what I suspected ->
    How do you change the java alternative?
    sudo update-alternatives --config java ?
    Do you have selected the java 7 jre?
    How To Install Oracle Java 7 (JDK) In Ubuntu ~ Web Upd8: Ubuntu / Linux blog
    + many other sites will give you a installation guide!
    Thanks a lot .....thank you very much....
    i had to change the java alternative,it was set to /usr/lib/jvm/java-6-sun/jre/bin/java
    changed it to /usr/lib/jvm/jdk1.7.0/bin/java

    so now it works ...thank you :)

Similar Threads

  1. Problem running DataGimmick program!!
    By Bentino in forum New To Java
    Replies: 1
    Last Post: 02-21-2012, 10:18 PM
  2. Simple program, simple problem
    By taymilll in forum New To Java
    Replies: 12
    Last Post: 06-20-2011, 06:12 AM
  3. Problem with running an external program via java
    By g123456 in forum New To Java
    Replies: 4
    Last Post: 12-30-2009, 06:06 PM
  4. Problem Running in Simple JSTL example
    By arpitgadle in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 06-28-2009, 10:19 PM
  5. Not able to debug simple hello world program
    By amit123solanki in forum New To Java
    Replies: 1
    Last Post: 06-12-2008, 04:41 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •