my dog learned polymorphism*
The moose likes Beginning Java and the fly likes Why are URLs in package names written in reverse? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Why are URLs in package names written in reverse?" Watch "Why are URLs in package names written in reverse?" New topic
Author

Why are URLs in package names written in reverse?

joseph corner
Ranch Hand

Joined: Feb 20, 2004
Posts: 50
The title says it all
Naren Chivukula
Ranch Hand

Joined: Feb 03, 2004
Posts: 576

It's just a convention. Its not mandatory. But, I'm glad to know more regarding this


Cheers,
Naren
(OCEEJBD6, SCWCD5, SCDJWS, SCJP1.4 and Oracle SQL 1Z0-051)
Mark Vedder
Ranch Hand

Joined: Dec 17, 2003
Posts: 624

I don�t know if this is the official answer, but it just makes sense from a directory standpoint, and as a �drilldown� methodology of taking a larger set, and refining it to a smaller subset. Using this naming convention, when a company or group has multiple packages, you cut down on the number of directories needed:
For example, given the packages:
com.foo.someApp
com.foo.someApp.helperClasses
com.foo.someApp.guiClasses
com.foo.anotherApp
you have


Here you have 6 total directories; if you went the other way:

This results in 14 directories and is a lot more confusing to find things. It is just a nature sorting order to go from the item with the largest quantity to the smallest. Personally, I�ve always felt that it is the URL�s that have it backwards
joseph corner
Ranch Hand

Joined: Feb 20, 2004
Posts: 50
Hi,
Well, it's a fairly trivial question, and I know it's just a convention, but I'm interested in case there's more than meets the eye.
I don't see why with your example you couldn't have foo as the top directory, followed by com, followed by the various subdirectories.
Ie.,
foo.com.someApp
foo.com.someApp.helperClasses
foo.com.someApp.guiClasses
foo.com.anotherApp
It seems more readable to me. Have I missed something?
J
[ February 25, 2004: Message edited by: joseph corner ]
Ben Wood
Ranch Hand

Joined: Aug 14, 2001
Posts: 342
I always thought the most basic reason for assigning package names as reverse URL domains is that they become unique to the organisation or individual who uses that URL. That way you only have to worry about other people in your organisation writing packages with the same name because no-one else outside your colleagues should be using your URL to name their package.
Reversing it completely does seem the most systematic way of doing it to me as it creates a more pure hierarchy.


SCJP 1.4, www.gsi3d.org.uk
Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923

joseph
You would have the root of the name in the middle:

This shall be the graph for your naming:
ibm.com.foo.c1;
sun.com.foo.c1;
or standard:
com.ibm.foo.c1;
com.sun.foo.c1;

There are domains like
foo.edu.uk
which lead to:
uk.edu.foo.c1;
but where would you search the net, if it was:
foo.edu.uk.c1;
You might search at the above mentioned place, for c1, or at
foo.edu
for uk.c1;


http://home.arcor.de/hirnstrom/bewerbung
sever oon
Ranch Hand

Joined: Feb 08, 2004
Posts: 268
If you think about it, URLs do, by convention, have the root web address backwards. Look at the URL above...saloon.javaranch.com/cgi-bin/ubb/...
So if you think about it, the pattern the URL follows is <site>/<directory>/<more specific directory>/...it's just that, by convention, the site components are listed in reverse.
sev
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Why are URLs in package names written in reverse?