
Durgesh Tiwari
Author
The Java Module System (introduced in Java 9) provides a modern way to organize large applications in a clean, secure, and scalable structure. It helps control how different parts of an application interact through well-defined modules.
In JPMS (Java Platform Module System), some of the key concepts include:
Exporting packages
requires keyword for dependencies
Strong encapsulation
Difference between public and exported packages
Module dependency graph
These concepts play an important role in building well-structured and enterprise-ready Java applications.
In Java modules, exporting means sharing packages outside the module.
A module does not expose all its code automatically. Only the packages declared using exports are accessible to other modules.
Why it matters
Only exported packages are accessible outside the module
Internal packages remain hidden by default
Helps control what part of code is public

User Module
module user.module {
exports com.user.service;
}
package com.user.service;
public class UserService {
public void getUser() {
System.out.println("User data fetched");
}
}
module app.module {
requires user.module;
}Now the app.module can access UserService because the package com.user.service is exported.
In simple words: Exporting means allowing other modules to use a specific package.
The requires keyword in Java modules is used to define dependencies between modules.
If one module needs another module to work properly, it must declare that dependency using requires.
Why it matters
It defines a dependency between modules
It allows access to exported packages of another module
It ensures proper communication between modules
Without requires, a module cannot use another module’s code

Payment Module depends on User Module
module payment.module {
requires user.module;
}What it means
payment.module depends on user.module
It can now access only the exported packages of user.module
This keeps dependencies clear and controlled
In simple words:
requiresmeans one module depends on another module to function.
Strong encapsulation is one of the most important features of the Java Module System (JPMS).
It means that a module strictly hides its internal implementation details and only exposes what is explicitly allowed.
Why it matters
Only exported packages are accessible from outside
Internal classes and packages remain hidden by default
It improves security and modular design
It prevents accidental or unwanted use of internal code

Example
module user.module {
exports com.user.api;
}
package com.user.internal;
class DatabaseHelper {
void connect() {
System.out.println("Connecting to database...");
}
}👉 Here:
com.user.api is accessible outside the module
com.user.internal is hidden and cannot be accessed from other modules
In simple words: Strong encapsulation means hiding internal code and exposing only what is necessary.
Feature |
| Exported Package (Java Modules) |
|---|---|---|
Meaning | Makes a class or member accessible everywhere | Makes a package accessible outside the module |
Scope | Works at class/member level | Works at package/module level |
Access control | Controlled using | Controlled using |
Outside module access | Allowed if class is public | Allowed only if package is exported |
Dependency requirement | No module system needed | Requires Java Module System (JPMS) |
Key limitation | No module-level restriction | Even |

A module dependency graph shows how different modules in a Java application are connected and depend on each other.
It helps you understand the overall structure of the system and the flow of communication between modules.
Example Structure:
UI Module
↓
Service Module
↓
Core ModuleWhy it matters
Shows which module depends on which module
Helps understand application architecture clearly
Useful in large enterprise-level applications
Helps detect circular dependencies and design issues
Improves maintainability and code organization

In simple words: A dependency graph is a map that shows relationships between modules.
Java Modules (JPMS) provide a powerful way to build modern applications with better structure, security, and maintainability.
What you should remember
exports controls what is shared outside a module
requires defines dependencies between modules
Strong encapsulation protects internal implementation details
public alone is not enough in modular Java
Dependency graph helps understand overall system architecture
Understanding these concepts is important for Java developers, especially in interviews and real-world enterprise application development.