How To Develop Java Using Textpad
The TextPad text editor that came on your student CD has many features that will help
you write Java source code. The trick is to let TextPad know you are writing Java and not
As an experiment, open one of the .java files that came with your student files in TextPad.
Note that the text is color coded. Keywords are blue, punctuation symbols are red,
comments are green, and literals (literal strings enclosed in “”, for example) are a sort of
turquoise. The color coding is designed to help you recognize and correct mistakes more
Now, as a second experiment, open a new document in TextPad and start writing a
simple Java application. Use the three lines below if you wish:
// A simple Java program
Public class MyFirst
Notice that the text you typed is not color coded as was the program you opened. That’s
because TextPad does not know you’re writing Java (yet). To tell TextPad you’re a Java
programmer, save your file using the extension .java. Use Save As from the file menu to
name your file correctly and place it in the directory of your choice. A good habit to
develop is to write the first line or two of a new program, then save it using the correct
class name with .java extension, then continue writing your code.
***Note*** You must name the file using the name of the declared public class!!
If you do not, Java will refuse to compile your code.
In the example above, the name of the file must be: MyFirst.java
Java is a case-sensitive language. The file name must be identical to the class name in
both spelling and case. In other words, myfirst.java is incorrect and will not work.
Note that once you save the file with a .java extension, TextPad displays your code with
the color coding described earlier.
Look at the options available in the TextPad Tools menu. Note the last three:
Run Java Application
Run Java Applet
These commands allow you to quickly and easily compile and execute your Java
programs without using a command prompt window or memorizing commands.
To compile your Java source code, simply select Compile Java from the Tools menu.
If your code is free of syntax errors, your source code will reappear in the edit window
and a message: “Tool completed successfully” will be displayed in the Status Bar
(bottom-left of the TextPad window). If errors are found, an error list will be displayed in
the edit window. The error messages are reasonably clear and include a line number in
the source code where the error was encountered. At this point, you may want to have
TextPad display line numbers with your source code. Select the View menu, then the Line Numbers selection. TextPad will now display line numbers with your code. (Note:
the line numbers do not become part of your code saved to your file).
To return from the error list displayed in the edit window, to your source code, simply
select your source code file from the list of open files displayed in the window just to the
left of your edit window. If you selected View->line Numbers, you will see line numbers
displayed with your code.
**A word on correcting syntax errors** Always fix the first (topmost) error in the list! Then, recompile your source code. Why? Because the compiler can become “confused”
as errors are encountered and will begin to list errors that are not really there. Fixing the
first error will often remove several subsequent errors from the list because the compiler
now “understands” what you were trying to do. Continue this process until all syntax
errors are eliminated.
Once you have compiled your source code successfully (no errors), you can run your
Java application (applets will be discussed at the appropriate time as the class progresses)
by selecting Tools-> Run Java Application in TextPad. Your application will run an display output in a command prompt window.
The following applies to CIT1613 students only. Getting user input into your Java programs: Although this topic has nothing to do with TextPad, per se, I’m including it here because you’ll encounter the need to capture
user input almost immediately. The author presents two alternative ways to capture user
input from the keyboard.
1. Use the Scanner class as instructed in your book.
2. Use JOptionPane dialogs to display prompts and capture input. If you use this
option, you must use an import statement to let Java know where to find the
desired class in the Java API. The statement you need to add, before your public
class header, is (with a comment included):
This should get you started. Have fun with Java!