Java包名称中的单词分隔符的约定是什么? [英] What is the convention for word separator in Java package names?

查看:592
本文介绍了Java包名称中的单词分隔符的约定是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在包名中单独添加单词?以下哪项是正确的?

How should one separate words in package names? Which of the following are correct?


  1. com.stackoverflow.my_package (下划线)

  2. com.stackoverflow.my-package (连字符)

  3. com.stackoverflow.MyPackage (CamelCase)

  1. com.stackoverflow.my_package (underscore)
  2. com.stackoverflow.my-package (hyphens)
  3. com.stackoverflow.MyPackage (CamelCase)

什么是通用标准?

推荐答案

以下是官方命名惯例文件规定的内容:

Here's what the official naming conventions document prescribes:




唯一包名的前缀始终以全小写ASCII字母书写,应该是顶级域名之一,目前 com edu gov mil net org ,或标识国家/地区指定的英文双字母代码之一ISO标准3166,1981。

Packages

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.


  • com.sun.eng

  • com.apple.quicktime .v2

  • edu.cmu.cs.bovik.cheese

  • com.sun.eng
  • com.apple.quicktime.v2
  • edu.cmu.cs.bovik.cheese



参考文献




  • java.sun.com - 代码约定/命名

  • References

    • java.sun.com - Code Conventions/Naming
    • 请注意,特别是上述文档未指定顶级域前缀后面的任何内容。 JLS也同意这一点,给出以下例子:

      Note that in particular, anything following the top-level domain prefix isn't specified by the above document. The JLS also agrees with this by giving the following examples:



      • com.sun .sunsoft.DOE

      • gov.whitehouse.socks.mousefinder

      • com.JavaSoft.jag.Oak

      • org.npr.pledge.driver

      • uk.ac.city.rugby.game

      • com.sun.sunsoft.DOE
      • gov.whitehouse.socks.mousefinder
      • com.JavaSoft.jag.Oak
      • org.npr.pledge.driver
      • uk.ac.city.rugby.game

      以下摘录也是相关的:


      在某些情况下,互联网域名可能不是有效的包名。以下是处理这些情况的一些建议约定:

      In some cases, the internet domain name may not be a valid package name. Here are some suggested conventions for dealing with these situations:


      • 如果域名包含连字符或任何其他不允许的特殊字符标识符,将其转换为下划线。

      • 如果任何生成的包名称组件是关键字,则将下划线附加到它们。

      • 如果有的话生成的包名称组件以数字开头,或任何其他不允许作为标识符的初始字符的字符,在组件前面加上下划线。



      参考文献




      • JLS 6.8.1包名

      • JLS 7.7独特包装名称

      • References

        • JLS 6.8.1 Package Names
        • JLS 7.7 Unique Package Names
        • 这篇关于Java包名称中的单词分隔符的约定是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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