Results 1 to 16 of 16
Thread: Help! New to java
- 10-19-2011, 08:43 PM #1
Member
- Join Date
- Oct 2011
- Posts
- 2
- Rep Power
- 0
Help! New to java
Hey, I just recently started following a Java beginner tutorial and I am creating a simple "Hello World" program. I saved the HelloApp.java text file onto my desktop
When I open the command line, I type in cd desktop...I then type in javac HelloApp.java hit ENTER and then a new blank line appears (seems as if nothing happens)...however, is this supposed to create a .class file on my desktop once its compiled? I try to type in java HelloApp and I get the following error: Could not find or load main class HelloApp
My CLASSPATH is blank
I added C:\Program Files (x86)\Java\jdk1.7.0_01\bin\ to my PATH setting
Thank you for taking the time to read this. HELP
- 10-19-2011, 08:51 PM #2
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,561
- Rep Power
- 11
Re: Help! New to java
It sounds like you are doing everything correctly. Could you run the following commands and copy and post the output exactly as you see it:
The dir statements are just to check that things are where you think they are. (you always have to be skeptical!) and the type statement will print the actual code. It is possible to write code that will compile but won't function as a main class.Java Code:cd Desktop dir HelloApp.* type HelloApp.java javac HelloApp.java dir HelloApp.* java HelloWorld
- 10-19-2011, 09:06 PM #3
Member
- Join Date
- Oct 2011
- Posts
- 2
- Rep Power
- 0
Re: Help! New to java
Alright, when i type in dir HelloApp.* I get:
Volume in drive C is Gateway
Volume serial number is 4639-CF24
Directory of C:\Users\main\Desktop
10/19/2011 144 HelloApp.java
1 File(s) 144 bytes
0 Dir(s) 225,036,967,936 bytes free
When I type HelloApp.java I get:
class ExampleProgram {
public static void main(String[] args)}
System.out.printIn("Hello World");
}
}
I then type in java HelloApp.java and get the blank line again. After this I type dir HelloApp.* and I get the same following message as the first time in this post.
- 10-19-2011, 11:09 PM #4
Member
- Join Date
- Oct 2011
- Posts
- 2
- Rep Power
- 0
Re: Help! New to java
Hi i have the same problem
this is the error i get :
Exception in thread "main" java.lang.UnsupportedClassVersionError: hello : Unsup
ported 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: hello. Program will exit.
i hope it's okay for me to post this here.
- 10-19-2011, 11:13 PM #5
Re: Help! New to java
I find it hard ot believe nothing happens. You should get some sort of error. You need to compile your file first.
If it successfully creates a class file: HelloApp.class, you then run itJava Code:javac HelloApp.java
Pay special attention to when you do and do not use file extensions.Java Code:java HelloApp
- 10-19-2011, 11:15 PM #6
- 10-20-2011, 12:10 AM #7
Member
- Join Date
- Oct 2011
- Posts
- 2
- Rep Power
- 0
- 10-20-2011, 03:52 AM #8
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,561
- Rep Power
- 11
Re: Help! New to java
You should name the class and the file the same thing. So if the file is HelloApp.java change the contents to
Junky has given you the commands that will compile and run this program. It is important to note that "java HelloApp" will attempt to run a class called HelloApp and *not* ExampleProgram. (which it knows nothing about).Java Code:public class HelloApp { public static void main(String[] args)} System.out.printIn("Hello World"); } }
- 02-12-2013, 03:19 PM #9
Member
- Join Date
- Feb 2013
- Posts
- 4
- Rep Power
- 0
Re: Help! New to java
Hi guys! My HelloApp is experiencing the same symptoms as the first user here. After I've installed JDK 1.7 update 13, I went to System Properties and then to Environment Variables to insert C:\Program Files\Java\jdk1.7.0_13\bin; in the Path variable. Then, I used Notepad to type
public class HelloApp
{
public static void main(String[] args)
{
System.out.println("Hello, World!");
}
}
then I saved it as "HelloApp.java". I opened the cmd and typed cd to change into the directory of the file. Afterwards, I typed javac HelloApp.java. Nothing appears. Then, I typed java HelloApp and the same error comes up (error: Could not find or load main class HelloApp).
When I typed dir HelloApp.*, this appears:
Volume in drive C has no label.
Volume Serial Number is 8ABD-1289
Directory of C:\Users\Vaio\Documents\Programming
12/02/2013 PM 10:01 423 HelloApp.class
12/02/2013 PM 10:00 116 HelloApp.java
2 File(s) 539 bytes
- 02-12-2013, 03:23 PM #10
Member
- Join Date
- Feb 2013
- Posts
- 4
- Rep Power
- 0
Re: Help! New to java
(continued from above - i accidentally posted the reply above without finishing it)
0 Dir(s) 138,179,428.352 bytes free
When I typed HelloApp.java, a text box appears saying Windows can't open it ><bleurrgh!!!
Please help this poor newbie....I've been trying to solve this for hours!
- 02-12-2013, 06:05 PM #11
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
Re: Help! New to java
Do you have a CLASSPATH environment variable set up?
If so then post the entry here.
It's likely it needs to be deleted, but it might be from some poor software you've installed (quicktime I'm looking at you).Please do not ask for code as refusal often offends.
- 02-13-2013, 08:24 AM #12
Member
- Join Date
- Feb 2013
- Posts
- 4
- Rep Power
- 0
Re: Help! New to java
My CLASSPATH is C:\Program Files\Java\jre6\lib\ext\QTJava.zip
- 02-13-2013, 09:38 AM #13
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,561
- Rep Power
- 11
Re: Help! New to java
Since you have a CLASSPATH variable set (and from the looks of it, required by quicktime) it is important that you *don't* use this CLASSPATH value when compiling or running your program. The reason for this is that the classpath is the place that the Java executables (java and javac etc) look for classes. Clearly the place to which CLASSPATH refers has nothing to do with your program. Hence the need to specify the classpath some other way.
The dash-c-p-space-dot in those two commands means "make the classpath the current directory". By specifying it explicitly you "overrule" the CLASSPATH setting. While not needed in this case for the javac command you might as well include it as it's a sensible default any time you compile or run things from the command line.Java Code:javac -cp . HelloApp.java java -cp . HelloApp
- 02-13-2013, 10:24 AM #14
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
- 02-15-2013, 08:41 AM #15
Member
- Join Date
- Feb 2013
- Posts
- 4
- Rep Power
- 0
Re: Help! New to java
Thanks pbrockway2 and Tolls! XD "-cp ." works! Yay! I'm deleting Quicktime too since I hardly use it.
- 02-15-2013, 10:28 AM #16
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,603
- Blog Entries
- 7
- Rep Power
- 17


4Likes
LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks