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. Java packages.

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, and then select Run as Java application from the Run menu. 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.

History

Sunday, 30 January 2005 [Samuel A. Rebelsky]

Tuesday, 30 August 2005 [Samuel A. Rebelsky]

Wednesday, 25 January 2006 [Samuel A. Rebelsky]

Thursday, 26 January 2006 [Samuel A. Rebelsky]

Thursday, 30 March 2006 [Samuel A. Rebelsky]


This page was generated by Siteweaver on Thu Mar 30 15:24:23 2006.
The source to the page was last modified on Thu Mar 30 15:24:16 2006.
This page may be found at http://www.cs.grinnell.edu/~rebelsky/Espresso/Readings/eclipse.html.

You may wish to validate this page's HTML ; Valid CSS! ; Check with Bobby

Samuel A. Rebelsky
rebelsky@grinnell.edu