
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Package Syntax
|
239
Package Syntax
Every package has a name that describes the classes it contains. By convention, pack-
age names do not use initial caps but might use mixed case, such as greatUtils. This
helps distinguish them from classes, which by convention start with a capital letter.
For example, a package that contains classes for a game might be named game, while
a package that contains general utilities might be named tools, and a library of visual
classes might be named graphics. Delaying, for a moment, the discussion of how to
create a package, let’s see how the classes within an existing package are accessed.
To refer to a specific class within a package, we use the dot operator, as follows:
packagename.ClassName
For example, in the following code, the names game, tools, and graphics are package
names and the names Player, Randomizer, and Vector2D are class names:
game.Player
tools.Randomizer
graphics.Vector2D
Packages can be nested to form a hierarchy; that is, a package can contain another
package. For example, the game package might contain a vehicles package that con-
tains a SpaceShip class. When referring to a class in a nested package, separate each
package name with the dot operator. For example:
game.vehicles.SpaceShip
By nesting packages, we can organize our classes ...