Using an Integrated Development Environment
In this section, we show you how to compile a program with Eclipse, an integrated development environment that is
After starting Eclipse, select File -> New Project from the menu, then select "Java Project" from the wizard dialog (see Figure 2-2). These screen shots were taken with Eclipse 3.0M8. Don't worry if your version of Eclipse looks slightly different. Figure 2-2. New Project dialog in Eclipse
Click the "
Figure 2-3. Configuring an Eclipse project
The project is now created. Click on the triangle in the left pane next to the project window to
Figure 2-4. Editing a source file with Eclipse
With the right mouse button, click on the project name (Welcome) in the leftmost pane. Select Build Project from the menu that pops up. Your program is compiled. If it compiles successfully, select Run -> Run As -> Java Application. An output window appears at the bottom of the window. The program output is displayed in the output window (see Figure 2-5). Figure 2-5. Running a program in Eclipse
Locating Compilation Errors
Presumably, this program did not have typos or
public static void main(
s
tring[] args)
Now, run the compiler again. You will get an error message that complains about an unknown string type (see Figure 2-6). Simply click on the error message. The cursor moves to the matching line in the edit window, where you can correct your error. This behavior allows you to fix your errors quickly. Figure 2-6. Error messages in Eclipse
These instructions should give you a taste of working in an integrated environment. We discuss the Eclipse debugger in Chapter 11. |
|
|
Compiling and Running Programs from a Text Editor
An integrated development environment accords many comforts but also insinuates some drawbacks. In particular, for simple programs that are not distributed over multiple source files, an environment with its long startup time and many
NOTE
Emacs is a splendid text editor that is
Another popular choice is JEdit, a very nice editor written in Java, freely available from http://jedit.org. Whether you use Emacs, TextPad,
Figure 2-7 shows the Emacs editor compiling a Java program. (Choose JDE -> Compile from the menu to run the compiler.) Figure 2-7. Compiling a program with Emacs
The error messages show up in the lower half of the window. When you move the cursor on an error message and press the ENTER key, the cursor moves to the corresponding source line. Once all errors are fixed, you can run the program by choosing JDE -> Run App from the menu. The output shows up inside an editor window (see Figure 2-8). Figure 2-8. Running a program from within Emacs
|
|
|