java项目中包的命名规范

一、包命名规范

为什么把包命名单独提出来呢?因为之前的命名一直是有问题的,被别人质疑了,所以这里单独提出来记录一下。
问题是关于包名里的下划线(_)是使用,如果包名的一个层级是多个单词,该不该用下划线分割呢?
答案是不能,多个单词也要使用小写命名,不能用下划线分割。
下面是摘自官方文档的一句话:

Package names are written in all lower case to avoid conflict with the names of classes or interfaces.

Companies use their reversed Internet domain name to begin their package names—for example, com.example.mypackage for a package named mypackage created by a programmer at example.com.

Name collisions that occur within a single company need to be handled by convention within that company, perhaps by including the region or the project name after the company name (for example, com.example.region.mypackage).

Packages in the Java language itself begin with java. or javax.

In some cases, the internet domain name may not be a valid package name. This can occur if the domain name contains a hyphen or other special character, if the package name begins with a digit or other character that is illegal to use as the beginning of a Java name, or if the package name contains a reserved Java keyword, such as “int”. In this event, the suggested convention is to add an underscore.

可以看出来,包名要始终以小写单词命名,即使需要多个单词作为一个层级,也要小写在一起,比如springframework,没有下划线,当然除了以下情况例外需要以下划线标示:
1. 某个层次名称里有特殊字符,比如name-chengdu作为包名,要命名为: name_chengdu。
2. 层次名称里有Java的关键字,比如int.example,我们要命名为int_.example。
3. 层次名称以数字开头,比如com.123name.utils,要命名为com._123name.utils。

这里小计一下,避免以后忘记。

注:https://blog.csdn.net/feigeswjtu/article/details/76240568

二、方法命名规范

动词+名词

https://zhuanlan.zhihu.com/p/97939831

1. boolean 命名 isEnter

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值