Reputation: 53
I don't really understand what the point of having a package is. Every Class is kept in a different file, so what's the point of using different packages in a single project?
Upvotes: 4
Views: 13135
Reputation: 7863
An Eclipse project has nothing to do with Java. It is a feature of Eclipse to organize and configure your different projects.
A Java package is a language feature of Java. You can use them to structure your project and control visibility between different classes. This becomes necessary even in relatively small projects, which already might have a few hundred classes. I suggest you look for a basic tutorial on what a Java package is and what it can do. To give you a headstart, here is what the official documentation has to say about the purpose of bundling related classes in a package:
You should bundle these classes and the interface in a package for several reasons, including the following:
- You and other programmers can easily determine that these types are related.
- You and other programmers know where to find types that can provide graphics-related functions.
- The names of your types won't conflict with the type names in other packages because the package creates a new namespace.
- You can allow types within the package to have unrestricted access to one another yet still restrict access for types outside the package.
Upvotes: 8
Reputation: 751
Packages are useful for many things. For example, you could store a set of files that do a given task TASK
in a package named task
.
Packages are a way for developers to find easily and quickly a file, knowing what the role of the file is. Whenever your project starts growing, packages are essential.
See this lesson for basic understanding of packages utility.
Upvotes: 1