Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java com.* package namespace [duplicate]

Tags:

java

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

like image 258
Stan Avatar asked Apr 18 '10 09:04

Stan


People also ask

Why do Java namespaces start with com?

It ensures that the code will never conflict with any other code, even if I later write the same code for another company. It can make accessing the code cumbersome (typing com.

Is namespace same as package in Java?

Packages are used in Java in order to prevent naming conflicts, to control access, to make searching/locating and usage of classes, interfaces, enumerations and annotations easier, etc. A namespace is designed for providing a way to keep one set of names separate from another.

What does COM mean in package name?

Companies use their reversed Internet domain name to begin their package names—for example, com.

What is the COM package Java?

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.


1 Answers

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".

like image 123
polygenelubricants Avatar answered Sep 30 '22 17:09

polygenelubricants