Course contentsShow
← Java
Lesson 2463 of 2,87047. Java Platform Module System (JPMS)Free lesson

Basic Module Declaration Syntax

Write your first module declaration using the 'module' keyword and understand the required naming conventions.

Basic Module Declaration Syntax

What you'll learn: How to write your first module declaration using the module keyword and the naming conventions you must follow.


The module Keyword

Now that you know where module-info.java lives (at the root of your module), let's write the actual module declaration. Every module starts with the module keyword, followed by your module's name:

module com.example.myapp {
    // module directives go here
}

That's it—the simplest possible module declaration! Even an empty body like this creates a valid module.

Naming Conventions

Module names follow reverse domain name notation, just like package names:

  • Use lowercase letters
  • Separate parts with dots (.)
  • Start with your organization's domain reversed: com.company, org.project
  • Be descriptive: com.acme.accounting, org.utils.logging

Bad names: MyModule, module1, test
Good names: com.acme.sales, org.apache.commons.lang

Why Naming Matters

Module names become part of Java's module resolution system. They must be globally unique if you plan to share your code. Using reverse domain notation prevents name collisions—just like packages do, but at a higher architectural level.

Think of it like postal addresses: your module name is the city and street, while package names are the individual house numbers.


Key Takeaway: Declare a module using module followed by a reverse-domain-style name and curly braces—this single declaration transforms your code into a JPMS module, even before adding any directives inside the braces.