Results 1 to 3 of 3
  1. #1
    WhiskyMac is offline Member
    Join Date
    Jul 2012
    Posts
    2
    Rep Power
    0

    Default Java set up in Linux and Hello World

    I have seen many questions about getting Hello World to work.
    I have a similar problem: I used thsi code in my text editor in Ubuntu -
    "public class MainTest {

    public static void main(String[] args) {
    System.out.println("Hello World");
    }

    } "

    -I saved it as MainTest.java in my /home/me/ directory
    -then complied it with "javac MainTest.java" to create the .class file
    -then attempted to run it with "java MainTest" and also "java MainTest.java" both of which failed with error messages as follows;

    Exception in thread "main" java.lang.UnsupportedClassVersionError: MainTest : 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(Secure ClassLoader.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.j ava:205)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:3 21)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launche r.java:294)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:2 66)
    Could not find the main class: MainTest. Program will exit.

    -At this point there seem to be 3 files in the directory: Maintest.java , Maintest.class and Maintest.java~.

    - I have tried changing the CLASSPATH to the working directory, using the CLASSPATH and -cp options in the "java" command line instruction, entering and omitting the .java file type but nothing works.

    Advice required please!

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    19

    Default Re: Java set up in Linux and Hello World

    Nothing to do with CLASSPATH, indeed you do not (nor should ever use) that.
    It has everything to do with you having two versions of Java on your system.
    A 1.7 JDK and a 1.6 JRE.
    Please do not ask for code as refusal often offends.

  3. #3
    WhiskyMac is offline Member
    Join Date
    Jul 2012
    Posts
    2
    Rep Power
    0

    Default Re: Java set up in Linux and Hello World

    Hi Tolls, You are right.

    I googled the "Exception in Thread" error message and realsied it was because there were multiple versions of Java. I managed to find a piece of code in Ubuntu documentation that, once installed, allowed me to choose which version of Java runs. I selected the latest version and the code ran.

    Thanks for your help and all the forum users whose comments pointed me in this directiopn!

Similar Threads

  1. Java world generator-real world with people and stuff
    By conker5295 in forum Jobs Offered
    Replies: 2
    Last Post: 02-23-2012, 01:22 PM
  2. hello java world!
    By Stephenmak in forum Java Software
    Replies: 2
    Last Post: 09-23-2009, 05:29 AM
  3. Replies: 6
    Last Post: 04-08-2009, 04:05 AM
  4. Replies: 5
    Last Post: 04-06-2009, 10:10 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
  •