Chapter 12 Modules Flashcards

Review Questions

1
Q

1.Which statement is true of the following module?
~~~
|—zoo
|– staff
|– Vet.java
~~~

A. The directory structure shown is a valid module.
B. The directory structure would be a valid module if module.java were added directly underneath zoo/staff.
C. The directory structure would be a valid module if module.java were added directly underneath zoo.
D. The directory structure would be a valid module if
module-info.java were added directly underneath zoo/staff.
E. The directory structure would be a valid module if
module-info.java were added directly underneath zoo.
F. None of these changes would make this directory structure a valid module.

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

2.Suppose module puppy depends on module dog and module dog depends on module animal. Fill in the blank so that code in module dog can access the animal.behavior
~~~
package in module animal.
module animal {
________ animal.behavior;
}
~~~

A. export
B. exports
C. require
D. requires
E. require transitive
F. requires transitive
G. None of the above

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

3.Fill in the blanks so this command to run the program is correct:
~~~
java
_______ zoo.animal.talks/zoo/animal/talks/Peacocks
_______ modules
~~~

A. -d and -m
B. -d and –p
C. -m and -d
D. -m and -p
E. -p and -d
F. -p and -m
G. None of the above

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

4.Which of the following pairs make up a service?
A. Consumer and service locator
B. Consumer and service provider interface
C. Service locator and service provider
D. Service locator and service provider interface
E. Service provider and service provider interface

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

5.A(n) \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_ module is on the classpath while a(n) \_\_\_\_\_\_\_\_\_\_\_\_ module is on the module path. (Choose all that apply.)
A. automatic, named
B. automatic, unnamed
C. named, automatic
D. named, unnamed
E. unnamed, automatic
F. unnamed, named
G. None of the above

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

6.Which of the following statements are true in a module-info.java file? (Choose all that apply.)
A. The opens directive allows the use of reflection.
B. The opens directive declares that an API is called.
C. The use directive allows the use of reflection.
D. The use directive declares that an API is called.
E. The uses directive allows the use of reflection.
F. The uses directive declares that an API is called.

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

7.An automatic module name is generated if one is not supplied. Which of the following JAR filenames and generated automatic module name pairs are correct? (Choose all that apply.)
A. emily-1.0.0.jar and emily
B. emily-1.0.0-SNAPSHOT.jar and emily
C. emily_the_cat-1.0.0.jar and emily_the_cat
D. emily_the_cat-1.0.0.jar and emily-the-cat
E. emily.$.jar and emily
F. emily.$.jar and emily.
G. emily.$.jar and emily..

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

8.Which of the following statements are true? (Choose all that apply.)
A. Modules with cyclic dependencies will not compile.
B. Packages with a cyclic dependency will not compile.
C. A cyclic dependency always involves exactly two modules.
D. A cyclic dependency always involves at least two requires statements.
E. An unnamed module can be involved in a cyclic dependency with an automatic module.

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

9.Suppose you are creating a service provider that contains the following class. Which line of code needs to be in your module-info.java?
~~~
package dragon;
import magic.*;
public class Dragon implements Magic {
public String getPower() {
return “breathe fire”;
}
}
~~~

A. provides dragon.Dragon by magic.Magic;
B. provides dragon.Dragon using magic.Magic;
C. provides dragon.Dragon with magic.Magic;
D. provides magic.Magic by dragon.Dragon;
E. provides magic.Magic using dragon.Dragon;
F. provides magic.Magic with dragon.Dragon;

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

10.What is true of a module containing a file named module-info.java with the following contents? (Choose all that apply.)
module com.food.supplier {}

A. All packages inside the module are automatically exported.
B. No packages inside the module are automatically exported.
C. A main method inside the module can be run.
D. A main method inside the module cannot be run since the class is not exposed.
E. The module-info.java file contains a compiler error.
F. The module-info.java filename is incorrect.

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

11.Suppose module puppy depends on module dog and module dog depends on module animal. Which lines allow module puppy to access the animal.behavior package in module animal? (Choose all that apply.)
~~~
module animal {
exports animal.behavior;
}
module dog {
_______ animal; // line S
}
module puppy {
_______ dog; // line T
}
~~~

A. require on line S
B. require on line T
C. requires on line S
D. requires on line T
E. require transitive on line S
F. require transitive on line T
G. requires transitive on line S
H. requires transitive on line T

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

12.Which of the following modules are provided by the JDK? (Choose all that apply.)
A. java.base
B. java.desktop
C. java.logging
D. java.util
E. jdk.base
F. jdk.compiler
G. jdk.xerces

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

13.Which of the following compiles and is equivalent to this loop?

A.
~~~
List<Unicorn> all = new ArrayList<>();
for (Unicorn current : ServiceLoader.load(Unicorn.class))
all.add(current);
~~~
B.
~~~
List<Unicorn> all = ServiceLoader.load(Unicorn.class)
.getStream()
.collect(Collectors.toList());
~~~
C.
~~~
List<Unicorn> all = ServiceLoader.load(Unicorn.class)
.stream()
.collect(Collectors.toList());
~~~</Unicorn></Unicorn></Unicorn>

D.
~~~
List<Unicorn> all = ServiceLoader.load(Unicorn.class)
.getStream()
.map(Provider::get)
.collect(Collectors.toList());
~~~</Unicorn>

E.
~~~
List<Unicorn> all = ServiceLoader.load(Unicorn.class)
.stream()
.map(Provider::get)
.collect(Collectors.toList());
~~~
F. None of the above</Unicorn>

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

14.Which of the following are legal commands to run a modular program where n is the module name and c is the fully qualified class name? (Choose all that apply.)
A. java –module-path x -m n.c
B. java –module-path x -p n.c
C. java –module-path x-x -m n/c
D. java –module-path x -p n/c
E. java –module-path x-x -m n-c
F. java –module-path x -p n-c
G. None of the above

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

15.For a top-down migration, all modules other than named modules are \_\_\_\_\_\_\_\_\_\_\_\_\_
modules and are on the \_\_\_\_\_\_\_\_\_\_\_\_.
A. automatic, classpath
B. automatic, module path
C. unnamed, classpath
D. unnamed, module path
E. None of the above

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

16.Suppose you have separate modules for a service provider interface, service provider, service locator, and consumer. If you add a second service provider module, how many of these modules do you need to recompile?
A. Zero
B. One
C. Two
D. Three
E. Four

A
17
Q
  1. Suppose we have a JAR file named cat-1.2.3-RC1.jar, and Automatic-Module-Name in the MANIFEST.MF is set to dog. What should an unnamed module referencing this automatic module include in module-info.java?
    A. requires cat;
    B. requires cat.RC;
    C. requires cat-RC;
    D. requires dog;
    E. None of the above
A
18
Q

18.Which commands are used to create a smaller Java image and work with native code, respectively?
A. jimage and jlink
B. jimage and jmod
C. jlink and jimage
D. jlink and jmod
E. jmod and jimage
F. jmod and jmod

A
19
Q

19.Which are true statements about the following module? (Choose all that apply.)
~~~
class dragon {
exports com.dragon.fire;
exports com.dragon.scales to castle;
}
~~~

A. All modules can reference the com.dragon.fire package.
B. All modules can reference the com.dragon.scales package.
C. Only the castle module can reference the com.dragon.fire package.
D. Only the castle module can reference the com.dragon.scales package.
E. None of the above

A
20
Q

20.Which would you expect to see when describing any module?
A. requires java.base mandated
B. requires java.core mandated
C. requires java.lang mandated
D. requires mandated java.base
E. requires mandated java.core
F. requires mandated java.lang
G. None of the above

A
21
Q

21.Suppose you have separate modules for a service provider interface, service provider, service locator, and consumer. Which module(s) need to specify a requires directive on the service provider?
A. Service locator
B. Service provider interface
C. Consumer
D. Consumer and service locator
E. Consumer and service provider
F. Service locator and service provider interface
G. Consumer, service locator, and service provider interface
H. None of the above

A
22
Q

22.Which are true statements? (Choose all that apply.)
A. An automatic module exports all packages to named modules.
B. An automatic module exports only the specified packages to named modules.
C. An automatic module exports no packages to named modules.
D. An unnamed module exports only the named packages to named modules.
E. An unnamed module exports all packages to named modules.
F. An unnamed module exports no packages to named modules.

A
23
Q

23.Which is the first line to contain a compiler error?
~~~
1: module snake {
2: exports com.snake.tail;
3: exports com.snake.fangs to bird;
4: requires skin;
5: requires transitive skin;
6: }
~~~

A. Line 1
B. Line 2
C. Line 3
D. Line 4
E. Line 5
F. The code does not contain any compiler errors.

A
24
Q

24.Which are true statements about a package in a JAR on the classpath containing a module-info.java file? (Choose all that apply.)
A. It is possible to make the package available to all other modules on the classpath.
B. It is possible to make the package available to all other modules on the module path.
C. It is possible to make the package available to exactly one other specific module on the classpath.
D. It is possible to make the package available to exactly one other specific module on the module path.
E. It is possible to make sure the package is not available to any other modules on the classpath.

A
25
Q

25.Suppose you have separate modules for a service provider interface, service provider, service locator, and consumer. Which statements are true about the directives you need to specify? (Choose all that apply.)
A. The consumer must use the requires directive.
B. The consumer must use the uses directive.
C. The service locator must use the requires directive.
D. The service locator must use the uses directive.
E. None of the above

A