For a long time ago, I have thought that, in java, reversing the domain you own for package naming is silly and awkward.
Which do you use for package naming in your projects?
Package names are written in all lower case to avoid conflict with the names of classes or interfaces. Companies use their reversed Internet domain name to begin their package names—for example, com. example. mypackage for a package named mypackage created by a programmer at example.com .
Generally we android developer having practice to decide package name based on the domain name of a particular company. For example: Domain name: sun.com => Root package name something like : com. sun.
It's just a namespace definition to avoid collision of class names. The com.
The package names do not follow camel casing or underscores or hyphens package naming convention.
Once you understand why the convention exists, it shouldn't feel silly or awkward in the least.
This scheme does two important things:
All of your code is contained in packages that no one else will collide with. You own your domain name, so it's isolated. If we didn't have this convention, many companies would have a "utilities" package, containing classes like "StringUtil", "MessageUtil" etc. These would quickly collide if you tried to use anyone else's code.
The "reverse" nature of it makes class-directory layout very narrow at the top level. If you expand a jar, you'll see "com", "org", "net", etc dirs, then under each of those the organization/company name.
(added in 2021) This is even more important nowadays when this type of package naming is used for third-party libraries which are pulled in transitively during builds and could easily conflict if the names were not unique. If everyone adheres to the same convention, there will be no accidental collisions.
(added in 2021) The same naming convention can be used for application ids on an app store to ensure uniqueness as well.
We usually don't expand jars, but in early java development, this was important because people used expanded dir structures for applets.
However, this is nice now as source code dir structures have a very "top-down" feel. You go from the most general (com, org, net...) to less general (company name) to more specific (project/product/lib name).
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