File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes MyFirstApp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "MyFirstApp" Watch "MyFirstApp" New topic
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: 19695
    
  20

Are you in the same folder as the Java file?


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
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: 38851
    
  23
. . . 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: 38851
    
  23
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: 38851
    
  23
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 into
  • Control Panel
  • Folder Options
  • View
  • Un-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 as
  • Then 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.
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: MyFirstApp