Chapter 17 Modular Applications Flashcards

1
Q

Reviewing Module Directives

A

Common module directives

  1. exports <package>
    Allows all modules to access the package
  2. exports <package> to <module>
    Allows a specific module to access the package
  3. requires <module>
    Indicates module is dependent on another module
  4. requires transitive <module>
    Indicates the module and that all modules that use this module are dependent on another module
  5. uses <interface>
    Indicates that a module uses a service
  6. provides <interface> with <class>
    Indicates that a module provides an implementation of a service
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Comparing Types of Modules

A

Three types of modules:

  1. named modules
  2. automatic modules
  3. unnamed modules
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

CLASSPATH VS. MODULE PATH

A
  • the Java runtime is capable of using class and interface types from both the classpath and the module path, although the rules for each are a bit different.
  • An application can access any type in the classpath that is exposed via standard Java access modifiers, such as a public class.
  • public types in the module path are not automatically available. While Java access modifiers must still be used, the type must also be in a package that is exported by the module in which it is defined. In addition, the module making use of the type must contain a dependency on the module.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

NAMED MODULES

A
  • A named module is one containing a module‐info file.
  • this file appears in the root of the JAR alongside one or more packages.
  • Unless otherwise specified, a module is a named module.
  • Named modules appear on the module path rather than the classpath.
  • You’ll learn what happens if a JAR containing a module‐info file is on the classpath.
  • For now, just know it is not considered a named module because it is not on the module path.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

AUTOMATIC MODULES

A
  • An automatic module appears on the module path but does not contain a module‐info file.
  • It is simply a regular JAR file that is placed on the module path and gets treated as a module.
  • The code referencing an automatic module treats it as if there is a module‐info file present. It automatically exports all packages.
  • It also determines the module name.
  • When Java 9 was released, authors of Java libraries were encouraged to declare the name they intended to use for the module in the future. All they had to do was set a property called Automatic‐Module‐Name in the MANIFEST.MF file.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

ABOUT THE MANIFEST

A
  • A JAR file is a zip file with a special directory named META‐INF.
  • The MANIFEST.MF file is always present.
  • The manifest contains extra information about the JAR file.
  • For example, it often contains the version of Java used to build the JAR file. For command‐line programs, the class with the main() method is commonly specified.
  • Each line in the manifest is a key/value pair separated by a colon.
  • The default manifest in Java 11 looks like this:
Manifest-Version: 1.0
Created-By: 11.0.2 (Oracle Corporation)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Determining the name of an automatic module.

A
  • If the MANIFEST.MF specifies an Automatic‐Module‐Name, use that. Otherwise, proceed with the remaining rules.
  • Remove the file extension from the JAR name.
  • Remove any version information from the end of the name. A version is digits and dots with possible extra information at the end, for example, ‐1.0.0 or ‐1.0‐RC.
  • Replace any remaining characters other than letters and numbers with dots.
  • Replace any sequences of dots with a single dot.
  • Remove the dot if it is the first or last character of the result.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Practicing with automatic module names

commons2‐x‐1.0.0‐SNAPSHOT.jar
A
  1. Beginning JAR name
    commons2‐x‐1.0.0‐SNAPSHOT.jar
  2. Remove file extenstion
    commons2‐x‐1.0.0‐SNAPSHOT
  3. Remove version information
    commons2‐x
  4. Replace special characters
    commons2.x
  5. Replace sequence of dots
    commons2.x
  6. Remove leading/trailing dots (results in the automatic module name)
    commons2.x
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Practicing with automatic module names

mod_$‐1.0.jar
A
  1. Beginning JAR name
    mod_$‐1.0.jar
  2. Remove file extenstion
    mod_$‐1.0
  3. Remove version information
    mod_$
  4. Replace special characters
    mod..
  5. Replace sequence of dots
    mod.
  6. Remove leading/trailing dots (results in the automatic module name)
    mod
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

UNNAMED MODULES

A
  • An unnamed module appears on the classpath.
  • Like an automatic module, it is a regular JAR.
  • Unlike an automatic module, it is on the classpath rather than the module path.
  • This means an unnamed module is treated like old code and a second‐class citizen to modules.
  • An unnamed module does not usually contain a module‐info file.
  • If it happens to contain one, that file will be ignored since it is on the classpath.
  • Unnamed modules do not export any packages to named or automatic modules.
  • The unnamed module can read from any JARs on the classpath or module path.
  • You can think of an unnamed module as code that works the way Java worked before modules. Yes, we know it is confusing to have something that isn’t really a module having the word module in its name.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

COMPARING MODULE TYPES

A

test

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

Analyzing JDK Dependencies

A

test

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

IDENTIFYING BUILT-IN MODULES

A

test

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

USING JDEPS

A

test

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

ABOUT SUN.MISC.UNSAFE

A

test

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

Migrating an Application

A

test

17
Q

MIGRATING YOUR APPLICATIONS AT WORK

A

test

18
Q

DETERMINING THE ORDER

A

test

19
Q

EXPLORING A BOTTOM-UP MIGRATION STRATEGY

A

test

20
Q

EXPLORING A TOP-DOWN MIGRATION STRATEGY

A

test

21
Q

SPLITTING A BIG PROJECT INTO MODULES

A

test

22
Q

FAILING TO COMPILE WITH A CYCLIC DEPENDENCY

A

test

23
Q

Creating a Service

A

test

24
Q

DECLARING THE SERVICE PROVIDER INTERFACE

A

test

25
Q

CREATING A SERVICE LOCATOR

A

test

26
Q

INVOKING FROM A CONSUMER

A

test

27
Q

ADDING A SERVICE PROVIDER

A

test

28
Q

MERGING SERVICE LOCATOR AND CONSUMER

A

test

29
Q

REVIEWING SERVICES

A

test