| Author |
Need Help getting Started
|
Kevin Smira
Greenhorn
Joined: Sep 30, 2004
Posts: 8
|
|
Hello all. I searched, but couldnt find the answer I was looking for. I need help getting started with Java programming. I d/l J2sdk1.4.2_05 a little while ago, and now I am having problems. I started out with the tutorial on Suns site, but I cant seem to get it to work. I guess I am having problems with setting the path and all. I have looked at everything posted, and cant seem to get it right. My first program (Hello World) is in c:\Java so, I type c:\Java\c:\J2sdk1.4.2_05\bin\javac HelloWorldApp.java Then, I get this error message: HelloWorldApp.java:7: <identifier> expected public static void main(String{} args) { ^ HelloWorldApp.java:11: ')' expected } ^ 2 errors What gives? Thanks, Kevin
|
 |
Gregg Bolinger
Ranch Hand
Joined: Jul 11, 2001
Posts: 15230
|
|
Well, looking at your code snippet from the error message (we would prefer to see all the code) you are using braces for your String array in your main method. So: public static void main(String{} args) should be public static void main(String[] args) I realize that Java's main method can be a bit confusing when just starting because you haven't even read about array declarations in Java yet. But when you declare an array you are to use brackets [], not braces {}.
|
 |
Kevin Smira
Greenhorn
Joined: Sep 30, 2004
Posts: 8
|
|
OK...I just took the text straight from Suns site, but I coulda screwed that up. I have limited programming knowledge, a year of COBOL, a year of C++, and a year of VB, not to mention a semester in 91 of FORTRAN (dont even remember that one) Anyway, heres the source code as I typed it: /** * The HelloWorldApp class implements an application that * displays "Hello World!" to the standard output. */ public class HelloWorldApp { public static void main(String{} args) { // Display "Hello World!" System.out.println("Hello World!"); } } Thanks, Kevin
|
 |
Gregg Bolinger
Ranch Hand
Joined: Jul 11, 2001
Posts: 15230
|
|
|
Everything looks good except the brackets/braces issue I told you about.
|
 |
Kevin Smira
Greenhorn
Joined: Sep 30, 2004
Posts: 8
|
|
Alright, changing the {} to [] worked fine, and after another look, it was my error. Anyway, why cant I just type javac HelloWorldApp.java from my c:\Java prompt? I assume it has to do with the path not being set right, but how do I do that? I have tried following the directions, but I cant seem to get it to work. Thanks, Kevin
|
 |
Gregg Bolinger
Ranch Hand
Joined: Jul 11, 2001
Posts: 15230
|
|
Yes, it has to do with the path. And it depends on your version of Windows. If it's 2000/XP you will need to: right click on my computer choose properties click the advanced tab click the Environment Variables button Either create a new PATH in the user variables. Or append the PATH in the global variables with the location of your bin folder
|
 |
Kevin Smira
Greenhorn
Joined: Sep 30, 2004
Posts: 8
|
|
Alright...I have a Path under my system variables, but nothing (as far as path) under my user variables. Which one should it go in? Thanks, kevin
|
 |
Chris Staten
Ranch Hand
Joined: Sep 24, 2004
Posts: 101
|
|
I could be wrong here, but if you have the path under your system variables then it will apply to all users (including you). I�m thinking that you don�t have to put it under your User variables. But if you want to you can click the �New� button and create it that way.
|
 |
Gregg Bolinger
Ranch Hand
Joined: Jul 11, 2001
Posts: 15230
|
|
Originally posted by Chris Staten: I could be wrong here, but if you have the path under your system variables then it will apply to all users (including you). I�m thinking that you don�t have to put it under your User variables. But if you want to you can click the �New� button and create it that way.
Yes, it really doesn't matter unless you care about other users on that PC having access to Java via the path. I always just put it in the global. That way if I have to blow away my profile for any reason, it's one less thing I have to worry about setting back up. Plus, I am the only one that uses my PC.
|
 |
Kevin Smira
Greenhorn
Joined: Sep 30, 2004
Posts: 8
|
|
Im the only one that uses my computer also, so no worries there. This is what I have in path under system variables: %SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\Program Files\PC-Doctor for Windows\services; c:\J2sdk1.4.2_05\bin Then, every time I go to compile the program, I have to type c:\Java\c:\J2sdk1.4.2_05\bin\javac xxxx.java Should I alays have to type this? Isnt there a way that I can just type c:\java\javac xxxx.java? thanks, kevin [ September 30, 2004: Message edited by: Kevin Smira ]
|
 |
Gregg Bolinger
Ranch Hand
Joined: Jul 11, 2001
Posts: 15230
|
|
Once you have that specified in your path you should just be able to type any command that exists in the java/bin folder. Make sure that you close your Command Prompt Window and re-open it for it to pick up the path change.
|
 |
Kevin Smira
Greenhorn
Joined: Sep 30, 2004
Posts: 8
|
|
I feel like a pest, but I have tried all the options listed, but nothing seems to work. kevin
|
 |
Gregg Bolinger
Ranch Hand
Joined: Jul 11, 2001
Posts: 15230
|
|
Originally posted by Kevin Smira: I feel like a pest, but I have tried all the options listed, but nothing seems to work. kevin
Are you absolutly sure the J in J2sdk1.4.2_05 is caps? Mine is j2sdk not J2sdk. I'm not sure if Windows cares about that or not.
|
 |
Kevin Smira
Greenhorn
Joined: Sep 30, 2004
Posts: 8
|
|
That wasnt it either. I feel so stupid kevin
|
 |
Joyce Lee
Ranch Hand
Joined: Jul 11, 2003
Posts: 1392
|
|
|
How about you reboot the system?
|
 |
Kevin Smira
Greenhorn
Joined: Sep 30, 2004
Posts: 8
|
|
Rebooted...didnt seem to help Believe it or not, a space makes all the difference in the world in the path. I typed path at the c:\ prompt and started examining it. There was a space between the semi-colon of my last entry and the java one. Stupid me. Got it fixed now, and thank you to all for your help. Kevin
|
 |
Gregg Bolinger
Ranch Hand
Joined: Jul 11, 2001
Posts: 15230
|
|
Originally posted by Kevin Smira: Rebooted...didnt seem to help Believe it or not, a space makes all the difference in the world in the path. I typed path at the c:\ prompt and started examining it. There was a space between the semi-colon of my last entry and the java one. Stupid me. Got it fixed now, and thank you to all for your help. Kevin
Glad to hear it Kevin. Keep chugging along. It'll start clicking.
|
 |
 |
|
|
subject: Need Help getting Started
|
|
|