Discussion Locked

compiling .java into .class applets?

0 helpful
8 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I bought a java2 complete book and downloaded the SDK bundle to run the java programs. I wrote the simple "hello.java" program and when I went to compile it in MS-DOS it gave me an error
error: Can't read: hello.java
1 error

I'm using notepad to write the code and saved it as "txt document" and "all file" both times it gave me the same error.

I know the path statement is right because it ran the demos just fine.

Is there anyway I can save it just as hello.java instead of hello.java.txt?? I think that is why MS-DOS can't read it cuz it see the .txt at the end of the file name.

Any suggestions??

8 replies

by timthetoolman

Under windows explorer, you need to change tools -> folder options -> then on the view tab, uncheck the "Hide extensions for known file types" so that you can see the extension.

Then simply rename the file - it'll now show in windows explorer as hello.java.txt

Also make sure you have the case of the filename exactly the same as the class definition in the java file.

Cheers,
Tim.

by jay eckles

Notepad automatically appends .txt to the end of your file name, even if you provide another extension. So if you enter hello.java, it will save the file as hello.java.txt. To prevent this, when saving the file, type the name in quotation marks: "hello.java".

by diva_cen2000

hi,

basically if ur writing a java program u may edit the program in any editor but while saving the program u have to save the program with .java extn

eg:

class example
{
p s v m(s[])
{}
}

save the above program as "example.java".u may use double qoutes if u have the program in notepad not if u have edited in the MSDos.

because some of the dos prompt does not accept files with four letter extension.

compile the program as : javac example.java

there is an another case

1.u can save the java program with an name.

2.if u have declared the class public then u have to save the program with the class name.

3.while running the program :java example

though u have saved the java program in any name if u have not declared the class as public
u have to use the class name which has the main method :java example -> class name with main method

This discussion is closed to new replies.