Results 1 to 8 of 8
  1. #1
    Join Date
    Aug 2012
    Posts
    3
    Rep Power
    0

    Default Failing miserably at learning Java!

    Well, apparently I can't even get a simple HelloWorld program right.

    Following this tutorial (with the sole exception of me using Java 7 instead of Java 2, as this was written in 2000), I did the following:

    - Open up Notepad.

    - Type this in:
    Java Code:
    public class MyProgram {
    
      public static void main(String[] args) {
        System.out.println(
          "Eureka, I can put Java on my resume.");
      }
    }
    - Saved as MyProgram.java

    - Opened up Command Prompt, typing javac MyProgram.java to compile it.


    Compiling was successful (apparently), as it created a .class file. However, when I typed 'java MyProgram', I got this:

    C:\Users\Jonathan\javastuff>java MyProgram
    Exception in thread "main" java.lang.UnsupportedClassVersionError: MyProgram :
    Unsupported major.minor version 51.0
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(Unknown Source)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknow n Source)
    at java.net.URLClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.access$000(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    Could not find the main class: MyProgram. Program will exit.
    There are no troubleshooting paragraphs that address this issue, what on earth did I do wrong?

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default Re: Failing miserably at learning Java!

    The version number message refers to the fact that you are compiling the code with a newer version of Java than the one you are trying to run it with. The runtime doesn't understand the .class files created by the compiler.

    Check the version of the JRE (Java Runtime Environment) to are using. In the Control Panel it will be listed under Programs. Or you can enter the command

    Java Code:
    java -version
    If it is not Java7, download and install the most recent JRE.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,197
    Rep Power
    19

    Default Re: Failing miserably at learning Java!

    Please go through the Forum Rules -- particularly the third paragraph.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    Join Date
    Aug 2012
    Posts
    3
    Rep Power
    0

    Default Re: Failing miserably at learning Java!

    1.6.0_31. I coulda sworn it was up to date.


    I just installed the Java 7 runtime environment now, but it still said I'm running 1.6.
    Quote Originally Posted by DarrylBurke View Post
    Please go through the Forum Rules -- particularly the third paragraph.

    db
    Sorry about that, Darryl. I also should have known that something like this would have been posted before.

  5. #5
    awinston is offline Student
    Join Date
    Jul 2012
    Location
    United States
    Posts
    328
    Rep Power
    3

    Default Re: Failing miserably at learning Java!

    Quote Originally Posted by ThesaurusRex84 View Post
    Sorry about that, Darryl. I also should have known that something like this would have been posted before.
    I think he was actually referring to the the fact that your title doesn't accurately reflect the topic of this thread.
    "Success is not final, failure is not fatal: it is the courage to continue that counts." - Winston Churchill

  6. #6
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default Re: Failing miserably at learning Java!

    I just installed the Java 7 runtime environment now, but it still said I'm running 1.6.
    Make sure the bin directory (folder) of the Java 7 runtime is on your system's path. (an not the older one). Or - more easily - use the control panel to uninstall 1.6.0_31 then reinstall 7.

    (In general there's no reason why you shouldn't have multiple versions installed. But while you're still getting used to the language it is probably easiest to have just one.)

  7. #7
    Join Date
    Aug 2012
    Posts
    3
    Rep Power
    0

    Default Re: Failing miserably at learning Java!

    Thank you, Brock. This solved my problem!

  8. #8
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default Re: Failing miserably at learning Java!

    You're welcome. Good luck with the rest of the Tutorial!

Similar Threads

  1. Java Learning
    By JTUS in forum New To Java
    Replies: 2
    Last Post: 12-12-2011, 12:30 AM
  2. Replies: 12
    Last Post: 06-14-2011, 04:55 PM
  3. Learning Java...
    By Learning Java in forum New To Java
    Replies: 2
    Last Post: 09-24-2010, 09:03 PM
  4. Pls Help me in learning Java
    By SimranK in forum New To Java
    Replies: 6
    Last Post: 06-24-2010, 07:44 PM
  5. Trying to use RSA encryption, failing...
    By soccermiles in forum New To Java
    Replies: 2
    Last Post: 04-26-2010, 07:53 PM

Tags for this Thread

Posting Permissions

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