开发者

Why is the root package in source code called "com"? [duplicate]

This question already has answers here: Java packages c开发者_如何转开发om and org (4 answers) Closed 6 years ago.

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:

  1. Domain name: sun.com => Root package name something like : com.sun
  2. Domain name: technotalkative.com => Root package name something like: com.technotalkative.android
  3. 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜