包名称的Java代码约定 [英] Java code convention for package names

查看:93
本文介绍了包名称的Java代码约定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

我想知道是否有包含几个单词的包名称的一些代码张力。例如。 package name com.dreamcom.objectInterfaces 。在这种情况下,驼峰盒是否合适?

I wonder if there are some code convension for package name which contains several words. E.g. package name com.dreamcom.objectInterfaces. Is camel case suitable in this case?

推荐答案

Java包命名约定 @维基百科(添加了强调):

From Java package naming conventions @ Wikipedia (emphasis added):


包通常使用分层命名模式,层次结构中的
级别由句点(。)(发音为dot)分隔。
虽然在命名层次结构中较低的包通常被称为
作为在
层次结构中较高的相应包的子包,但是包之间几乎没有语义关系。
Java语言规范建立了包命名约定
,以避免两个已发布包具有相同
名称的可能性。命名约定描述如何创建唯一的包
名称,以便广泛分发的包将具有唯一的
命名空间。这使得包可以单独,轻松地自动安装和编目

Packages are usually defined using a hierarchical naming pattern, with levels in the hierarchy separated by periods (.) (pronounced "dot"). Although packages lower in the naming hierarchy are often referred to as "subpackages" of the corresponding packages higher in the hierarchy, there is almost no semantic relationship between packages. The Java Language Specification establishes package naming conventions to avoid the possibility of two published packages having the same name. The naming conventions describe how to create unique package names, so that packages that are widely distributed will have unique namespaces. This allows packages to be separately, easily and automatically installed and catalogued.

一般来说,包名称以顶级域名$ b $开头b组织,然后组织的域,然后任何
子域,以相反的顺序列出。然后,组织可以为其包选择
特定名称。 包裹名称应尽可能小写
个字符。

In general, a package name begins with the top level domain name of the organization and then the organization's domain and then any subdomains, listed in reverse order. The organization can then choose a specific name for its package. Package names should be all lowercase characters whenever possible.

例如,如果加拿大一家名为MySoft的组织创建一个
包处理分数,命名包 ca.mysoft.fractions
将分数包与另一个公司创建的另一个类似包
区分开。如果一个名为MySoft的德国公司也
创建一个分数包,但命名 de.mysoft.fractions ,那么
这两个包中的类

For example, if an organization in Canada called MySoft creates a package to deal with fractions, naming the package ca.mysoft.fractions distinguishes the fractions package from another similar package created by another company. If a German company named MySoft also creates a fractions package, but names it de.mysoft.fractions, then the classes in these two packages are defined in a unique and separate namespace.

当Internet域名无法直接连接时,完成用于消除包名和规则的约定,用于
命名包使用
作为包名称在Java语言
规范的第7.7节中描述。​​

Complete conventions for disambiguating package names and rules for naming packages when the Internet domain name cannot be directly used as a package name are described in section 7.7 of the Java Language Specification.






另请参阅:



查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆