Content deleted Content added
No edit summary Tags: Mobile edit Mobile web edit |
|||
(14 intermediate revisions by 3 users not shown) | |||
Line 67:
== Properties of modules ==
Modules are
| url=http://openjdk.java.net/projects/jigsaw/spec/sotms/
| title=The State of the Module System
Line 75:
| 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.
The module declaration is placed in a file named
For example, the following module declaration declares that the module
<syntaxhighlight lang="cpp">
module com.foo.bar {
Line 86:
}
</syntaxhighlight>
The public members of
The JDK itself has been modularized in [[Java version history#Java SE 9|Java 9]].<ref>{{cite web
Line 99:
}}</ref> For example, the majority of the Java standard library is exported by the module <code>java.base</code>.
<syntaxhighlight lang="Java">
import java.sql.*;
Line 106:
</syntaxhighlight>
Similarly, <syntaxhighlight lang="Java" inline>import module java.base;</syntaxhighlight>, similarly, imports all 54 packages belonging to <code>java.base</code>.
<syntaxhighlight lang="Java">
import module java.base;
/**
* importing module java.base allows us to avoid manually importing most classes
* the following classes (outside of java.lang) are used:
* java.text.MessageFormat
* java.util.Date
* java.util.List
* java.util.concurrent.ThreadLocalRandom
*/
public class Example {
public static void main(String[] args) {
List<String> colours = List.of("Red", "Orange", "Yellow", "Green", "Blue", "Indigo", "Violet");
IO.println(MessageFormat.format("My favourite colour is {0} and today is {1,date,long}",
colours.get(ThreadLocalRandom.current().nextInt(colours.size())),
new Date()
));
}
}
</syntaxhighlight>
Modules use the following [[List of Java keywords|keywords]]:
* <code>exports</code>: used in a module declaration to specify which packages are available to other modules
* <code>module</code>: declares a module
* <code>open</code>: indicates that all classes in a package are accessible via reflection by other modules
* <code>opens</code>: used to open a specific package for reflection to other modules
* <code>provides</code>: used to declare that a module provides an implementation of a service interface
* <code>requires</code>: used in a module declaration to specify that the module depends on another module
* <code>to</code>: used with the <code>opens</code> directive to specify which module is allowed to reflectively access the package
* <code>transitive</code>: used with the <code>requires</code> directive to indicate that a module not only requires another module but also makes that module's dependencies available to modules that depend on it
* <code>uses</code>: used in a module to declare that the module is using a service (i.e. it will consume a service provided by other modules)
* <code>with</code>: used with the <code>provides</code> directive to specify which implementation of a service is provided by the module
== Core modules ==
Line 112 ⟶ 146:
! scope="row" | {{code|java.base}}
| Defines the core APIs that form the foundation of the Java SE Platform.
Implicitly required by all modules and does not need to be declared with <code>requires</code> inside a module declaration.
|-
! scope="row" | {{code|java.compiler}}
| Defines APIs related to the language model, [[Java annotation]] processing, and the [[Java compiler]].
|-
! scope="row" | {{code|java.datatransfer}}
Line 279 ⟶ 314:
|-
! scope="row" | {{code|jdk.xml.dom}}
| Defines the JDK's subset of the [[World Wide Web Consortium]] (W3C) [[Document Object Model]] (DOM) API not covered by Java SE. Exports packages outside of the <code>java</code> namespace (from <code>org.w3c.dom</code>).
|-
! scope="row" | {{code|jdk.zipfs}}
Line 306 ⟶ 341:
* [[Classpath]]
* [[Java class loader]]
* [[
== References ==
Line 322 ⟶ 357:
[[Category:Java specification requests]]
[[Category:Modularity]]
|