Module Naming Conventions and Best Practices
What You'll Learn
You'll learn how to name your Java modules using reverse-DNS patterns and understand the relationship between module names and package names for maximum clarity.
Why Module Naming Matters
When you declare a module in module-info.java, choosing the right name isn't arbitrary—it affects clarity, collision avoidance, and maintainability across your entire codebase and ecosystem.
The Reverse-DNS Convention
Module names should follow the reverse-DNS naming pattern, just like package names:
module com.mycompany.myapp.core {
// module directives
}
This pattern ensures global uniqueness. If your company owns mycompany.com, starting your modules with com.mycompany virtually guarantees no conflicts with modules from other organizations.
Relationship to Package Names
Best practice: Your module name should typically be a prefix of the packages it contains.
For example, if your module is named com.mycompany.myapp.core, it should contain packages like:
com.mycompany.myapp.corecom.mycompany.myapp.core.utilcom.mycompany.myapp.core.model
Avoid having a module com.mycompany.app containing packages like org.other.stuff—this creates confusion about ownership and organization.
Naming Style Guidelines
- Use all lowercase letters
- Separate components with dots (
.) - Avoid hyphens or underscores
- Keep names descriptive but concise:
com.mycompany.inventorybeatscom.mycompany.the.inventory.management.system - Match the primary purpose: if your module handles database access, consider
com.mycompany.myapp.database
Think of It Like Postal Addresses
Reverse-DNS naming is like a postal system: the broadest category comes first (com), then your organization (mycompany), then increasingly specific divisions. This hierarchy prevents naming collisions just as street addresses prevent mail mix-ups.
Key Takeaway: Use reverse-DNS notation for module names, ensure they logically prefix the packages they contain, and keep them lowercase and descriptive for clarity and collision avoidance.