©2010 Felleisen, Proulx, et. al.

5  Understanding Constructors; Equality

5.1  Standard Java and the tester library

Goals

Starting with this lab we will use the standard Java language. Of course, we only know a small part of the language. We will learn new features when they are needed to support our program design process.

Moving to standard Java: File organization

Standard Java Project differs very little from the projects we have built so far. The main difference is that standard Java expects you to define every class and every interface in a separate file whose name is the name of the class or interface, followed by .java. So, if our project contains classes Book, the class Author, and the class ExamplesBooks, we will need to define these classes in files Book.java, Author.java, and ExamplesBooks.java. Typically, each Project contains all files that are used to solve one problem.

Moving to standard Java: Visibility modifiers

The first new feature of the standard Java we need to introduce is the use of visibility modifiers. In Java every class, interface, field, method declaration, and method definition in Java typically starts with one of the words public, private, or protected. The fields and methods declared to be public can be accessed and are visible to all other classes — the way we have been using the fields and methods in FunJava. Fields or methods declared to be private can only be accessed within the class in which they are defined. So, for example, if we need a helper method that is not relevant for anyone using our class, we would make this a private method. We will have example of the use of the private visibility modifiers over the next couple of weeks.

If the visibility modifier is omitted, as we have done, the methods and fields can be used by any other classes within the same package. In our projects, all classes are defined in the default package, and so we only need to add the visibility modifiers when it serves a specific purpose:

We will worry about the protected visibility modifiers later.

Moving to standard Java: Setting up a Project

Moving to standard Java: Setting up the Run Configuration

Moving to standard Java: Zipping up the Project

You can create an archive of your project by highlighting the project, then choose Export then select Archive File. Eclipse will ask you for a folder where to place the zip file and will let you choose the name for the zip file.

Your project will remain in the Eclipse workspace, but now you have saved a copy that will not change as you keep working.

This is also the file that you will be submitting as your homework.

Last modified: Wednesday, October 6th, 2010 3:46:12pm