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 hello world code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "hello world code" Watch "hello world code" New topic
Author

hello world code

tny shariff
Greenhorn

Joined: Sep 18, 2004
Posts: 7
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

Joined: Mar 18, 2004
Posts: 40
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

Joined: Mar 20, 2005
Posts: 256
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..


Life called,so here I am.<br />Cheers<br />Niki.:-)
Giovanni De Stefano
Ranch Hand

Joined: Aug 17, 2004
Posts: 144
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


SCJP 1.4
Ramakrishna Nalla
Ranch Hand

Joined: Apr 21, 2005
Posts: 61
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

Joined: Dec 06, 2001
Posts: 3061
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


Java API Documentation
The Java Tutorial
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9044
    
  10
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.


JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: hello world code
 
Similar Threads
Problem with JDK at command prompt
Exception in thread "main" java.lang. NoClassDefFoundError: HelloWorldApp
Error by compiling textfile Could not find the main class: HelloWorldapp. Program will exit
helloworld error
Cant run apps[help]