Sun 的 Java 包命名约定:sun 与 com.sun
在JRE中,Sun的内部包以2个顶级域(sun和com)为前缀。例如,对
com.sun.security.jgss
sun.security.jgss
我来说,他们选择哪个前缀似乎很随机。我很好奇Sun 为此使用了什么规则。
In JRE, Sun's internal packages are prefixed with 2 top-level domains (sun and com). For example,
com.sun.security.jgss
sun.security.jgss
It seems pretty random to me which prefix they choose. I am curious what rules Sun uses for this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不是问题的答案,但请注意,您不应直接在程序中使用“sun”或“com.sun”包。
请参阅为什么开发人员不应编写调用“sun”包的程序
这些包不是标准 Java 库的公共 API 的一部分,使用它们可能会使您的程序与 Java 的未来版本或除 Sun 实现之外的 Java 实现不兼容(还有其他供应商的多种实现,包括苹果、IBM 和惠普)。
Not an answer to the question, but please be aware that you should not use 'sun' or 'com.sun' packages in your programs directly.
See Why Developers Should Not Write Programs That Call 'sun' Packages
Those packages are not part of the public API of the standard Java library, and using them might make your program incompatible with future versions of Java or implementations of Java other than the Sun implementation (and there are several implementations by other vendors, including Apple, IBM and HP).
“com.sun”约定是更可取的格式,因为它遵循为命名 Java 包而建立的“命名约定”。
http://java.sun.com/docs/codeconv/html/CodeConventions .doc8.html
您应该使用您唯一的公司或个人网站 URL 作为包中的前几个单词,以保证命名空间的唯一性。以“太阳”开头的那些可能并不是为了暴露在外面的世界。
The "com.sun" convention is the more preferable format because it follows the "naming conventions" that have been established for naming Java packages.
http://java.sun.com/docs/codeconv/html/CodeConventions.doc8.html
You're supposed to use your unique company or personal website URL as the first few words in the package to guarantee uniqueness in the namespace. The ones that start with "sun" were probably not intended to be exposed to the outside world.
如果您浏览一下Java 5 的兼容性文档,您会'您会注意到还有其他原因:
If you take a glance at the compatibility document for Java 5 you'll notice that there are other reasons too: