Java Reference
In-Depth Information
18.1. Package Naming
A package name should prevent collisions with other packages, so choos-
ing a name that's both meaningful and unique is an important aspect
of package design. But with programmers around the globe developing
packages, there is no way to find out who is using what package names.
So choosing unique package names is a problem. If you are certain a
package will be used only inside your organization, you can use an in-
ternal arbiter to ensure that no projects pick clashing names.
But in the world at large, this approach is not practical. Package identifi-
ers are simple names. A good way to ensure unique package names is to
use an Internet domain name. If you worked at a company named Ma-
gic, Inc., that owned the domain name magic.com , the attribute package
declaration should be
package com.magic.attr;
Notice that the components of the domain name are reversed from the
normal domain name convention.
If you use this convention, your package names should not conflict with
those of anyone else, except possibly within your organization. If such
conflicts arise (likely in a large organization), you can further qualify us-
ing a more specific domain. Many large companies have internal subdo-
mains with names such as east and europe . You could further qualify the
package name with such a subdomain name:
package com.magic.japan.attr;
Package names can become quite long under this scheme, but it is rel-
atively safe. No one else using this technique will choose the same pack-
age name, and programmers not using the technique are unlikely to pick
your names.
 
Search WWH ::




Custom Search