Java com.* package namespace [duplicate]

It's quite often to see com.* package namespace. What does 'com' mean? Thanks.


Solution 1:

The naming convention for packages is specified in the JLS. Here is the relevant snippet (there's a lot more in the section):

JLS 7.7 Unique Package Names

You form a unique package name by first having (or belonging to an organization that has) an Internet domain name, such as sun.com. You then reverse this name, component by component, to obtain, in this example, com.sun, and use this as a prefix for your package names, using a convention developed within your organization to further administer package names.

It's also given in Naming Conventions section of Sun's code conventions document:

Packages: The prefix of a unique package name is always written in all-lowercase ASCII letters and should be one of the top-level domain names, currently com, edu, gov, mil, net, org, or one of the English two-letter codes identifying countries as specified in ISO Standard 3166, 1981.

Subsequent components of the package name vary according to an organization's own internal naming conventions. Such conventions might specify that certain directory name components be division, department, project, machine, or login names.

Examples: com.sun.eng, com.apple.quicktime.v2, edu.cmu.cs.bovik.cheese


So com. prefix in package names means the same as .com suffix in domain names: "commercial".

Solution 2:

When it created Java, Sun established a convention that package names should be constructed starting with the reversed domain names of the company or individual creating the package. Because DNS guarantees that domain names are unique (i.e. given to only one organization or person), this avoids duplication.

So Java packages by Microsoft have names starting with com.microsoft, those from Sun are com.sun and so on.

Solution 3:

Java packages other than the standard libraries are typically named in reverse order of the domain of the vendor, e.g. Microsoft uses com.microsoft, Apache may use org.apache, etc. (See this link for details on naming conventions in Java.) This is to prevent naming conflicts. So the com is just part of the domain name, it has no special meaning to Java.

There is no requirement that you name your packages that way, it's just a very good idea for any package that may remotely end up being used outside your organization.

Solution 4:

com is derived from commercial. Like org is derived from organization.