Java com. * Package namespace

You can often see com. * package namespace. What does com mean? Thank.

+48
java
Apr 18 '10 at 9:13
source share
6 answers

The naming convention for packages is specified in JLS. Here is the corresponding snippet (in the section more):

JLS 7.7 Unique Package Names

You form a unique package name by first having (or belonging to an organization that has) a domain name on the Internet, for example sun.com . Then you drop that name, component by component, to get com.sun in this example and use it as a prefix for the names of your packages, using the agreement developed in your organization to further administer package names.

It is also listed in the Naming Conventions section of the Sun legend:

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

Subsequent components of a package name are distinguished by their own internal organization naming conventions. Such conventions may indicate that some components of a directory name are divisions, departments, projects, machines, or login names.

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




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

+53
Apr 18 '10 at 9:27 a.m.
source share

When he created Java, Sun made an agreement that package names should be built, starting with the inverted company domain names or individual package creators. Since DNS ensures that domain names are unique (i.e., provided only to one organization or person), this avoids duplication.

So, Java packages from Microsoft have names starting with com.microsoft , and from Sun - com.sun , etc.

+23
Apr 18 '10 at 9:17
source share

Java packages other than standard libraries are usually called in the reverse order of the provider domain, for example. Microsoft uses com.microsoft , Apache can use org.apache , etc. (See this link for more information on Java conventions.) This is to prevent name conflicts. Thus, com is only part of the domain name; it has no special meaning for Java.

There is no requirement that you name your packages this way, it is just a great idea for any package that can be remotely used outside your organization.

+7
Apr 18 '10 at 9:16
source share

com obtained from commercial. How org comes from organization.

+4
Apr 18 2018-10-18T00:
source share

A package is a directory that contains an associated class and interface group. package of two types. 1. Built-in package. 2. User define package. the note. a package may contain a subpackage. eg. java.awt (here awt is the package); java.awt.event (here the event is an additional package that is present in java.awt)

0
Apr 16 '13 at 9:36 on
source share

If you haven’t done this before, download some source code for some Java application (for example, jEdit ), and look at the file structure in the sources. All this will clarify the situation a bit. jEdit has several different packages, so you will see how everything works.

And by the way - if you never read any code - go ahead and do it as soon as possible! Even if you don’t understand everything or just small parts - do it as an excellent school of good programming methods !!!

-one
Apr 18 '10 at 10:21
source share



All Articles