Naming Java Packages
Java package names are identifiers and therefore are subjected to the same limitations imposed on naming classes, variables, methods, etc.
Although this still gives you lots of freedom when naming packages, there is a package-naming scheme promoted by Sun to which you should consider adhering. Sun's naming scheme involved using the domain name of your Web site as the beginning of a package name, followed by more descriptive names that describe the set of classes you are packaging.
The purpose of this scheme is to help assure that all Java classes are uniquely identified.
The domain name of my Web site is thetribe.com, so a package containing my own custom animation classes might be named com.thetribe.animation
.
Placing my animation classes in this package guarantees uniqueness because the domain name thetribe.com
is not used by anyone else.
Of course, you may not even have a domain name or you may be developing classes for use in a stand-alone Java application that has no association with the Internet. In this case, the naming of your packages is less of an issue.
Naming a Package
With programmers worldwide writing classes and interfaces using the Java programming language, it is probable that many programmers will use the same name for different types.
The compiler allows both classes to have the same name if they are in different packages. The fully qualified name of each class includes the package name.
The fully qualified name of the Rectangle class in the graphics package is graphics.Rectangle, and the fully qualified name of the Rectangle class in the java.awt package is java.awt.Rectangle.
This works well unless two independent programmers use the same name for their packages.