Advertisement
Beginner Java, Java Platform Module System (JPMS)

How do you name a Java module, and what naming convention is recommended to avoid conflicts with other modules?

Short answer

A module name is declared directly after the module keyword in module-info.java, and the recommended convention (mirroring Java package naming conventions) is to use a reverse-domain-style name matching your organization's own domain (like com.example.myapp), helping avoid…

Save Java mock interview
Advertisement
AModel answer
A module name is declared directly after the module keyword in module-info.java, and the recommended convention (mirroring Java package naming conventions) is to use a reverse-domain-style name matching your organization's own domain (like com.example.myapp), helping avoid naming collisions with modules from other organizations or open-source libraries in the same application's module graph, since module names must be globally unique within a given application's module path.
module com.example.myapp {
    // module body: requires, exports, etc.
}

// Poor practice: a generic, collision-prone name
// module utils { }  -- could easily conflict with another library also naming its module "utils"

// Good practice: reverse-domain style, following Java package naming conventions
module com.mycompany.utils { }
Real-world example
A company standardizes on reverse-domain module naming (com.mycompany.*) across all their internal modules, avoiding a naming collision that occurred early in their JPMS adoption when two unrelated internal teams had both independently named their module simply "common", which caused a conflict when both were eventually included in the same application's module path.
Likely follow-ups
  • What happens if two different JARs on the module path declare modules with the identical name?
  • Is there any central registry or enforcement mechanism preventing module name collisions across the broader Java ecosystem?
Related topics