Espresso: A Concentrated Introduction to Java


Java Programming in Eclipse

Summary: We describe how to compile and use Java in the Eclipse software development enviornment.

Prerequisites: Unix basics. Java basics.

Disclaimer: Although I use the term Unix throughout this document, the ideas apply equally well to Linux, the variant of Unix we use in MathLAN.

Contents:

About Eclipse

There are a variety of ways in which one can develop Java programs. It is certainly possible to develop Java programs using a simple editor, such as gedit, and command-line tools for compiling and running Java programs. However, many programmers find it easier to build programs in an environment designed explicitly for editing, running, and testing programs.

Eclipse is an industrial-strength integrated development environment designed generically for working with programs. Although Eclipse can be used to develop programs in a variety of languages, it is frequently used as a Java development environment. Eclipse has been implemented for all three major operating systems (Macintosh OS X, Microsoft Windows, and Unix variants, including Linux).

Because Eclipse is designed for professional software development, you may find it a bit cumbersome at first. However, after a week or two, you will find it relatively comfortable for software development, and a few weeks later, you'll find that it helps you work more efficiently.

Detour: Naming Files

For the purposes of your initial work in Java, you will find it most convenient to have one class per file. (As we will soon see, if you make changes to one class, this limits the amount of extra work the computer must do to incorporate changes.) The name of the file must match the name of the class. It must also end with the suffix .java. For example, if I created a class named First, it would go in the file First.java. Fortunately, Eclipse follows this naming convention.

Setting Up Your Program

As suggested above, it's a little bit cumbersome to set up Eclipse to edit a Java program (that is, a collection of .java files).

Running Your Program

In comparison to all of the setup steps mentioned above, running your Java program is fairly easy. Save your file, then select Run As from the Run menu, and then select Java application. In many cases, the output will appear in a console at the bottom of the screen.

Importing Projects

At times, you will find it more convenient to set up your project outside of Eclipse and then import the directory structure and .java files into Eclipse. It is also relatively straightforward to create projects that way.


Written and revised by Samuel A. Rebelsky, 2005-2006.
Revised further by Marge M. Coahran, 2006.
Samuel A. Rebelsky
rebelsky@grinnell.edu
--->