java中包名是如何确定的,为什么要用“com”?作为根?

发布于 2024-09-06 10:37:52 字数 68 浏览 2 评论 0原文

我尝试用谷歌搜索这个但找不到任何东西。我只是好奇为什么我们使用文件夹名称“com”作为根目录?它代表什么?电脑?哈哈。谢谢

I tried googling this but can't find anything. I'm just curious as to why we use the folder name 'com' as the root directory? what does it stand for? computer? haha. thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(4

任谁 2024-09-13 10:37:52

为了避免冲突,命名时的标准做法是按照您拥有的的顺序命名它们。因此,如果您公司的网站是 betterwidgets.com,您几乎肯定会将文件放入 com.betterwidgets.* 包中。

Java(可能还有其他语言)规定目录结构需要符合包层次结构(即使它是非层次结构的,请看图),因此在这种情况下,所有源文件都将位于“com”目录下,然后是其中的“betterwidgets”子目录。

Standard practice when naming packages, in order to avoid collisions, is to name them after a domain that you own, in reverse order. So if your company's website was betterwidgets.com, you would almost certainly put your files in a com.betterwidgets.* package.

Java (and probably other languages) impose that the directory structure needs to conform to the package hierarchy (even though it's non-hierarchical, go figure) and so in this case, all the source files would be under "com" directory, then a "betterwidgets" subdirectory within that.

半枫 2024-09-13 10:37:52

在java中,约定是用包提供者的域名的倒数作为前缀来命名包。例如,由 microsoft(拥有“microsoft.com”)开发的包“foobar”可能被命名为“com.microsoft.foobar”。如果您的公司拥有域“fantastic.net”,您可以将该包命名为“net.fantastic.foobar”。

这些包在磁盘上按照其名称进行组织,因此“net.fantastic.foobar”将位于“com/fantastic/foobar”文件夹中。

这只是一种简单、低开销的方法,可以防止两家公司开发同名的软件包。

FWIW,域名上下文中的“com”代表“商业”,如“与商业相关”。如果您好奇的话,维基百科有更多信息

In java, the convention is to name packages prefixed by the reverse of the domain name of the package provider. For example, the package "foobar" developed by microsoft (which owns "microsoft.com") might be named "com.microsoft.foobar". If your company owns the domain "fantastic.net", you would name the package "net.fantastic.foobar".

The packages are organized on disk related to their name, so "net.fantastic.foobar" would be in the folder "com/fantastic/foobar".

This is just a simple, low-overhead way to prevent two companies from developing packages that have the same name.

FWIW, the "com" in a domain name context stands for "commercial", as in "related to commerce". Wikipedia has more information if you are curious.

倾听心声的旋律 2024-09-13 10:37:52

它是一个域名,其组成部分按相反顺序排列。

It's a domain name with the components in reverse order.

暮年慕年 2024-09-13 10:37:52

通常“.com”代表商业解决方案。在本例中,我认为该包是商业 API 的一部分。

Generally ".com" stands for a commercial solution. In this case I suppose that the package is part of a commercial API.

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