0

I have been learning java and using eclipse. So my question is what is the purpose of a package, and why can't there just be projects and classes?

greg-449
  • 109,219
  • 232
  • 102
  • 145
Aubrey Champagne
  • 123
  • 1
  • 10

2 Answers2

2

Packages are a way to group/organize/separate your classes depending of the a common functionality. So, say you have a set of classes that deal with storing multiple objects (such as the collections package) or you could have a package of classes that deal with File manipulation: such as the java.io.* package.

It's just a way of organizing.

1

In addition to what @Manuel Manrique has said, one thing that I could think of is, packages help resolve class/interface naming conflicts

For ex: I use some-apache.jar and some-google-api.jar, assuming both have same class named Test, packages help resolve the conflict.

In general package naming convention is something like org.apache.Test or com.google.Test

JavaHopper
  • 5,567
  • 1
  • 19
  • 27