C4 - Lesson 4: Java Modules Flashcards
export
exports: Identify a package that should be available to users of this module. Takes a package name as a parameter. Does not include subpackages.
requires
- requires: Make the packages in the specified module available in this module. You cannot require a package that also requires you
- Is like the import
module descriptor
- it is the modules-info.java
- module name
indicates which packages the module makes available, as well as which modules this module relies on - has the “module” keyword
modules
- Is a jar
- They also contain one additional class called a module descriptor modules-info.java
MODULEPATH
- you place your modules at a different location, called the MODULEPATH.
- This is the path where the compiler looks for all your modules.
to
The to keyword can be used to modify exports to limit which modules can access the specified package.
transitive
The transitive keyword modifies the requires keyword and specifies that the required module will also be made available to any other module that includes this module.
reflection access.
,
CLASSPATH
This is the path where the compiler looks for all your class files. - Before java 9 building a Java project involved placing all project classes and jars on the CLASSPATH
What happens in java 9+ if something does not use modules?
- All Java applications compiled in Java 9+ use the module system
- Even if they contain no modules and do not use a module descriptor, everything placed on the CLASSPATH are placed into what is called the Unnamed Module.
Named, Unnamed and automatic modules: Access comparasion
- Named: Named and automatic
- Unnamed: Unnamed and automatic
- automatic: Named and Unnamed
Classpath and modulepath in maven
Modulepath
- Modular jars
- Nonmodular dependencies. This become automatics module with same name
- Transitive dependencies that are modules
Classpath
- Transitive dependencies that are not modules
open
opens: Makes the specified package available for both public and private class reflection access. Can optionally use the to keyword to limit which modules have this access.