Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do you set a text file as a JAVA file?

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
It says both in my java book and a tutorial I looked at that you put your source code into a text editor and then save it as a JAVA file. How do I make a text file into a JAVA file?
 
Set the file extension to .java :) (example01.java).
[sig][/sig]
 
you just have to rename the file to .java from txt.
 
I tried, it won't let me. It just saves as {classname}.java.txt whenever I try.
 
Nevermind, I got it to work now. But how do I use my Javac compiler now?
 
if you are using a PC then go to MS DOS prompt, and then use Javac [filename].java to compile.

see if you installed java correctly.

go to and obtain the installation pages.

This should sort your probs!!! [sig][/sig]
 
actually try http//java.sun.com

my mistake!!! [sig][/sig]
 
in notepad the easiest way to make sure that you saved it has a .java file is when you save it in the file name prompt type in "Whatever.java" and the file type is .txt the "" tell windows to save it exactely as that. It works in most other programs as well.

[sig]<p>ackka<br><a href=mailto:tmoses@iname.com>tmoses@iname.com</a><br><a href= my site</a><br>"Do No Harm, Leave No Tracks"<br>
ICMP Summer 2000, 2600 Article<br>
<br>
[/sig]
 
&quot;if you are using a PC then go to MS DOS prompt, and then use Javac [filename].java to compile.&quot;

It says the same thing in my book, but it doesn't work. I put that command after opening the Javac program through the MS-DOS prompt, but it just says &quot;Bad command or file name&quot;

Any idea what might be wrong?
 
The reason is that the jdk does not automatically put a dos path to the executable(javac.exe) You have to put this in manually. The following is dependent on where you installed your jdk to. If you installed to c:\jdk1.3 then this will work. What you do is go to dos prompt, thpe in path c:\jdk1.3\bin
then javac classname.java

good luck :) [sig]<p>ackka<br><a href=mailto:tmoses@iname.com>tmoses@iname.com</a><br><a href= my site</a><br>"Do No Harm, Leave No Tracks"<br>
ICMP Summer 2000, 2600 Article<br>
<br>
[/sig]
 
That is what I did, ackka. It doesn't work. I opened the program, some stuff popped up, and then I put in the code that's SUPPOSED to compile the thing, but it just says &quot;Bad Command or File Name&quot;
 
in your autoexec.bat file there should be a line
[tt]PATH=C:\WINDOWS;C:\WINDOWS\COMMAND;[/tt]...
add
[tt]C:\java1.2.2\bin\[/tt] or wherever your java binaries ar located to the end.
then run autoexec.bat either by typeing that a dos prompt or by rebooting [sig]<p>Chris Packham<br><a href=mailto:kriz@i4free.co.nz>kriz@i4free.co.nz</a><br><a href= > </a><br>A thousand mokeys at a thousand machines, it happened, it got called the internet.[/sig]
 
Just did that. It doesn't work. Put this into that BAT file:
C:\java1.2.2\bin
When I restarted and ran autoexec.bat, just some anti-virus thing ran. Nothing else. And the code still wouldn't work :(
 
Oops! I meant
C:\jdk1.3\bin
That's the location
And it still doesn't work :(
 
What version of java have u obtained??

just follow the java installation procedure ok.

If you do not know how to set your CLASSPATH, then just save your work in the BIN folder of your java program.
You know how to save as a .java file now.

At the MSDOS prompt type the whole path to your program, so it will roughly be something like this c:/pragram files/jdk1.3/bin/ then type in ls, which should bring up all the files in that directory.

Your program should be there. Now at the prompt type in javac [programName].java
it should not be javac [programName.java].java ok!!!!

now it should compile.

If you get a whole list of errors, its coz u aint written your program correctly, check capitals, spaces, sem colons etc. Then save and compile.

This should work!!!!!
 
the above was written by me, sorry i forgot to log in!!! [sig][/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top