This week's book giveaway is in the OCAJP forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide 1Z0-808 and have Jeanne Boyarsky & Scott Selikoff on-line! See this thread for details.
I am brand new to java. So new, that I'm trying to get the classic "Hello World" program to compile and when I run javac.exe the prompt stays open for less than a second (you can see that its scrolling something) and then immediately closes.
"javac.exe" is a command-line program. You have to run it by typing "javac" at a command prompt -- i.e., the "MS-DOS Window". Typing "javac.exe" into the "Start | Run..." dialog isn't going to do you much good. Let me lean over and look at my wife's XP box... Start | Programs | Accessories | Command Prompt. You should get a nice black window. Type your commands in there!
Are you using Jview, by chance? If so, see this page.
Otherwise, are you running directly from the Command Prompt (I'm assuming you're using Windows)? What exactly are you entering at the prompt?
Since you mentioned "javac.exe," I'll just add that you do not type a ".exe" extension when running javac. Simpy type "javac" (without quotes), followed by a space and then the name of your file (including the .java extension)...
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer sscce.org
Joined: Dec 10, 2005
When using the dos prompt, I went into the directory where my sample java program is (which is not in the same folder as the JDK software)
and then I typed "javac sample.java"
I got this as a error " 'javac' is not recognized as an internal or external comand, operable program or batch file."
That error is because your sample.java file is in a different directory. If you've changed your directory to where javac is installed, then I think you would need to type the full path after "javac." Something like...
What isn't working about setting your PATH? Which operating system are you using?
(After setting the PATH variable, I know that you would at least need to close the Command Prompt and re-open to start a new session. But you might need to reboot the machine as well.)
I'd definitely encourage you to consider getting some kind of graphical IDE - it sounds like you'd probably be much more comfortable with a GUI than the command line. Here are a couple of good Open Source choices:
But back to your immediate problem: getting a simple Java program compiled. Please do this:
1. Start a "command prompt"
2. Create a .bat file to set your environment: From the command prompt, type: notepad
NOTES: You need to have the quote ('"') and percent ('%') characters exactly like I have them. Feel free to cut and paste from this note.
You need to find the actual path where you installed your JDK. One way is to find it in Windows Explorer. Another is to just re-install it.
3. Save your environment file as "env.bat" <= From notepad, do a "File, Save As..." Be *SURE* to Go into the pull-down dialog and set "Save as Type" to "All Files". This is very important - or notepad will always try to save your file with the suffix ".txt". And it won't work.
From notepad, select:
4. Create a "Hello.java" source program: From the command prompt, type: notepad
5. Save "Hello.java": From notepad, select:
6. OK: we're nearly done! Promise! Go to the C:\ root directory. From the command prompt:
7. Whew! After all that, hopefully, you'll see the text "Hello, Java!" printed out... [ December 10, 2005: Message edited by: Paul Santa Maria ]
Paul M. Santa Maria, SCJP
Joined: Dec 10, 2005
Thanks everyone! I made a bat file that sets my path and everything and I just run it in the command prompt before i do any compiling or running and everything works now.
Thanks for all the help! Now I can get to the actually programming aspect of java lol