| Author |
MyFirstApp
|
j patrick
Greenhorn
Joined: May 02, 2008
Posts: 11
|
|
Hi i just bought head first java band cant compile the 'MyFirstApp' code, can anyone help? I have written the code in wordpad ie: public class MyFirstApp { public static void main (String [] args) { System.out.println("I Rule!"); System.out.println("The World!"); } } set the path and this is recognised by the command prompt (i type path and it returns c:\Program Files\java\jdk1.5.0_03\bin) so i type 'javac MyFirstApp.java' and it returns 'error: cannot read: MyFirstApp.java I can feel that there is something really elementary im doing wrong, can anyone help? cheers
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
|
Are you in the same folder as the Java file?
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
j patrick
Greenhorn
Joined: May 02, 2008
Posts: 11
|
|
|
Im not sure
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32611
|
|
. . . and welcome to the Ranch. When you go into command prompt or a terminal window, you get a prompt at the left showing where you are. On Windows you tend to start in MyDocuments or similar. Which folder did you put the MyFirstApp file in? Maybe it was c:\\java\apps, in whihc case write "cd c:\\java\apps" and go to that folder. Then try "dir" (Windows) or "ls" (*nix) to find the contents of that folder. Then try again. If you are on Windows and have the app on a floppy disc, try simply writing "a:" to get to the floppy disc.
|
 |
j patrick
Greenhorn
Joined: May 02, 2008
Posts: 11
|
|
ive copied the code into notepad and saved it and it seems to work, i think wordpad was saving it with .rtf or .txt, thanks for the help anyway. cheers
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32611
|
|
|
Notepad is notorious for that sort of thing. Get yourself Notepad++ or Notepad2 or similar. Much better than Notepad or Wordpad.
|
 |
j patrick
Greenhorn
Joined: May 02, 2008
Posts: 11
|
|
I got 'MyFirstApp' to work, but now nothing else compiles?? Has anyone else had problems with notepad or not being able to compile java files??
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32611
|
|
As I said, try something different from Notepad. It is notorious for appending .txt to the name of your files. To see those extensions go intoControl PanelFolder OptionsViewUn-tick/un-check "hide extension for known file types."If you still use Notepad, you have to put "" quotes round the name of the file when you use save asThen you can see how many files you have called MyFile.java and how many called MyClass.java.txt. Try Notepad++; when you save the file with a .java extension, it gives automatic indentation, highlights matching bracket pairs, and displays keywords in different colours. Makes programming much easier. The other app I recommended, Notepad2, is also better than Notepad.
|
 |
 |
|
|
subject: MyFirstApp
|
|
|