Java Magazine, September/October 2017
ORACLE COM JAVAMAGAZINE SEPTEMBER OCTOBER 2017 26 java 9 At compile time if multiple modules have the same name a compilation error occurs At runtime if multiple modules have the same name an exception occurs This example uses the same name for the module and its contained package because there is only one package in the module This is not required but is a common convention In a modular app Java maintains the module names separately from package names and any type names in those packages so duplicate module and package names are allowed Modules normally group related packages As such the packages will often have commonality among portions of their names For example if a module contains the packages com deitel sample firstpackage com deitel sample secondpackage com deitel sample thirdpackage you would typically name the module with the common portion of the package names com deitel sample If theres no common portion then youd choose a name representing the modules purpose For example the java base module contains core packages that are considered fundamental to Java apps such as java lang java io java time and java util and the java sql module contains the packages required for interacting with databases via JDBC such as java sql and javax sql These are just two of the many standard modules The online documentation for each standard module such as java base provides the modules complete list of exported packages Class Welcome The following code presents a Welcome app that simply displays a string at the command line When defining types that will be placed in modules every type must be placed into a package as in the third line below Welcome java Welcome class that will be placed in a module package com deitel welcome all classes in modules must be packaged public class Welcome public static void main String args
You must have JavaScript enabled to view digital editions.