Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Use of packages

 
Sim Kim
Ranch Hand
Posts: 268
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do we use packages ? What are the limitations on definations of the class in package ?
 
Darren Horsman
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 268
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic