Chapter 12 Modules Flashcards
Review Questions
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.
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
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
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
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
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.
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..
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.
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;
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.
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
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
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>
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
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