3
I often observe examples on the Java code web where your class organization is always contained in packages with the br.com.algumNomeDecote prefix. Why is "br.com used" ?
3
I often observe examples on the Java code web where your class organization is always contained in packages with the br.com.algumNomeDecote prefix. Why is "br.com used" ?
7
Sun, the company that created the Java language and platform, created a naming convention to prevent name collisions.
Suppose you have created a library to handle geolocation. Your program has a package called GPS
. The package has several classes and one of them is called Coordenada
.
Now suppose I have created a library to deputize GPS signal reading. I create a package called GPS
, that has several classes. One of my classes in the package is called Coordenada
.
If someone includes our two packages in the same application, what will happen? How will the application know which code GPS.Coordenada
refers to your package or my?
Sun’s suggestion was to use as a package name prefix the domain of the company that holds the code, to avoid name collisions... Because it is impossible for two companies to have the exact same domain. Domain reversal is just an aesthetic decision.
The documentation of this convention can be found on the Oracle website, the current owner of Java. Follow the link (in English):
Brazilian companies follow the pattern and put the stretch br
in front.
.NET has the same name-collision risk problem since its inception, but Microsoft people have solved it differently. You can give nicknames to namespaces to avoid collisions. So in . NET libraries do not usually use domain names, but only business names.
Finally, what to do when the code is not a company, but something personal, or at least something or someone who has no domain? Well, in that case, * in his * The paperwork doesn’t say anything. Just as a company is free not to follow the convention, in which case you are free to name your packages as you see fit.
Browser other questions tagged java
You are not signed in. Login or sign up in order to post.