☰ See All Chapters |
Classpath vs Modulepath
This tutorial provides you the difference between classpath and modulepath. After you step into modulepath concept you may get confused between classpath and modulepath. We have provided the detailed comparison between classpath and modulepath, their usage, their strengths and weakness.
Classpath | Modulepath |
Will be applicable to all java versions. | Will be applicable to java version 9 and above. |
Classpath does not require module-info.java | module-info.java is necessary for modulepath. |
Adding libraries to classpath works only if project does not have module-info.java file. | Irrespective of whether module-info.java exists or not, we can add libraries to modulepath. |
If project has module-info.java then that project gets the module nature, libraries cannot be added into modulepath. | If project has module-info.java all libraries must be added to modulepath. |
We can add only non-modularized libraries to classpath. | Both modularized and non-modularized libraries can be added to classpath. |
Libraries on classpath in java 8 and below versions will be accessible without any further configurations. | Libraries on modulepath in java 9 and above versions will not be accessible until requires declaration in module-info.java file. To effectively access the libraries, those libraries must have provided necessary access using exports directive in module-info.java file. |
Encapsulation, Abstraction of the libraries can be broken by reflection API | Encapsulation, Abstraction of the libraries cannot be broken until opens, open, opens…to declaration in their module-info.java file. |
Encapsulation and Abstraction is week. | Encapsulation and Abstraction is strong. |
It is not possible to add part of the library to project by adding it in classpath | We can add only required part of the library to project by adding it in modulepath. |
Modularity is week. | Modularity is strong. |
All Chapters