Module Name
A legal module name can consist of one or more (by convention, lowercase) legal identifiers separated by a . (dot), as in the case of a package name. Module names and package names are in different namespaces. From the context in which such a name occurs, the compiler can deduce which namespace it belongs to. For example, the name com.abc.seller is a module name if used with the context-dependent keyword module in a module declaration, but it is a package name when used in an exports directive.
Analogous to package names, reverse DNS (Domain Name System) notation can be used to form unique module names. The convention is to use the name of the principal exported package (if there is one) in a module as its module name. When naming a module, it is recommended that the name should reflect the structure of the module—that is, its package hierarchy. For example, the module declarations in Figure 19.3(c) and (d) can be written as follows, respectively:
module com.abc.client { module com.abc.seller {
requires com.abc.seller; exports com.abc.seller;
} exports com.abc.factory;
}
If care is not exercised in naming modules and packages, distinguishing between module names and package names can become a problem when reading the code, as we can see in the module declarations above, where the name com.abc.seller is used both as a module name and as a package name. For brevity, we will not adhere to the naming scheme described above and will continue to use simple names for modules, as in Figure 19.3.
A package is implemented in the file system by a directory hierarchy that mirrors its name. For example, a package named com.abc.seller is implemented by its source code files being located under the directory ./com/abc/seller. As we shall see in §19.5, p. 1181, a module named com.abc.seller is implemented by a directory whose name is com.abc.seller under which all its packages are located.
Some examples of legal module names (as well as legal package names):
my.big.fat.module, com.passion.controller, org.geek.gui, view
Some examples of illegal module names (as well as illegal package names):
net.soda.7up, org:factory, com-factory-gizmo
Leave a Reply