java 为什么源代码中的根包叫“com”?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4620045/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 07:15:13  来源:igfitidea点击:

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

javanaming-conventionspackages

提问by Umar Khan

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?

在大多数源代码中,根包/文件夹被命名为“com”。为什么呢?它只是约定俗成还是代表什么?

回答by Jacob Mattison

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

因此,如果我在一家名为 Supercompany 的公司工作,并且他们的域名是 supercompany.com,那么我所有的包名称都将以com.supercompany. 而且由于很多代码是为公司编写的,所以很多包都是以 com 开头的。但是,有很多包以“net”或“org”或其他此类顶级域开头。我自己,我在一所大学工作,所以我的包名通常以“edu”开头。

The brief answer, then, is that most package names start with "com" because most domain names end with "com".

简短的回答是,大多数包名称以“com”开头,因为大多数域名以“com”结尾。

回答by Paresh Mayani

Its not necessary that it always start with .com.

它没有必要总是以.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.

一般我们android开发者都有习惯根据特定公司的域名来决定包名。

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
  1. 域名:sun.com=> 根包名称类似于:com.sun
  2. 域名:technotalkative.com=> 根包名称类似于:com.technotalkative.android
  3. 域名:sun.org=> 根包名称类似于:org.sun.androidapp

For more information, check: What should be the package name of android app?

有关更多信息,请检查:android 应用程序的包名称应该是什么?

回答by SilverbackNet

Because it's sun.comand 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.

因为是太阳。com并且绝大多数软件包都来自一家公司。对于 apache.org 包,根是org,依此类推。它只是一个反向(规范)域名命名空间。