Module Names and Naming Conventions
You'll learn: How to properly name modules in Java and understand the conventions that keep module names unique and maintainable.
Core Concept
Module names in Java follow specific rules and conventions that make them globally unique and prevent naming conflicts across different projects and organizations. Unlike package names (which organize classes within a module), module names identify entire modules in the module system.
Naming Rules
Technical requirements:
- Module names must be valid Java identifiers separated by dots
- Characters allowed: letters, digits, underscores, and dots
- Cannot start with a digit
- Cannot be Java keywords
Example valid names: myapp, my.app, app_utils
Reverse-DNS Convention
The strongly recommended convention mirrors package naming: use your organization's reverse domain name as a prefix.
com.mycompany.projectname
org.apache.commons.math
java.base
This ensures your module com.acme.inventory won't collide with someone else's com.example.inventory.
Module Names vs Package Names
Key difference: A module name identifies a container of packages, while package names organize classes within that container.
Think of it like a building address: the module name is the street address (uniquely identifies the building), while package names are the apartment numbers inside (organize contents within the building).
A module com.acme.sales might contain packages like com.acme.sales.model, com.acme.sales.ui, and even org.helpers.util — the module name and internal package names are independent.
Convention Best Practices
- Use lowercase letters
- Keep names concise but descriptive
- Match your primary package prefix when possible
- Avoid underscores unless necessary
Key Takeaway: Module names use reverse-DNS conventions to ensure global uniqueness and should clearly identify the module's purpose while remaining distinct from the package names they contain.