Java Platform Module System: Difference between revisions

Content deleted Content added
Adding local short description: "Distribution format for Java code and resources", overriding Wikidata description "distribution format" (Shortdesc helper)
A248 (talk | contribs)
Add properties of modules section and elaborate on the features of module-info files
Line 27:
 
== Architecture ==
The Java Module System implemented forin Java 9 includeincludes the following [[JDK Enhancement Proposal|JEP]]s and [[Java Community Process|JSR (Java Specification Request)]]:<ref name="jigsaw"/>
* JEP 200: The Modular JDK: Define a modular structure for the JDK
* JEP 201: Modular Source Code: Reorganize the JDK source code into modules, enhance the build system to compile modules, and enforce module boundaries at build time
Line 66:
| accessdate=2017-07-31}}</ref>
 
== Properties of Modules ==
Modules are a new way of grouping code and data. Contrary to [[JAR (file format)|Jar files]], modules explicitly declare which modules they depend on, and what packages they export.<ref>{{cite web
 
Modules are a new way of grouping code and data. Contrary to [[JAR (file format)|Jar files]], modules explicitly declare which modules they depend on, and what packages they export.<ref>{{cite web
| url=http://openjdk.java.net/projects/jigsaw/spec/sotms/
| title=The State of the Module System
Line 72 ⟶ 74:
| author=Mark Reinhold
| date=2016-03-08
| accessdate=2017-02-18}}</ref> Explicit dependency declarations improve the integrity of the code, by making it easier to reason about large applications and the dependencies between software components.
| accessdate=2017-02-18}}</ref>
 
For example, the following module declaration declares that the module ''com.foo.bar'' depends on another ''com.foo.baz'' module, and exports the following packages: ''com.foo.bar.alpha'' and ''com.foo.bar.beta'':
Line 82 ⟶ 84:
}
</pre>
The public members of ''com.foo.bar.alpha'' and ''com.foo.bar.beta'' packages will be accessible by dependent modules. Private members are inaccessible even through a means such as [[reflective programming|reflection]], though whether 'illegal access' is ''de facto'' permitted depends on a command line setting.<ref name="JEP 396: Strongly Encapsulate JDK Internals by Default">{{cite web | url=https://openjdk.java.net/jeps/396 | title=JEP 396: Strongly Encapsulate JDK Internals by Default | access-date=2021-02-06}}</ref>
 
Contrary to the Jar file format, the module will describe these dependencies in a module declaration which will be placed in a file named ''module-info.java'' at the root of the module’s source-file hierarchy. The JDK will be able to checkverify themdependencies and interactions between modules both at compile-time and runtime. The JDK itself willhas bebeen modularized forin [[Java version history#Java SE 9|Java 9]].<ref>{{cite web
| url=http://cr.openjdk.java.net/~mr/jigsaw/ea/module-summary.html
| title=JDK Module Summary