J2EEOnline J2EEOnline

Java Fundamentals  «Prev 

Selecting Package Names

In an effort to avoid name collisions, Sun recommends using a package naming scheme intended to produce unique package names.
This scheme is based on inverting your Internet domain name. For example, a package named tools developed at acmecorp.com would have a full package name of com.acmecorp.tools. While some companies are using this naming scheme, others are simply using their company name to produce package names such as acmecorp.tools. Keep in mind that you are free to use any package naming scheme that you like.

Naming Conventions

Package names are written in all lower case to avoid conflict with the names of classes or interfaces.Companies use their reversed Internet domain name to begin their package names for example,


for a package named mypackage created by a programmer at j2eeonline.com.
Name collisions that occur within a single company need to be handled by convention within that company, perhaps by including the region or the project name after the company name (for example, com.example.region.mypackage).
Packages in the Java language itself begin with java. or javax.
In some cases, the internet domain name may not be a valid package name. This can occur if the domain name contains a hyphen or other special character, if the package name begins with a digit or other character that is illegal to use as the beginning of a Java name, or if the package name contains a reserved Java keyword, such as "int". In this event, the suggested convention is to add an underscore.