Java Packages – Steps to Grouping Related Classes

javamvcpackagesseparation-of-concerns

What are the steps needed to be taken to group related classes into packages in Java?

In my case, I have about a number of .java files that I'd like to group into 3 packages according to the MVC pattern. One package for Model classes, one package for View classes and one package for Controller classes. I've identified which belong in what package, but not sure of the next step.

I want to know how to seperate them into packages, do I make 3 folders and place the .java files in the folder that represents the package they belong in?

Best Answer

Java requires that the name of a class file reflects the class name but there's no such requirement for packages. Packages are just names that do not form hierarchies although it might appear so on the surface. It is still a good practice to separate different packages to different directories that reflect the package name. All development environment do this for you automatically.

Related Topic