16

I don't understand why Java uses the reverse of a (probably hypothetical) domain name as the name of a package, while mostly there is no connection between the domain name that some people uses and the products that they have. A lot of developers don't even have any domain.

What are the reasons of this naming convention, if any?

Louis Rhys
  • 6,182

3 Answers3

16

Global uniqueness. If everyone, or at least serious developers who distribute their code beyond in-house projects, adheres to that convention, it will never happen that you get name clashes when you add another third-party library to your project. Bear in mind that Java was initially propagated as a solution for code deployment anywhere, anytime (via applets and remote classloading over the internet).

Kilian Foth
  • 110,899
12

As Wikipedia says on the subject,

"The Java Language Specification establishes package naming conventions to avoid the possibility of two published packages having the same name."

LaLeX
  • 221
  • 1
  • 2
2

I found two Oracle-published documents that discuss the naming of packages. There is the Naming a Package page in the Java Tutorials and the Packages section of the Java Language Specification.

The primary purpose of this convention is to try to minimize conflicts between packages published by different organizations.

Thomas Owens
  • 85,641
  • 18
  • 207
  • 307