Sun 的 Java 包命名约定:sun 与 com.sun

发布于 2024-08-03 11:34:29 字数 154 浏览 0 评论 0原文

在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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

知足的幸福 2024-08-10 11:34:29

不是问题的答案,但请注意,您不应直接在程序中使用“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).

肤浅与狂妄 2024-08-10 11:34:29

“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.

旧城空念 2024-08-10 11:34:29

如果您浏览一下Java 5 的兼容性文档,您会'您会注意到还有其他原因:

Apache - org.apache 类从未受 J2SE API 支持,但由 javax.xml 包使用,已在 5.0 中移至 **com.sun.**org.apache.package.internal,以便它们不会与开发人员下载的最新版本的类发生冲突。
任何依赖于 J2SE 版本中的 org.apache 类的应用程序必须执行以下操作之一才能在 5.0 中工作:
* 对应用程序进行编码,使其仅使用属于 JAXP 一部分的受支持接口。
* 从 Apache 下载 org.apache.xalan 类。

If you take a glance at the compatibility document for Java 5 you'll notice that there are other reasons too:

Apache - The org.apache classes, which have never been supported J2SE APIs but are used by the javax.xml package, have moved in 5.0 to **com.sun.**org.apache.package.internal so that they won't clash with more recent, developer-downloaded versions of the classes.
Any applications that depend on the org.apache classes being part of the J2SE release must do one of the following to work in 5.0:
* Code the application so it uses only the supported interfaces that are part of JAXP.
* Download the org.apache.xalan classes from Apache.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文