Java 包 com 和 org
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2125293/
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
Java packages com and org
提问by Gabriel
What are the meaning of the packages org
and com
in Java?
包org
和com
Java中的含义是什么?
回答by BalusC
You can also see package names as reversed internet domain names (which is often also true in real world, see for example the org.apache.commons
which correlate with http://commons.apache.org). The com
(commercial)and org
(organization)are here then actually Top Level Domainnames.
您还可以将包名称视为反向 Internet 域名(在现实世界中通常也是如此,例如参见org.apache.commons
与http://commons.apache.org相关的)。的com
(商业)和org
(组织)的位置,然后居然顶级域的名称。
Package names are in general just to identify the manfacturer/vendor of the code you're facing.
包名称通常只是为了标识您所面对的代码的制造商/供应商。
回答by Paul Wagland
According to Sun, packages should be namespaced according to the inverse of your domain name, and then followed by whatever you see fit. Most companies or organisations have a .com
, or .org
domain name, and hence most packages start with com.
or org.
. To quote from the Sun Code Conventions:
根据Sun 的说法,包应该根据您的域名的倒数进行命名空间,然后是您认为合适的任何名称。大多数公司或组织都有一个.com
, 或.org
域名,因此大多数软件包都以com.
或开头org.
。引用Sun 代码约定:
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.
唯一包名的前缀总是用全小写的ASCII字母书写,并且应该是顶级域名之一,目前是com、edu、gov、mil、net、org或英文双字母代码之一识别 ISO 标准 3166, 1981 中规定的国家/地区。
包名称的后续组成部分根据组织自己的内部命名约定而有所不同。此类约定可能指定某些目录名称组件是部门、部门、项目、机器或登录名。
And the examples that they give, make it pretty clear that you are meant to use the companies DNS name:
他们提供的示例清楚地表明您打算使用公司的 DNS 名称:
com.sun.eng
com.apple.quicktime.v2
edu.cmu.cs.bovik.cheese
com.sun.eng
com.apple.quicktime.v2
edu.cmu.cs.bovik.cheese
You will also see edu.
and net.
packages out in the wildas well, although they are less common.
您还将在野外看到edu.
和net.
打包,尽管它们不太常见。
回答by Guillaume
Usually com
is used by companies when naming the packages, com
being followed by the company's name. For instance you have the com.sun
packages in the JVM.
通常com
由公司在命名包时使用,com
后跟公司名称。例如,您com.sun
在 JVM 中有包。
The org
package prefix is mostly used by non-profit organizations or for open source code, such as apache, w3c, etc.
该org
包的前缀主要用于通过非营利组织或开放源代码,如Apache,W3C等
回答by Dharmendrasinh Chudasama
See Oracle docfor package naming
有关包命名,请参阅Oracle 文档
See Naming Conventionsfor class/interface/annotations/etc standard naming
请参阅类/接口/注释/等标准命名的命名约定
package name and class standard syntax:
<your domain in reverse>.<project name>.<controller/dao/service/handlers etc>.<your class>
包名和类标准语法:
<your domain in reverse>.<project name>.<controller/dao/service/handlers etc>.<your class>
example1:(here domain:-
"stackoverflow.com", project:- "Test")
com.stackoverfllow.test.handler.TestHandler
示例1:(此处域:-“stackoverflow.com”,项目:-“Test”)
com.stackoverfllow.test.handler.TestHandler
example2: (here domain:- "www.google.co.in", project:- "My Proj")
in.co.google.myproj.controller.MainController
示例2:(此处域:-“www.google.co.in”,项目:-“我的项目”)
in.co.google.myproj.controller.MainController
but for reserved domains like java.*, javax.*, sun.*, etc. you should get permissionfrom oracle community
但是对于像 java.*、javax.*、sun.* 等保留域,您应该获得oracle 社区的许可