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

    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 in my /home/me/ directory
    -then complied it with "javac" to create the .class file
    -then attempted to run it with "java MainTest" and also "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( :634)
    at .java:277)
    at$000(URLClassLoader. java:73)
    at$ 212)
    at Method)
    at ava:205)
    at java.lang.ClassLoader.loadClass( 21)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launche
    at java.lang.ClassLoader.loadClass( 66)
    Could not find the main class: MainTest. Program will exit.

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

    - 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
    Rep Power

    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.

    ** This space for rent **

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

    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