Java包名称中单词分隔符的约定是什么?

What is the convention for word separator in Java package names?(Java包名称中单词分隔符的约定是什么?)
本文介绍了Java包名称中单词分隔符的约定是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

限时送ChatGPT账号..

包名中的单词应该怎么分开?以下哪项是正确的?

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

  1. com.stackoverflow.my_package(Snake Case 使用下划线)
  2. com.stackoverflow.my-package(Kebab Case 使用连字符)
  3. com.stackoverflow.myPackage(骆驼案例)
  4. com.stackoverflow.MyPackage (Pascal Case)
  1. com.stackoverflow.my_package (Snake Case using underscore)
  2. com.stackoverflow.my-package (Kebab Case using hyphens)
  3. com.stackoverflow.myPackage (Camel Case)
  4. com.stackoverflow.MyPackage (Pascal Case)

一般标准是什么?

推荐答案

以下是官方命名约定文档的规定:

Here's what the official naming conventions document prescribes:

唯一包名的前缀总是用全小写的ASCII字母写的,应该是顶级域名之一,目前是comedugovmilnetorg 或用于标识国家/地区的英文双字母代码之一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

参考文献

  • java.sun.com - 代码约定/命名
  • 请注意,上述文档未指定顶级域前缀之后的任何内容.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

    以下摘录也是相关的:

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

    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.1 包名称
    • 这篇关于Java包名称中单词分隔符的约定是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

      本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Sending a keyboard event from java to any application (on-screen-keyboard)(将键盘事件从 java 发送到任何应用程序(屏幕键盘))
How to make JComboBox selected item not changed when scrolling through its popuplist using keyboard(使用键盘滚动其弹出列表时如何使 JComboBox 所选项目不更改)
Capturing keystrokes without focus(在没有焦点的情况下捕获击键)
How can I position a layout right above the android on-screen keyboard?(如何将布局放置在 android 屏幕键盘的正上方?)
How to check for key being held down on startup in Java(如何检查在Java中启动时按住的键)
Android - Get keyboard key press(Android - 获取键盘按键)