Java Magazine, Sept/Oct 2017
ORACLE COM JAVAMAGAZINE SEPTEMBER OCTOBER 2017 21 java 9 followed by a unique module name and a module body enclosed in braces as in module modulename The module declarations body can be empty or may contain various module directives including requires exports provides with uses and opens each of which we discuss As youll see later compiling the module declaration creates the module descriptor which is stored in a file named module info class in the modules root folder Here we briefly introduce each module directive After that well present actual module declarations The keywords exports module open opens provides requires uses with as well as to and transitive which we introduce later are restricted keywords Theyre keywords only in module declarations and may be used as identifiers anywhere else in your code requires A requires module directive specifies that this module depends on another module this relationship is called a module dependency Each module must explicitly state its dependencies When module A requires module B module A is said to read module B and module B is read by module A To specify a dependency on another module use requires as in requires modulename There is also a requires static directive to indicate that a module is required at compile time but is optional at runtime This is known as an optional dependency and wont be discussed in this introduction requires transitive implied readability To specify a dependency on another module and to ensure that other modules reading your module also read that dependency known as implied readability use requires transitive as in requires transitive modulename A key motivation of the module system is strong encapsulation
You must have JavaScript enabled to view digital editions.