Results 1 to 8 of 8
- 08-18-2012, 01:58 AM #1
Member
- Join Date
- Aug 2012
- Posts
- 3
- Rep Power
- 0
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:- Saved as MyProgram.javaJava Code:public class MyProgram { public static void main(String[] args) { System.out.println( "Eureka, I can put Java on my resume."); } }
- 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:
There are no troubleshooting paragraphs that address this issue, what on earth did I do wrong?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.
- 08-18-2012, 02:09 AM #2
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,545
- Rep Power
- 11
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
If it is not Java7, download and install the most recent JRE.Java Code:java -version
- 08-18-2012, 05:18 AM #3
Re: Failing miserably at learning Java!
Please go through the Forum Rules -- particularly the third paragraph.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 08-18-2012, 06:17 AM #4
Member
- Join Date
- Aug 2012
- Posts
- 3
- Rep Power
- 0
Re: Failing miserably at learning Java!
- 08-18-2012, 06:25 AM #5
Student
- Join Date
- Jul 2012
- Location
- United States
- Posts
- 328
- Rep Power
- 1
Re: Failing miserably at learning Java!
"Success is not final, failure is not fatal: it is the courage to continue that counts." - Winston Churchill
- 08-18-2012, 06:31 AM #6
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,545
- Rep Power
- 11
Re: Failing miserably at learning Java!
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.I just installed the Java 7 runtime environment now, but it still said I'm running 1.6.
(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.)
- 08-18-2012, 07:25 AM #7
Member
- Join Date
- Aug 2012
- Posts
- 3
- Rep Power
- 0
Re: Failing miserably at learning Java!
Thank you, Brock. This solved my problem!
- 08-18-2012, 08:22 AM #8
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,545
- Rep Power
- 11
Similar Threads
-
Java Learning
By JTUS in forum New To JavaReplies: 2Last Post: 12-12-2011, 12:30 AM -
hi guys help me please . Learning from pdf is good or learning from book ?
By funkygarzon in forum New To JavaReplies: 12Last Post: 06-14-2011, 04:55 PM -
Learning Java...
By Learning Java in forum New To JavaReplies: 2Last Post: 09-24-2010, 09:03 PM -
Pls Help me in learning Java
By SimranK in forum New To JavaReplies: 6Last Post: 06-24-2010, 07:44 PM -
Trying to use RSA encryption, failing...
By soccermiles in forum New To JavaReplies: 2Last Post: 04-26-2010, 07:53 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks