Hello, I am completely new Java, and I cannot compile via command line. I set up the Java SDK, and have made my first program that is found on this site, but when I type Javac MooseGreetings.java it says " 'javac' is not recognized as an internal or external command" I have set the path and all, but it just won't work. What am I doing wrong?
You do not say what kind of system you are on -- on most operating systems, there is some way for the system to look up the program you are trying to run.
On Windows, for example, the OS looks for a BAT, COM, or EXE file with the command name somewhere on the "path". "Path" is an environment variable; you can see what yours is from the command line by entering "echo %path%". You will see a list of directories separated by semicolons; Windows (aka DOS) looks in each of these directories in turn for the command you enter. It checks for some internal commands as well, but they need not concern us here.
Rather than have me try to describe how to set an environment variable, try searching for instructions to do so on whatever system you have. Then add the proper directory to the path so that the directory that contains javac.exe (or whatever it is you are going to run) is on the path. It needs to be an "absolute" path (starting with the drive specification), since you want it to work from different directories.
Ralph Cook wrote:You do not say what kind of system you are on . . .
Only Windows throws that particular error message.
Welcome to the Ranch Jackson Thurston. Ralph Cook is absolutely correct, that it is a PATH problem. Lots and lots of people have that problem. So we have an FAQ which tells you how to set your PATH. Note it doesn't tell you how to set a CLASSPATH.
Did you close and reopen your command line window? It won't recognise the new PATH on an old command line window.
The simple answer to how to set a CLASSPATH is - - - don't!
I am feeling like an idiot. When setting the Path, I put %JAVA_HOME%\bom instead of %JAVA_HOME%\bin. Well, thanks for the help anyway!
Also, in the book Head First: Java, in chapter 5, am I suppose to save it all in one java file, or multiple?
EDIT: Now I am feeling like even more of an idiot. I said "I am feel like an idiot"
Probably better to have each Java™ class in its own file. If the class is labelled public, it must go in a file with the same name as the class, so you can't get two public [top-level] classes in the same file.
At this stage it is best to omit any package names.