Archived

This topic is now archived and is closed to further replies.

Java Packages

This topic is 5127 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

According to the Sun Java code conventions your package names must begin with a top level domain. i.e. com.something.blah. "The first component of a unique package name is always written in all-lowercase ASCII letters and should be one of the top-level domain names, currently com, edu, gov, mil, net, org, or one of the English two-letter codes identifying countries as specified in ISO Standard 3166, 1981." - Quoted from http://java.sun.com/docs/codeconv/html/CodeConventions.doc2.htm. Can anyone explain to me why this is, it seems very strange. Also, does anyone know when Java 1.5 is scheduled for release?

Share this post


Link to post
Share on other sites
I can think of two reasons:

1) If you start with a domain that you have registered, then you know that nobody else will use the same name; i e uniqueness is guaranteed.

2) If you want to know where to go for support, updates, etc, then inspecting the name of the package may give you a clue.

I doubt they actually enforce this recommendation, though.

Share this post


Link to post
Share on other sites
Yes, the primary reason is for uniqueness. You can call your packages anything you want, and it''s not unusual for a top level package name to be that of the application it is coded for. However, if you are writing any kind of code that is intended to be used by other developers in any way, shape, or form, it is a very good idea to follow the Sun conventions. Many Java bashers are quick to blast the accepted conventions as being ridiculous. However, they go a long way to making code readable, easy to understand, easy to maintain, and (in the case of package names) result in fewer namespace collisions.

Share this post


Link to post
Share on other sites