01. Which scenario is the best use of an exception?
a) An element is not found when searching a list.
b) An unexpected parameter is passed into a method.
c) The computer caught fire.
d) You want to loop through a list.
d) You don’t know how to code a method.
02. Which statements about functional interfaces are true?
(Choose all that apply.)
a) A functional interface can contain default and private methods.
b) A functional interface can be defined as a class or an interface.
c) Abstract methods with signatures that are contained in public methods of java.lang.Object do not count toward the abstract method count for a functional interface.
d) A functional interface cannot contain static or private static methods.
e) A functional interface must be marked with the @FunctionalInterface annotation.
03. Suppose we have a JDBC program that calls a stored procedure, which returns a set of results. Which is the correct order in which to close database resources for this call?
a) Connection, ResultSet, CallableStatement
b) Connection, CallableStatement, ResultSet
c) ResultSet, Connection, CallableStatement
d) ResultSet, CallableStatement, Connection
e) CallableStatement, Connection, ResultSet
f) CallableStatement, ResultSet, Connection
04. 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.
05. Which of the following statements about resource bundles are correct?
(Choose all that apply.)
a) All keys must be in the same resource bundle to be used.
b) A resource bundle is loaded by calling the new ResourceBundle() constructor.
c) Resource bundle values are always read using the Properties class.
d) Changing the default locale lasts for only a single run of the program.
e) If a resource bundle for a specific locale is requested, then the resource bundle for the default locale will not be used.
f) It is possible to use a resource bundle for a locale without specifying a default locale.
06. 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
07. Which of the following statements are true in a module-info.java file?
(Choose all that apply.)
a) The opens keyword allows the use of reflection.
b) The opens keyword declares an API is called.
c) The use keyword allows the use of reflection.
d) The use keyword declares an API is called.
e) The uses keyword allows the use of reflection.
f) The uses keyword declares an API is called.
g) The file can be empty (zero bytes).
08. 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
09. Which happens when a new task is submitted to an ExecutorService in which no threads are available?
a) The executor throws an exception when the task is submitted.
b) The executor discards the task without completing it.
c) The executor adds the task to an internal queue and completes when there is an available thread.
d) The thread submitting the task waits on the submit call until a thread is available before continuing.
e) The executor stops an existing task and starts the newly submitted one.
10. Which class would be best to use to read a binary file into a Java object?
a) ObjectInputStream
b) FileReader
c) BufferedStream
d) ObjectReader
e) ObjectOutputStream
f) ObjectWriter
g) None of the above