What's the difference between “package” and “module”?

前端 未结 5 852
你的背包
你的背包 2020-12-04 23:42

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

What\'s the difference?

5条回答
  •  暖寄归人
    2020-12-05 00:40

    Java Platform Module System or JPMS was introduced when java-9 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.

提交回复
热议问题