Chaper 12 - Modules Flashcards
What does the Java Platform Module System (JPMS) do?
- Groups code at a higher level than packages
- Developers can declare what packages are available outside the module
What is the special file called needed for using modules?
module-info.java
This file contains the module declaration
What are the 6 benefits of using modules?
- Better access control
You can specifically allow a package to be accessed by a certain package. - Clearer dependency management
- Custom Java Builds
You can create a java runtime that only needs a small part of JDK, so you won’t need to load the full 150MB JDK. - Improved security
- Improved performance
Because the program starts op in smaller java packages (/modules) it improves startup time and has a lower memory requirement. - Unique package enforcement
Modules specify exposed packages, so Java can ensure that each package comes from only one module and avoid confusion about what needs to run
What naming conventions do modules follow?
The naming conventions from a package. so a Module name should be: food.eat.module
and NOT EatModule
What is the command line format when to run to compile your module?
javac –module-path <module-path> -d <directory> <module-path>/module-info.java</module-path></directory></module-path>
What is the command line syntax to access Directory for class files?
-d{dir}
What is the command line syntax to access the module path?
-p <module_path> // --module-path <module_path></module_path></module_path>
What is the command line format when you want to run a module?
java – module-path <module_path> ---module <module_name>/<package_name>.<class_name></class_name></package_name></module_name></module_path>
What is the command line syntax to access the module name?
-m <module_name> Or --module <module_name></module_name></module_name>
What is the command line syntax to access the module path?
-p <path> OR --module-path <module_path></module_path></path>
Which modules are present on the module path?
only named and automatic modules
is this a legal module name:
com.amazing.movierental
Yes, it is. small letters only
is this a legal module name:
com.amazing.$movierental
Yes it is, allow to start a module and package with ‘$’
is this a legal module name:
com.amazing.1movierental
No, you can’t start a module, or package-, name with a number
is this a legal module name:
com.amazing.movie-rental
No, you are not allowed to use a ‘-‘
is this a legal module name:
com.amazing.movie_rental
yes, you are allowed to use an underscore
True or false. The module system has 3 phases:
- compile-time
- link-time
- runtime
True;
“link time”, is an optional phase between the two in which a set of modules can be assembled and optimized into a custom run-time image. The benefit of this phase is that the size of the resultingapplication is reduced because only those classes that are actually used are included in the application artifacts.
Which statement would you need to have in the module-info of a Java Swing based desktop application?
requires java.desktop;
What does “exports <package_name>" do in the module-info.java file?</package_name>
It makes a package available outside it’s own module.
If we don’t add the exports statement it is only possible to run that package from the command line within it’s own package.
What does “requires <package_name>" do in the module-info.java file?</package_name>
It makes clear that <package_name> (from an other module) is needed to run this module.</package_name>
How can you export a package only to specific package?
“exports <package_name> to <module_name>;"</module_name></package_name>
Is a PRIVATE method available within the module and/or outside the module?
in the module: available but only in the class
outside the module: no access
Is a PACKAGE-PRIVATE method available within the module and/or outside the module?
in the module: Available in the package
outside the module: no access