Java com.* package namespace

Java

Java Problem Overview


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

Java Solutions


Solution 1 - Java

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 - Java

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

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 - Java

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

Solution 5 - Java

Package represent a directory that contain related group of class and interface. package are two type.

  1. Built in package.
  2. user define package. note. a package can contain sub package. eg. java.awt(here awt is a package); java.awt.event(here event is a sub package which present in java.awt)

Solution 6 - Java

If you didn't do that before - download some source code of some Java application (http://www.jedit.org/">jEdit</a> for example) and look and the files structure in the sources. It will clarify everything a bit probably. in jEdit there are several different packages, so you'll see how everything works.
And by the way - if you never read anyone's code - go and do it ASAP!! Even if you don't understand everything or just a small parts - do it as it's a great school of good programming practices!!!

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionStanView Question on Stackoverflow
Solution 1 - JavapolygenelubricantsView Answer on Stackoverflow
Solution 2 - JavaCarl SmotriczView Answer on Stackoverflow
Solution 3 - JavaT.J. CrowderView Answer on Stackoverflow
Solution 4 - Javabruno condeView Answer on Stackoverflow
Solution 5 - JavaMahee yadavView Answer on Stackoverflow
Solution 6 - JavatrzewiczekView Answer on Stackoverflow