PDA

View Full Version : HelloWorld.java



Sylvie
11-08-2006, 03:05 AM
Okay so I have this book called: Java Programming for the Absolute Beginner. I typed in this on notepad:




/*
* Hello World
* The classic first program
*/

public class HelloWorld {

public static void main(String args[]) {
System.out.println("Hello, world!");
}

}

So, the thing says to compile it. It makes me install Java SDK and this crap that doesn't work on my computer.

What I'm wondering is, is there a way to compile this stuff without going on the command prompt?
</pre>

Dr Unne
11-08-2006, 03:37 AM
So, the thing says to compile it. It makes me install Java SDK and this crap that doesn't work on my computer.

What I'm wondering is, is there a way to compile this stuff without going on the command prompt?
</pre>

The command line is by far the easiest way. What kind of problem are you getting when trying via the command prompt?

Sylvie
11-08-2006, 03:54 AM
Well, the book says to enter "javac HelloWorld.java" in the directory where you saved it. I keep getting an error and the thing isn't working.

Dr Unne
11-08-2006, 04:09 AM
Well, the book says to enter "javac HelloWorld.java" in the directory where you saved it. I keep getting an error and the thing isn't working.

What is the error? That's the thing I actually need to know.

Sylvie
11-08-2006, 04:19 AM
Alright, so the default directory is:

C:\Documents and Settings\Genji>

I put in:

C:\Documents and Settings\Genji> cd My Documents

Because thats where the file is located.

So I do that, and now its

C:\Documents and Settings\Genji\My Documents>

Now I put:

C:\Documents and Settings\Genji\My Documents>javac HelloWorld.java
'javac' is not recognized as an internal or external command, operable program or batch file.

So thats the message I get.

Dr Unne
11-08-2006, 04:37 AM
The problem is that javac is not on your $PATH. run

echo $PATH

and it will show you what $PATH currently is. $PATH is where it searches for executables every time you type a command on the command line. Java directories have to be included in that list or else DOS can't find them. So you either have to add the Java directory to your $PATH, or you have to type the full pathname to javac every time you run it, i.e. c:\j2sdk_version\blah\blah\bin\javac or something similar.

Try this: http://www.cs.colostate.edu/helpdocs/JavaPaths.html#XP

Sylvie
11-08-2006, 04:46 AM
You're the man, you know that Unne? :D

Thanks a ton, that was much more clearer than the book. :thumb: