What's the difference between "package" and "module"?

Viewed 60000

I use Java where we only have packages. I know there are other programming languages that also include modules.

What's the difference?

5 Answers

Java Platform Module System or JPMS was introduced when was released. Starting from that time Java has both packages and modules. So what is the difference between them?

What is a Package?

A package is a namespace that organizes a set of related classes and interfaces.

What is a Module?

A module is a collection of related Java packages and associated resources with a descriptor file, which contains information about which packages/resources are exposed by this module, which packages are used by current module and some other information.

We can thing of a Java Module as a higher level of aggregation above packages. A Module allows you to organize a few packages into one single logical unit and to distribute them as one whole system. As well JPMS provides a way to control which packages are visible to users.

Related