
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Package Syntax
|
243
Package Naming Conventions
Earlier we posed a scenario in which a game and a music component each defined
unrelated classes named Player. We learned how packages could fix this problem by
providing a unique, fully qualified identifier for each class. For example:
musiccomponent.Player
game.Player
But this merely trades one problem for another. We still need a way to prevent one
application’s game.Player class from conflicting with another application’s game.
Player class. In other words, just as two class names can conflict, two package names
can conflict. To avoid package or class naming conflicts you should use the conven-
tion of placing all your classes and packages in a package named after your organiza-
tion’s domain name. For example, classes and subpackages created by Acme Corp.,
whose domain name is acme.com, would be stored in the package:
com.acme
Notice that com precedes acme (the package name is the reverse of the domain name).
Thus, a game.Player class created by Acme and a game.Player class created by, say,
Nintendo, could be stored safely in the following unique packages:
com.acme.game.Player
com.nintendo.game.Player
Domain names are guaranteed to be unique by the system of authorized top-level-
domain (TLD) registrars; thus, starting your package names ...