CH12 - Modules Flashcards

(19 cards)

1
Q

What is module

A

A module is a group of one or more packages plus a special file called module-info.java

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Module declaration Rules

A
  1. The module-info.java file must be in the root directory of your module. Regular Java classes should be in packages.
  2. The module declaration must use the keyword module instead of class, interface or enum.
  3. The module name follows the naming rules for package names. It often includes periods (.) in its name. Regular class and package names are not allowed to have dashes (-). Module names follow the same rule
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

export

A

It is used to indicate that a module intends for those packages to be used by Java code outside the module.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Java module

A

It is a packaging mechanis that enables you to package a Java application or Java API as a separate Java module.

A Java module can specify which of the Java packages it contains that should be visible to other Java modules which uses this module.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Modules contain

A

A java module is one or more Java packages that belong together. A module could be either a full Java application, a Java Platform API, or third party API>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Module exports

A

A Java module must explicitly export all packages int he module that are to be accessible for other modules using the module.

module com.jenkov.mymodule {
exports com.jenkov.mymodule;
}

No “subpackages” of the exported package are exported.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Parent package export

A

You dont have to export the parent package in order to export a subpackage.

module com.jenkov.mymodule {
exports com.jenkov.mymodule.util;
}

This example only exports the com.jenkov.mymodule.util package, and not the com.jenkov.mymodule package.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Module requires

A

If a Java module requires another module to do its work, that module must be specified in the module descriptior too.

module com.jenkov.mymodule {
requires javafx.graphics;
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Circular Dependencies Not Allowed

A

It is not allowed to have circular dependencies between modules. In other words, If module A requires module B, then module B cannot also require module A. The module dependency graph must be an acyclic graph.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Split Packages Not Allowed

A

The same Java package can only be exported by a single Java module at runtime.

Having two modules export the same package is also sometimes referred to as a split package. By split package is meant that the total content (classes) of the package is split between multiple modules. This is not allowed

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

🔧 What is a Service in Java Modules (JPMS)?

A

In JPMS, a Service is a way to allow one module to provide implementations of an interface, and another module to consume (use) them — without tightly coupling the two modules.

It’s part of the Service Provider Interface (SPI) mechanism, now integrated into the module system.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

JPMS key Concepts

A

🧩 Key Concepts
provides – a module provides an implementation of a service.

uses – a module uses a service.

ServiceLoader – used at runtime to load the implementations.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Service Implementation Module

A

A Java module that wants to implement a service interface from a service interface module must:

-Require the service interface module in its own module descriptor.
-Implement the service interface with a Java class.
-Declare the service interface implementation in its module descriptor.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Automatic Module

A

It appears on the module path but does not contain a module-info.java file. It is simply a regular JAR file that is placed on the module path and gets treated as a module

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

A service

A

A service consists of the service provider interface and logic to look up implementations of using a service locator.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Automatic modules

A

Automatic modules are on the module path but do not have a module-info.java file

16
Q

Named modules

A

Named modules are on the module path and do have a module-info.java.

17
Q

Unnamed modules

A

Unnamed modules are on the classpath.

18
Q

A cyclic dependency

A

A cyclic dependency is when a module graph forms a circle.