Most computer programs are written in the same way that you write a letter—by typing each statement into a text editor. Some programming tools come with their own editor, and others can be used with any text-editing software.
When you have finished writing a computer program, you save the file to disk. Computer programs often have their own filename extension to indicate what type of file they are. Java programs must have the extension .java
, as in Calculator.java
.
If your text editor is a word processing program that has features such as boldface text, font sizes, and other stylistic touches, do not use those features while writing a computer program. Programs should be prepared as text files with no special formatting. Notepad, a word processor that comes with Windows, saves all files as unformatted text. You also can use the vi editor on Linux systems to create text files without formatting.
To run a program you have saved as a file, you need some help. The kind of help that’s needed depends on the programming language you’re using. Some languages require an interpreter to run their programs. The interpreter is a program that interprets each line of a computer program and tells the computer what to do. Most versions of BASIC are interpreted languages. The advantage of interpreted languages is that they are faster to test. When you are writing a BASIC program, you can try it out immediately, fix errors, and try again. The primary disadvantage is that interpreted languages run slower than other programs.
Other programming languages require a compiler. The compiler takes a computer program and translates it into a form that the computer can understand. It also makes the program run as efficiently as possible. The compiled program can be run directly without the need for an interpreter. Compiled programs run more quickly than interpreted programs but take more time to test. You have to write your program and compile it before trying it out. If you find an error and fix it, you must compile the program again.
Java is unusual because it requires both a compiler and an interpreter. You learn more about this later as you write Java programs.
18.191.135.214