• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

hello world code

 
tny shariff
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
dear all,
im starting my 1st program java,i saved it as "HelloWorldApp.java". but i cant compile it- the error statement is error: cannot read: HelloWorldApp.java (im using console window)
pls help..

/*
* The HelloWorldApp class implements an application that
* displays "Hello World!" to the standard output.
*/
public class HelloWorldApp {
public static void main(String[] args) {
// Display "Hello World!"
System.out.println("Hello World!");
}
}

p/s:- i compile it as javac HelloWorldApp.java

error msg:error : cannot read: HelloWorldApp.java
1 error
 
Parth Sagdeo
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you save the file as HelloWorldApp.java? Is it in the right directory?
[ April 29, 2005: Message edited by: Parth Sagdeo ]
 
Niki Nono
Ranch Hand
Posts: 256
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
are you comppiling from the directory where you have the java file???
javac may be in the classpath but you still have to navigae to the directory where you have the java file and then try compiling..
 
Giovanni De Stefano
Ranch Hand
Posts: 161
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
it seems that the file is not there or it has a different name!
You are using the command line, aren't you? If you can type java from anywhere, then your JAVA_HOME environment variable is set properly...great...now you have to navigate to the directory where you actually saved your HelloWorld.java file, I would suggest c:\ just to be sure you don't get lost!
Once you have java in your path AND you are in the same directory where your java file is, then javac HelloWorld.java will do just fine, after that (if there are no errors) you will find HelloWorld.class, type java HelloWorld and you are set! :-)
P.S. The error you reported says that the compiler cannot find the source file, this means that you are in the wrong directory (just type dir and look for HelloWorld.java) OR you used something like Notepad which added the extension .txt to your java file (in this case you have HelloWorld.java.txt).
Good luck!
Giovanni
 
Ramakrishna Nalla
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi shariff welcome to JAVA world:
Comming to YOUR problem..As you using command line...(Linux or Windows ??)...
I am assuming windows...

Don't use notepad to write java programs, because it add extention .txt to your given name..for examle if you give filename: MyProg.java then it will be
MyProg.java.txt If you prefer to notepad only...then save file with double codes like "MyProg.java" and that's it.

That's problem only mistake of filename...better try in command line..

Command line: if u use directory C:\JAVAPRG\> ...then:

C:\JAVAPRG\>EDIT MyProg.java
Press ENTER...
write your program and save it and exit...and now...
stay in same directory
C:\JAVAPRG\>javac MyProg.java
Press ENTER....
---STILL SAME ERROR:
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I might agree that the DOS text editor is better than NotePad. However, I'd go a bit further and suggest that you download a REAL text editor like TextPad.

Also, let us know if the suggestions above helped at all.

Layne
 
Marilyn de Queiroz
Sheriff
Posts: 9066
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch, Tny Shariff. How do you pronounce your first name?

You might consider returning a thread that you start to see responses there and clarify any questions the responders ask before starting another almost identical thread.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic