It's quite often to see com.* package namespace. What does 'com' mean? Thanks.
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.
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.
Companies use their reversed Internet domain name to begin their package names—for example, com.
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.
The naming convention for packages is specified in the JLS. Here is the relevant snippet (there's a lot more in the section):
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".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With