Editing Your First Java Program
w/Text Editor
(Free Web Tutorials & Resources)
by Michael Thomas
Java First Steps Home Page
You can use any text editor to edit the Java Programs. One of the best
environments to program in is called an IDE (Integrated Development
Environment). For training purposes, you do need to create some programs
using a Text Editor and the DOS compile process.
Warning: Some programs created with unix vs Mac vs Windows systesm may
use different end of line characters. This may cause some editors to read
in the source code differently. A good text editor will take care of this
for you.
To complete this section, you should have already completed the "Compile
Your First Program" step of Java, Your First Steps.
We will be using both the files downloaded and the compile process in this prior
section to complete this section.
Editors that come with Windows (NT and/or Win 98)
- WordPad
- Start, Accessories, Word Pad
- Now open up the program "MyFirstApplet.java" created
in the "Compile Your First Program" step of Java, Your First Steps.
- Change the words, "Hello World" to "Hello Mickey
Mouse"
- Recompile the program and test.
- Features/Problems
- Opens larger programs.
- Not really designed for the programmer.
- May have problems w/Unix source.
- NotePad
- Start, Accessories, Note Pad
- Now open up the program "MyFirstApplet.java" created
in the "Compile Your First Program" step of Java, Your First Steps.
- Change the words, "Hello World" to "Hello Mickey
Mouse"
- Recompile the program and test.
- Features/Problems
- Opens programs totally in memory - so you may run out of memory on
large programs.
- Not really designed for the programmer.
- May have problems w/Unix source.
- Note: NotePad adds the extension .txt to files that you
create. If you put the file name in quotes it will not (ie:
" MyFirstApplet.java" )
- Edit.dom (DOS Only) - Not sure about Win NT.
- Go to a DOS prompt.
- Type the command: edit
- Now open up the program "MyFirstApplet.java" created
in the "Compile Your First Program" step of Java, Your First Steps.
- Change the words, "Hello World" to "Hello Mickey
Mouse"
- Recompile the program and test.
- Features: Has line #'s.
Create for First Applet & Application from Scratch
-
Get Ready to Program
- Launch your text Editor.
- Create your first Java Application using your editor.
- Name your file "HelloWorld_application.java"
public class HelloWorld_application {
public static void main( String [] args ) {
System.out.println("Hello World from an Application.");
}
}
- Now create a file called "HelloWorld_application_compile.bat"
javac HelloWorld_application.java
pause
- In Windows Explorer, double click on the compile batch file. It
should bring up a DOS window and compile your program.
- Now create a file called "HelloWorld_application_run.bat"
java HelloWorld_application
pause
- In Windows Explorer, double click on the run batch file. It
should bring up a DOS window and show the words "Hello World from
an Application"
-
Debug your application.
-
Go back to the "Source Editor" where you typed
your program in.
Now create a "compile error" in your program.
Delete the word "void" from line #2.
Should be: public static main( String[] args ) {
Now click on the compile batch file again and look
at your errors.
Fix your code and recompile again.
Now, run your program again.
- Create your first Java Applet using your editor.
- Name your file "HelloWorld_applet.java"
import java.applet.Applet;
import java.awt.Graphics;
public class HelloWorld_applet extends Applet {
public void paint(Graphics g) {
g.drawString("Hello World from an Applet.",25,25);
}
}
- Now create a file called "HelloWorld_applet_compile.bat"
javac HelloWorld_applet.java
pause
- In Windows Explorer, double click on the compile batch file. It
should bring up a DOS window and compile your program.
- Create your first HTML file that launches an Applet.
- Name your file "HelloWorld_applet.html"
<html>
<head>
<title>Hello World - Applet only</title>
</head>
<body>
<h1 align="center">Hello World - Applet</h1>
<applet code="HelloWorld_applet.class"
align="baseline"
width="275" height="55">
</applet>
</body>
</html>
- Now create a file called "HelloWorld_applet_view.bat"
appletviewer HelloWorld_applet.html
- In Windows Explorer, double click on the appletviewer batch
file. It should bring up a Java window which will display the
applet using Sun's appletviewer program.
- Next, in Windows Explorer, double click on the "HelloWorld_applet.html"
file and it should bring up your default browser and display the applet.
Congratulations - Your Finished!
Other Free Editors (Freeware)
Other Text Editors
- Other Editors
- MultiEdit Pro - great text editor.
- UltraEdit - great text editor.
- Edit+ - http://www.editplus.com/
- Quote from site, "EditPlus is an Internet-ready 32-bit text
editor, HTML editor and programmers editor for
Windows. While it can serve as a good replacement for Notepad, it also
offers many powerful features for Web page authors and
programmers." Is distributed as shareware and purchase at
$30.
- Med - Programmers Text Editor. Free 30 day trial. $30 for
private/educational single lifetime license. http://www.utopia-planitia.de
(German Site I think)