• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Rob Spoor
  • Henry Wong
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh
  • Jj Roberts

MyFirstApp

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 22116
114
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you in the same folder as the Java file?
 
j patrick
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Im not sure
 
Marshal
Posts: 72416
315
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
. . . 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
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Marshal
Posts: 72416
315
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Notepad is notorious for that sort of thing. Get yourself Notepad++ or Notepad2 or similar. Much better than Notepad or Wordpad.
 
j patrick
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Marshal
Posts: 72416
315
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
     
    Water proof donuts! Eat them while reading this tiny ad:
    SKIP - a book about connecting industrious people with elderly land owners
    https://coderanch.com/t/skip-book
    reply
      Bookmark Topic Watch Topic
    • New Topic