Why is the root package in source code called "com"? [duplicate]
In most source codes, the root package/folder is named "com". Why is that so? It it just convention or does it stand for something?
The convention is that a programmer in a given organization will start package names with their organization's domain name, as a unique identifier -- in reverse order. This prevents namespace clashes between code from different organizations (within the organization you're on your own).
So if I work for a company called Supercompany, and their domain is supercompany.com, all of my package names will start with com.supercompany
. And since a lot of code is written for companies, a lot of packages start with com. However, there are plenty of packages that start with "net" or "org" or other such top-level domains. Myself, I work for a university, so my package names generally start with "edu".
The brief answer, then, is that most package names start with "com" because most domain names end with "com".
Its not necessary that it always start with .com.
What is it exactly?
Its actually package naming convension.
How to decide root package name?
Generally we android developer having practice to decide package name based on the domain name of a particular company.
For example:
- Domain name: sun.com => Root package name something like : com.sun
- Domain name: technotalkative.com => Root package name something like: com.technotalkative.android
- Domain name: sun.org => Root package name something like: org.sun.androidapp
For more information, check: What should be the package name of android app?
Because it's sun.com and the vast majority of packages come from a company. For apache.org packages, the root is org, and so on. It's just a reverse (canonical) domain name namespace.
精彩评论