In most source codes, the root package/folder is named "com". Why is that so? It it just convention or does it stand for something?
It's the domain name spelt out in reverse. For example, one of my domains is hedgee.com. So, I use com. hedgee as the base name of all my packages.
So com. prefix in package names means the same as .com suffix in domain names: "commercial".
Yes perfectly acceptable to have plurals, look at Collections for example, it is a class which has many static methods which help when dealing with different flavours of collection.
A package in Java is used to group related classes. Think of it as a folder in a file directory. We use packages to avoid name conflicts, and to write a better maintainable code. Packages are divided into two categories: Built-in Packages (packages from the Java API)
The convention is that a programmer in a given organization will start package names with their organization's domain name, as a unique identifier -- in reverse order. This prevents namespace clashes between code from different organizations (within the organization you're on your own).
So if I work for a company called Supercompany, and their domain is supercompany.com, all of my package names will start with com.supercompany
. And since a lot of code is written for companies, a lot of packages start with com. However, there are plenty of packages that start with "net" or "org" or other such top-level domains. Myself, I work for a university, so my package names generally start with "edu".
The brief answer, then, is that most package names start with "com" because most domain names end with "com".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With