File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Use of packages Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Use of packages" Watch "Use of packages" New topic

Use of packages

Sim Kim
Ranch Hand

Joined: Aug 06, 2004
Posts: 268
Why do we use packages ? What are the limitations on definations of the class in package ?
Darren Horsman

Joined: Dec 04, 2005
Posts: 9
I'd almost put money on this one being homework related then again, if your test scores in your sig are legitimat, you wouldn't be getting this as a homework question, so here goes.

Why do we use packages?

It allows classes to be organised.

It means that two people can write a class with the same name BUT with different package names without there being any doubt which is which.

Personally, I dislike the old days when you could have litterally a few hundred source files in one folder, grouping things make it easier to understand.
[ December 05, 2005: Message edited by: Darren Horsman ]
Sim Kim
Ranch Hand

Joined: Aug 06, 2004
Posts: 268
Darren this is not homework .

And I know the answer of this too . But I was just asking to know more from the people .

And for your info I have 1 1/2 yrs work exp. in J2EE .
Can u see the lines below : they mean something .
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
At one level packages match folders on disk and serve just as a convenient way to organize files.

You can also manage dependencies and change at the package level. It's nice to have core packages that never changes while others might change with every release. I like Robert Martin's writings on this. Even though he says "package" as a generic "unit of deployment" rather than a literal Java package it's useful thinking. This blog is a good starting point. I wrote this for my team and contrast packaging for reuse and packaging for robustness.

You can manage visibility by package, too, such as package visibility classes. Sometimes it's nice to have public interfaces but keep implementation classes hidden from other packages.
[ December 05, 2005: Message edited by: Stan James ]

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
I agree. Here's the link:
subject: Use of packages
It's not a secret anymore!