Creating New Classes

Now that you have a project set up, you're going to want start writing some new classes. The easiest way to do this is to right-click on a project in the Package Explorer and select New > Class. This will bring up a totally sweet class creation window.

If you know what packages are and how to use them, you can specify what package your new class will fall into. For your assignments in this course, you should NOT use packages unless explicitly told to do so! When no package is specified, your new class will be placed in the "default" package (as it has been in the past with your CSE 142 assignments). If you're curious and impatient, however, check out working with packages.

The name of your new class is as you would define it in your file name (i.e. or the header for your class (i.e. public class BigDawg...), and therefore must follow Java naming rules. You are given the choice of giving your class one of various scopes (e.g. public, default, etc.) and several modifiers (e.g. final, etc.). For the purposes of this course, you can safely ignore both of those features. Make your classes "public" and don't worry about the rest. If you are extending another class, you can specify the superclass (parent class) either by typing its package and name (e.g. package = "java.lang.", class = "Object", so type "java.lang.Object"), or by clicking Browse.

After clicking "Browse," a window pops up and allows you to do an auto-complete search for the class that you want to use. Simply start typing (you don't need a package name) and the list of possible matches will appear below. The more you type, the more the specific the results will get. At any point, if you see the class you want to use, select it and click Ok.

Interfaces work in much the same way. Since you can create a class that implements an arbitrary number of interfaces, you must click Add once for every interface you want to implement. Clicking will pop open the same window that you use to search for classes. Search for an interface, select it, and click Add. When you've added all the interfaces you want, click Ok.

This window gives you a glimpse of what Eclipse can do for you. You have the option to have Eclipse generate method stubs (a method stub is a method which is defined but has no statements in it, or no functionality) for various types of methods. Among your options are a stub for the main(String[] args) method, any constructors from the superclass, as well as stubs for inherited abstract methods. Check any that you'd like generated. You can also have it set up JavaDoc comment stubs where possible by clicking the Generate Comments checkbox. Now you're all set. Click Finish and you have a new class!