没有域关联的 java 包名称的约定是什么?

What#39;s the convention for java package names without a domain association?(没有域关联的 java 包名称的约定是什么?)
本文介绍了没有域关联的 java 包名称的约定是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我在 SO 上找不到回答我的确切问题的 Q/A,所以我想我会发布它,看看有什么结果.

就 Java 包的命名约定而言,我知道它应该是反向域名:com.whatever.stuff,并且我得到了关于不混合大小写、连字符、关键字等.

我还阅读了 Java 语言规范的第 7.7 节(唯一包名称).据我所知,Java 的规则是使用反向域来确保唯一性……如果你没有,那就去买一个:

您首先拥有(或属于拥有)互联网域名的组织,例如 sun.com,从而形成一个唯一的包名称. - 第 7.7 节

因此,如果我对花钱购买域名不感兴趣,我不属于我可以捎带名字的公司,我是否遗漏了命名约定的任何部分应该遵循吗?我想我可以随心所欲地为其命名,但我只是想知道我是否遗漏了什么.

注意:我想发布我的包供其他开发人员使用,所以我不想只做一些在我的系统上工作的东西,而是尽可能地做一些更标准的东西.p>

我添加了android标签是因为我要写的java包将用于Android应用程序,不知道android开发者是否有不同意见.

解决方案

如果你要分发很多东西,我真的建议你申请一个域名.然而,另一种选择是使用您的电子邮件:例如bob@gmail.com 将变为 com.gmail.bob.这比使用域名少见,但仍然由一些人完成,并且仍然确保唯一性.

I can't find a Q/A on SO that answers my exact question, so I figure I'd post it and see what comes back.

As far as the naming convention goes for Java packages, I understand that it's supposed to be the reverse domain name: com.whatever.stuff and I get the rules about no mixed case, hyphens, keywords, etc.

I've also read section 7.7 (Unique-Package-Names) of the Java Language Specification. As far as I can tell, the rules from Java are to use the reverse domain to insure uniqueness... and if you don't have one, go get one:

You form a unique package name by first having (or belonging to an organization that has) an Internet domainname, such as sun.com. - Section 7.7

So if I'm not interested in shelling out the money for a domain name, I don't belong to a company whose name I can piggyback off of, is there any part of the naming convention that I'm missing that should be followed? I'm thinking I can just go name it whatever unique name I feel like at this point, but I was just wondering if I was missing anything.

Note: I would like to release my package for other developers to use, so I didn’t want to just do something that worked on my system, but something more standard if possible.

I added the android tag because the java packages I'm going to be writing are going to be used in an Android application, wasn't sure if there were different opinions from android developers.

解决方案

If you are going to be distributing a lot of stuff, I would really suggest getting a domain name. Another alternative however would be to use your e-mail: e.g. bob@gmail.com would become com.gmail.bob. This is less common than using domain names but is still done by some and still ensures uniqueness.

这篇关于没有域关联的 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 - 获取键盘按键)