1Z0-829 Flashcards

1
Q

What is the command line used to compile the Java class Wolf.java in the default package, and what file does it generate?

A
  1. javac Wolf.java
  2. Wolf.class
    Run: javac Wolf.java (and it generates Wolf.class)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

True or false?
An interface can extend multiple interfaces.

A

True

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

What security attack does using a PrepraredStatement help with?

A

SQL injection

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

True or false?
A static method is allowed to reference an instance variable.

A

False
(except through a reference to a class instance)

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

What methods on PreparedStatement can run a DELETE SQL statement?

A

executeUpdate() and execute()

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

What command is used to create a runtime image?

A

jlink

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

True or false?
The sorted() intermediate operation has overloaded versions that allow passing or omitting a Comparator.

A

True

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

Which Collections method provides a thread-safe version of an existing Map?

A

Collections.synchronizedMap()

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

True or false?
A private static interface method can access a default interface method within the same interface.

A

False

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

Given p || q, where both p and q are true expressions, which side will not be evaluated at runtime?

A

q

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

What method is used to retrieve a parallel stream from an existing stream?

A

parallel()

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

What is unreachable code?

A

Any lines of code that the compiler determines it is not possible to reach at runtime

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

True or false? Arrays.asList() returns an immutable list.

A

False. It returns a fixed-sized list backed by an array.

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

True or false? Polymorphism allows an object to be passed as a class it inherits but not an interface type.

A

False. Polymorphism allows an object to be passed by any reference type that the class inherits.

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

What is a redundant package import?

A

A package import that is unnecessary. Removing the import does not prevent the code from compiling.

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

What NIO.2 Files methods allow you to both read and write file attributes?

A

Files.getFileAttributeView()

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

What is a locale category, and how is it used?

A

A locale category is a way to differentiate between the display and formatting of locale-based values.

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

Which method should be called before calling mark() on an arbitrary InputStream?

A

markSupported()

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

True or false? Objects in Java can inherit at most one class.

A

False. While Java does rely on single inheritance, a class can extend another class, so a single class may inherit multiple classes.

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

What does executeQuery() return in JDBC?

A

ResultSet

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

True or false? If a module doesn’t contain a module-info file, one is automatically generated.

A

False

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

Under what conditions may a resource created before a try-with-resources statement be used in a try-with-resources declaration?

A

The resource must be marked final or effectively final.

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

True or false? If a method has an int return type and does not throw an exception, it must return a value.

A

True

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

Name two ways to prevent an immutable class from being extended by a mutable subclass.

A

Mark the class final or make all of the constructors private.

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

Which Lock method will wait indefinitely for a lock if it cannot be acquired?

A

lock()

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

Which of the following requires an explicit cast to be assigned to a short value? int, byte, float, bit

A

int and float require an explicit cast, while byte does not. Note that bit is not a primitive type in Java.

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

Given an interface Fly with no abstract methods, how would you create an instance of an anonymous class that implements it?

A

new Fly() {}

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

Which of these are required in a stream pipeline: source, intermediate operation, terminal operation?

A

Source and terminal operation

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

Given an outer class Rooster and its inner class Wattle, how would you create an instance of Wattle within an instance method of Rooster?

A

new Wattle()

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

What type of module is on the classpath?

A

Unnamed module

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

True or false?
All operators are evaluated from left to right.

A

False.
The assignment operator is evaluated from right to left.

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

True or false? Overloaded methods have the same method signatures.

A

False. The parameter lists must be different.

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

True or false? A static method is allowed to reference an instance variable.

A

False (except through a reference to a class instance)

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

Which Collections method provides a thread-safe version of an existing Map?

A

Collections.synchronizedMap()

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

Either of which two complementary operators can be used to test if x is greater than or equal to y?

A

> = or <

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

What does the following output?
~~~
int[] x = { 7, 8, 9};
int[] y = { 7, 7, 7};
System.out.println(Arrays.compare(x, y) + “ “ + Arrays.mismatch(x, y));
~~~

A

1 1

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

If an interface is annotated with @FunctionalInterface, what three common abstract methods can the interface declare in addition to the custom single abstract method?

A

toString(), hashCode(), and equals()

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

True or false? A vararg that takes a list of int values can be written within a method declaration using int… or int[].

A

False. Only … can be used to declare a vararg.

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

True or false? If a text block ends with gerbil”””, a new line is added.

A

False

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

True or false? An instance method that uses the synchronized modifier is equivalent to a method that does not but wraps the body of the method in synchronized(this) {} block.

A

True

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

On what class do you call a method to create a CallableStatement?

A

Connection

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

True or false?
All method references can be rewritten as a lambda.

A

True.
A method reference is a short form of a lambda.

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

var can be used as the type for which of the following: instance variable, static variable, local variable, constructor parameter, method parameter?

A

var can be used only as a local variable.

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

Which functional interface takes two parameters and returns a boolean?

A

BiPredicate

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

Without using any variables, what could you write to negate the value -5?

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

True or false? If a try-with-resources block causes multiple exceptions to be thrown at the same time, the first exception encountered becomes the primary, and the rest become suppressed exceptions.

A

True

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

Fill in the blank: A _ class is the first non-abstract class that extends an abstract class and is required to implement all inherited abstract methods.

A

concrete

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

What does JAR stand for?

A

Java archive

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

True or false? A class must implement Closeable to be used in a try-with-resources statement.

A

False. The class must implement AutoCloseable.

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

Fill in the blank with explicit or implicit: Accessing an object by one of its supertypes can be done with an \_\_\_\_\_\_\_\_\_ cast.

A

implicit

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

What parameter type can fill in the blank for a CallableStatement for the following? cs.setInt(\_\_\_\_\_, 1);

A

int or String

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

Which functional interface is declared with two generics and has an apply() method?

A

Function

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

What will equals() return when comparing a List and Set with the same elements?

A

false

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

True or false? Unary operators have the highest order of precedence.

A

True

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

What is the name of the method that creates Path objects in the Paths class?

A

Paths.get()

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

How do you create an Optional without a value?

A

Optional.empty()

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

True or false? In a JDBC URL, the port is required.

A

False

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

Fill in the blank to make this code compile:
~~~
List<______ Number> listOfNumbers = new ArrayList<object>();
~~~</object>

A

? super (this is a lower bound)

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

How many operators in Java take three values?

A

Just one, the ternary operator

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

Name a terminal operation that can always terminate on an infinite stream.

A

findAny() or findFirst()

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

What methods can remove whitespace from the end of a String ?

A

trim(), strip(), stripTrailing()

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

What symbol is used to represent a bind variable in a PreparedStatement?

A

Question mark (?)

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

Where can a call to super() or this() occur within a constructor?

A

As the first statement of the constructor

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

What character is used to escape values in a date formatter?

A

A single quote (‘)

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

What is it called when two threads are stuck forever but appear to be active and making progress?

A

Livelock

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

Which data types are supported as the target of an if statement’s conditional clause?

A

Only boolean

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

When passing an object to a method, how can the method be written to change the object that the caller references?

A

It cannot. A method cannot directly change the reference the caller passes so that the caller sees the change.

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

What functional interface does Java provide that declares a single method that returns a boolean?

A

Predicate

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

What Map method gives you all the keys?

A

keySet()

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

Write a for-each loop that iterates over an int[] data in reverse.

A

Trick question. For-each loops cannot be used to iterate over a data structure in reverse order.

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

Fill in the blank: An instance initializer can access \_\_\_\_\_\_\_\_\_ variables declared in the class.

A

static and instance

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

True or false?
If an automatic module name is not specified, Java keeps dots in the generated name.

A

True

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

Which keyword(s) can be used to access a member declared within the class?

A

this

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

When calling a String.format() method, what is the meaning of the symbols %n and %d?

A

The %n symbol is used to indicate a new line, while the %d symbol is used for integer values.

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

Name the four rules an overridden method must follow.

A

An overridden method must have the exact same signature, the same or a more accessible access modifier, and a covariant return type. It also must not throw a new or broader checked exception.

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

What is the purpose of using a try-with-resources statement?

A

Ensures that resources like files and database connections are properly closed at the conclusion of the try section

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

What does the Path resolve() method do?

A

It joins two paths. If the input argument to the method is an absolute path, then that value is returned.

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

Fill in the blanks: When executing a jar command, \_\_\_\_\_ is used to specify the JAR should be created, while \_\_\_\_\_ is used to specify the directory used to create the JAR.

A

Lowercase -c is used to specify that the JAR should be created, while uppercase -C is used to specify the directory used to create the JAR.

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

What is the most common signature of a main() method?

A
public static void main(String[] args)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
80
Q

What does the following expression return?
~~~
new StringBuilder(“Hello”).equals(“Hello”)
~~~

A

false, as they are not the same object type

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

When converting from an IntStream to a CharStream, what mapping method do you call?

A

Trick question. There is no CharStream.

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

Does Duration or Period support hours?

A

Duration

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

Which option should you use when calling Files.copy() if you want to overwrite the target file if it already exists?

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

What is the difference between the & and && operators when applied to boolean expressions?

A

The logical operator (&) evaluates both sides of the expression, while the short-circuit operator (&&) only evaluates the right side of the expression if the left side is true.

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

True or false? Queue.of() returns an immutable list.

A

False. This method does not exist.

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

True or false? Creating an instance variable with package access allows a subclass to access it under certain circumstances.

A

True, if the subclass is in the same package

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

What method should you call for OUT parameters when working with a CallableStatement?

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

What functional interfaces have andThen() as a helper method?

A

Consumer and Function

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

Besides letters and numbers, what symbols are permitted to be used in identifiers?

A

_ and currency symbols

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

How many loop variables can a traditional for loop have?

A

There is no specified limit.

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

Given an interface Cat with a default method meow(), what is the syntax for accessing this default method within a class that implements Cat, assuming that the class may override the method?

A
Cat.super.meow()
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
92
Q

Do lower or upper bounds allow you to add elements to a list?

A

Lower bounds do because they specify the class that all types must be above using super.

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

True or false? Garbage collection is guaranteed to run at a fixed schedule and when the JVM is low on memory.

A

False. The JVM controls when garbage collection is run, and when it occurs is not guaranteed.

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

Which keyword(s) can be used to access a member of the parent class?

A

super or this

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

True or false? If one lambda parameter uses var as the type, all other parameters in that lambda must as well.

A

True. The type format must be consistent within a lambda.

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

True or false? An anonymous class can only be declared as extending one class or implementing one interface.

A

True

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

What are acceptable data types on the right-hand side of a for-each loop?

A

A built-in array or class that implements java.lang.Iterable

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

What String method returns the position of a value in a String?

A

indexOf()

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

True or false? A class can implement two interfaces that have the same method signature.

A

True, provided the methods are compatible using the rules for overridden methods

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

What is a compile-time constant variable?

A

A variable that is marked final and initialized with a literal value when it is declared

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

What is the purpose of sealing an interface?

A

To restrict which interfaces can extend the interface or classes that can implement the interface

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

Rank these operators from highest operator precedence to lowest: + (addition) * ! == ++ ||

A

++
!
*
+
==
||

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

True or false? An instance method is allowed to reference a static variable.

A

True

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

True or false? indent(x) can take positive or negative integers as a parameter.

A

True. Negative integers will remove leading whitespace.

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

Besides itself, which numeric primitive types can be implicitly cast to double?

A

byte, short, int, float, long

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

Which sorts first: letters or numbers?

A

Numbers

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

What Collector would you use to return the type Map<String, List<String>>?

A

Collectors.groupingBy()

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

Which operator can be used to avoid cast exceptions at runtime?

A

instanceof

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

True or false? Records are both immutable and encapsulated.

A

True

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

A sealed class most closely resembles what other top-level type?

A

An enum

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

What Java Collections Framework interface requires unique elements?

A

Set

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

A thread has started but is waiting for a lock to become available. What state is it in?

A

BLOCKED

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

True or false? A vararg that takes a list of int values can be written within a method declaration using int… or int[].

A

False. Only … can be used to declare a vararg.

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

True or false? Calling rs.getString(1) before calling rs.next() throws a SQLException on a ResultSet.

A

True

113
Q

What return types are covariant with void?

A

Only void.

114
Q

How are suppressed exceptions created?

A

When more than one exception is thrown at the same time, all but the first exception are suppressed. Suppressed exceptions can come from close() methods within try-with-resource statements or a finally block.

115
Q

When closing a Statement, what other resources get closed?

A

ResultSet, if there is one opened by the statement

116
Q

What is the name of the parameter that can enable or disable the helpful NullPointerException feature?

A

ShowCodeDetailsInExceptionMessages

117
Q

True or false?
If the database field is a String, calling resultSet.getObject() returns an object that can be cast to a String.

A

True

118
Q

If you have a large file, which NIO.2 method should you use to read the lines of the file and why?

A

Files.lines() since the data is read using lazy evaluation

119
Q

What primitive has exactly one predefined functional interface?

A

Boolean with the functional interface BooleanSupplier

120
Q

Which ExecutorService method will synchronously wait for an entire Collection of tasks to complete?

A

invokeAll()

121
Q

What is the most restrictive access modifier?

A

private

122
Q

Name the four types of nested classes.

A

Inner class, static nested class, local class, and anonymous class

123
Q

When autocommit mode is turned off, what method saves the data to the database?

A

commit()

124
Q

Write a static import to import the static LENGTH variable of a.b.C.

A

import static a.b.C.LENGTH;
or
import static a.b.C.*;

125
Q

True or false? Pattern matching allows you to avoid performing a separate cast operator.

A

True

126
Q

In what order should a Connection, PreparedStatement, and ResultSet be closed?

A

ResultSet
PreparedStatement
Connection

127
Q

In a top-down migration of three modules, how many modules are on the module path after migrating the first module?

A

Three

128
Q

True or false? Nested loops can only be used with for loops.

A

False. Other types of loops, such as while and do while, can be used as nested loops.

129
Q

Which NIO.2 method returns the index of the first differing position of the contents of two files?

A

Files.mismatch()

130
Q

Which modifier is used to indicate a field should not be serialized?

A

transient

131
Q

Name the eight Java primitive types and indicate which are integer types, which are floating-point types, and which are neither, in increasing order of size.

A

In increasing order of size for each group: byte, short, char, int, and long are integer types; float and double are floating-point types; and boolean is neither.

1.byte
2.short
3.char
4.int
5.long
6.float
7.double
8.boolean

132
Q

What wrapper class goes with int?

A

Integer

133
Q

Which two static methods create an infinite stream of int primitives?

A

IntStream.generate() and IntStream.iterate()

134
Q

What is the value of 10 % 3 and 10 / 3?

A

1 and 3

135
Q

In a bottom-up migration of three modules, how many modules are on the module path after migrating the first module?

A

One

136
Q

True or false?
Math.round() returns the same primitive type it is passed.

A

False. It returns int/long when passed float/double, respectively.

137
Q

True or false? The NIO.2 Files class includes an overloaded copy() method that can write a file to an I/O stream.

A

True

138
Q

How many objects are created in String[] s = new String[5];?

A

Just one.
The references are all set to null by default.

139
Q

List all the access modifiers.

A

public, private, protected, and package. The first three are keywords. The last is specified with the lack of a keyword.

140
Q

What does the Collection removeIf() operation do, and what parameter does it take?

A

The removeIf() operation takes a Predicate<T> and removes all elements from a Collection for which the Predicate<T> evaluates to true.</T></T>

141
Q

Which java.io.File method is used to create a single directory?

A

mkdir()

142
Q

In a service, what is the name of the artifact that implements an interface?

A

Service provider

143
Q

What are the names of the options available to set a classpath in a java or javac command?

A

-cp, -classpath, and –class-path

144
Q

What is operator precedence?

A

Some operators have higher precedence and therefore are executed before other operators when reading from left to right.

145
Q

What is flow scoping?

A

Flow scoping means the variable is only in scope when the compiler can definitively determine its type.

146
Q

What type of module is on the module path but does not have a module-info.java file?

A

Automatic module

147
Q

Which operator increments a value and returns the original value?

A

The post-increment operator: variable++

148
Q

What is wrong with public void method(String… s, int… b) {}?

A

A vararg parameter must be the last parameter in a parameter list, and only one is allowed per method.

149
Q

What is printed if you fail to catch an unchecked exception?

A

A stack trace

150
Q

What method can you call on IntStream to get the sum and average?

A

summaryStatistics()

151
Q

True or false?
If a resource bundle for the requested locale is not available, the default locale may be used.

A

True

152
Q

Which List class creates a new underlying instance of the class anytime it is modified?

A

CopyOnWriteArrayList

153
Q

Which functional interface takes one parameter and returns a (possibly) different Object type?

A

Function

154
Q

What terminal operation has three overloaded signatures where one returns an Optional and two do not?

A

reduce()

155
Q

True or false?
stripIndent() can get rid of the extra space characters in “happy birthday”.

A

False.
strip() only gets rid of whitespace from the ends of the string.

156
Q

What is unboxing?

A

The process of converting a wrapper class into its equivalent primitive

157
Q

What module is automatically made available to all other modules?

A

java.base

158
Q

True or false?
Abstract classes do not contain constructors.

A

False

159
Q

Which operator or statement can be used to combine case values within a switch statement?

A

A comma (,)

160
Q

What method in Thread is used to spawn an asynchronous task?

A

start()

161
Q

Name the four abstract base I/O stream classes.

A

InputStream, OutputStream, Reader, Writer

162
Q

What modifiers are implicitly applied to all interface methods without a body?

A

public and abstract

163
Q

Which characters in this statement are optional?
() -> { System.out.println(); return true; }

A

None. The parentheses are required when there aren’t any parameters. The braces are required because there are multiple statements.

164
Q

True or false? An abstract class must contain at least one abstract method.

A

False

164
Q

What method does DoubleBinaryOperator declare?

A

applyAsDouble()

165
Q

What is the return type of the java.io.Console readPassword() method?

A

char[]

166
Q

How is 123_456_789 printed by a CompactNumberFormat using the Short style?

A

123M

167
Q

When working with a number formatter, which symbol omits the digit if it does not exist?

A

#

168
Q

What source can create an infinite stream and takes two or three parameters?

A

Stream.iterate()

169
Q

True or false? The absolute path /zoo/data.txt may refer to a file or a directory.

A

True. Directories can have extensions in their names.

170
Q

What is the difference between a switch statement and switch expression?

A

A switch expression is a compact form of a switch statement that uses the arrow operator (->) and is capable of returning a value.

171
Q

How do you override a static method declared in a parent class?

A

Trick question! Only instance methods can be overridden.

172
Q

True or false? A class containing an abstract method must be marked abstract.

A

True

173
Q

Which looping statement guarantees that the body is executed at least once?

A

do {} while ()

174
Q

What access modifiers are permitted for enum constructors?

A

private

175
Q

What keyword in the module declaration is used to specify that calling code can use a package?

A

exports

176
Q

What do FIFO and LIFO stand for, and what Java Collections Framework interface are they associated with?

A

First-in/first-out and last-in/first-out. Associated with Deque.

177
Q

Fill in the blank: An instance of a class is called a(n) \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_.

A

Object

178
Q

Define the proper format for a locale String, and provide an example of one.

A

A locale is defined with a required lowercase language code and optional uppercase country code. They are separated by an underscore (_) if both are provided. An example is en_GB for English/Great Britain.

179
Q

Define serialization and deserialization.

A

Serialization is the process of converting an in-memory object to a byte stream, while deserialization is the reciprocal process.

180
Q

True or false? An if statement can have one or more associated else statements.

A

False. An if statement can have at most one associated else statement.

181
Q

What Collector would you use to get the number of elements in a stream?

A

Collectors.counting()

182
Q

Which elements are inserted by the compiler into a record declaration?

A

A constructor, accessor methods, and useful implementations of equals(), hashCode(), and toString()

183
Q

What is the first parameter type that preparedStatement.setNull() takes?

A

int. It represents the data type the null value will be stored in.

184
Q

What parameter type can fill in the blank for a PreparedStatement in the following code? ps.setInt(\_\_\_\_\_, 1);

A

int

185
Q

True or false? The ExecutorService method execute()takes a Callable instance.

A

False. The execute() method is for Runnable expressions only.

186
Q

What characters may a variable name end with?

A

A letter, number, currency symbol ($), or underscore (_)

187
Q

What access modifiers can be applied to a member inner class?

A

public, protected, package, and private

188
Q

When working with the MessageFormat class, what is the syntax for parameterized values in text strings?

A

A number, surrounded by braces {}, indicating the numeric order in which the parameter is provided

189
Q

What method do you need to implement in a Comparator, and how many parameters does it take?

A

compare(), and it takes two parameters

190
Q

Does this compile?
~~~
List<> l = new ArrayList<String>();
~~~</String>

A

No. The diamond operator must be on the right side.

191
Q

Rewrite this code using a method reference given
that a List is passed in: x -> x.isEmpty()

A

List::isEmpty

192
Q

What can you pass to the java command option to view the modules without running the program?

A

–list-modules

193
Q

Write a statement to create a two-dimensional primitive integer array initialized with the values [1 2] [3 4].

A

int[][] array = {{1,2}, {3,4}};

194
Q

What is the output of
(true ? false : 4 ? 5 : 6)?

A

The code does not compile.

195
Q

What is the difference between a checked and an unchecked exception?

A

A checked exception must be handled or declared in the method in which it is thrown, while an unchecked exception does not.

196
Q

What three methods taking a lambda as a parameter can you call directly on an ArrayList (without using a stream)?

A

forEach, removeIf, and replaceAll

197
Q

What parameter type does Collection forEach() take?

A

Consumer<T></T>

198
Q

What does the Path relativize() method do?

A

It constructs a relative path from one Path to another. It will throw an exception if one is absolute and the other is relative.

199
Q

What goes in the module declaration to specify that modules requiring your module can access specific other modules?

A

requires transitive

200
Q

Which of these have a return type of Stream: source, intermediate operation, terminal operation?

A

Source and intermediate operation

201
Q

Under what circumstances can the extends clause of the subclass of a sealed class be omitted?

A

Trick question! It cannot be omitted.

202
Q

What parameter on Stream.iterate() is optional?

A

Predicate for when to stop

203
Q

What modifiers are implicitly applied to all interface variables?

A

public, static, and final

204
Q

Which statement can be used to stop the current loop execution and immediately evaluate the loop condition?

A

continue

205
Q

Which of these can exist multiple times in a stream pipeline: source, intermediate operation, terminal operation?

A

Intermediate operation

206
Q

What are the three valid formats for comments?

A

//, /* */, and /** */

207
Q

What character is used in a text block to avoid a line break?

A

\

208
Q

What must be the same for two methods to be considered overloaded?

A

The method name

209
Q

What is it called when a single thread is perpetually denied access to a resource and hangs forever?

A

Starvation

210
Q

True or false? It is a good idea to catch Throwable in your code.

A

False. Error is a subtype of Throwable, and Error should not be caught.

211
Q

Which functional interface takes two parameters and has an accept() method?

A

BiConsumer

212
Q

What class is used to read text values based on a particular locale?

A

ResourceBundle

213
Q

Assuming T is a generic type, fill in the blank to make this code compile so that the method returns the same type it is passed in:
~~~
public static _________ returnObject(T o) { return o;}
~~~

A

<T> T
</T>

214
Q

When calling the String.format() method, what is the meaning of the symbols %05.2f?

A

They will display a floating-point number as five digits, with leading 0s, rounding to two digits after the decimal.

215
Q

What is the advantage of using Files.lines() over Files.readAllLines()?

A

Files.lines() reads the results via lazy evaluation as a stream.

216
Q

What represents a specific moment in time in GMT?

A

Instant

217
Q

True or false? The CyclicBarrier may trigger its barrier more than once.

A

True. Once the barrier has been reached, it may be used again.

218
Q

What is the purpose of a label statement?

A

It allows the program to break or continue for a specific loop within a group of nested loops.

219
Q

What object does a static synchronized method synchronize on?

A

The static object associated with the class

220
Q

What Java Collections Framework interface has an offerFirst() method?

A

Deque

221
Q

Fill in the blank: \_\_\_\_\_ is used to reliably check if two String values are the same.

A

equals()

222
Q

What does execute() return in JDBC?

A

Boolean

223
Q

What is the data type of z?
~~~
short x = 20; var z = x + 10
~~~

A

int

224
Q

When a thread calls interrupt() on another thread in the WAITING state, what is the new thread state?

A

RUNNABLE

225
Q

What is the result of extending a class marked final?

A

It does not compile.

226
Q

What is an unperformed side effect?

A

An expression that could modify a variable but is never executed because of a short-circuit operation

227
Q

What ScheduledExecutorService method allows a task to be completed at the same time every hour?

A

scheduleAtFixedRate()

228
Q

True or false? A case statement can use effectively final variables.

A

False. The variables must be compile-time constants. Unlike effectively final variables, a compile-time constant must be explicitly marked final and be initialized in the line where it is declared.

229
Q

What are the short and long forms of the java command option used to describe the details of a module?

A

-d and –describe-module

230
Q

What aspects of the following statement are invalid?
~~~
Consumer p = (p) -> {int var = 3; var++; return;};
~~~

A

The p variable is reused inside the lambda expression. The rest of the statement is valid.

231
Q

What modifier can be used to prevent a method parameter from being reassigned?

A

final

232
Q

Which functional interface converts from int to double?

A

IntToDoubleFunction

233
Q

What is the advantage of using a Buffered I/O class?

A

It often improves performance, especially when reading/writing large amounts of data.

234
Q

Which order does Java use when looking for matches in overloaded methods of: autoboxing, exact match, widening primitives, varargs?

A

exact match, widening primitives, autoboxing, varargs

235
Q

Name three ways to obtain a locale object.

A

Call a Locale constructor, use the Locale.Builder class, or use a built-in constant (such as Locale.CHINA)

236
Q

The bytecode for a class named Hello in the a.b.c package must appear in what directory structure?

A

The file Hello.class must be in the subdirectory a/b/c.

237
Q

List the order of class and instance initialization within a single class.

A

static variable declarations, static initializers, instance variable declarations, instance initializers, constructors

238
Q

True or false? In JDBC, autocommit mode is enabled automatically.

A

True

239
Q

What is the name of the file that must be in the root directory of your module?

A

module-info.java

240
Q

What is the syntax for creating an instance initializer?

A

{} with zero or more statements inside the block

241
Q

How do you create an Optional with the value “hi”?

A
Optional.of("hi")
242
Q

What does ObjectIntegerConsumer do?

A

Nothing. This is not part of the Java API.

243
Q

What is a stateful lambda expression?

A

A lambda expression whose results depend on any state that might change during the execution of a pipeline

244
Q

What are the default values for these instance variables:

String s; int num; boolean b; double d
A
s = null; 
num = 0; 
b = false; 
d = 0.0
245
Q

True or false? A case statement can use effectively final variables.

A

False. The variables must be compile-time constants. Unlike effectively final variables, a compile-time constant must be explicitly marked final and be initialized in the line where it is declared.

246
Q

Fill in the blank: An abstract method must be \_\_\_\_\_\_\_ in the first concrete subclass that inherits the method.

A

overridden

247
Q

When performing pattern matching, which operator is primarily used?

A

instanceof

248
Q

What is the syntax for creating an instance initializer?

A

{} with zero or more statements inside the block

249
Q

True or false? The this() statement can be used to call other constructors within the class but can only be used on the first line of a constructor.

A

True

250
Q

What are the short and long forms of the java command option used to describe the details of a module?

A

-d and --describe-module

251
Q

True or false? In JDBC, autocommit mode is enabled automatically.

A

True

252
Q

What exception is thrown if print() is called on a closed PrintStream?

A

Trick question! PrintStream does not throw an exception. Use checkError() to check for an error.

253
Q

When do you need to call the get() method on Provider when working with a service?

A

When calling the stream() method on ServiceLoader

254
Q

Name the data types supported by a switch statement.

A

int and Integer, byte and Byte, short and Short, char and Character, String, enum, and var

255
Q

True or false? A no-argument constructor may only be inserted by the compiler.

A

False. It can be explicitly declared.

256
Q

Which I/O stream class is best suited for reading a text file?

A

FileReader

257
Q

Which functional interface converts from int to double?

A

IntToDoubleFunction

258
Q

What is an unperformed side effect?

A

An expression that could modify a variable but is never executed because of a short-circuit operation

259
Q

Which Lock method returns immediately if the lock cannot be acquired?

A

tryLock()

260
Q

What method do you call on an IntStream instance to convert it to a Stream<Integer>?

A

mapToObj() or boxed()

261
Q

What String method converts \\n to the new line escape character?

A

translateEscapes()

262
Q

What does this code print?
~~~
String s = “hmm”;
System.out.println(s.substring(1, 2));
~~~

A

m. The substring starts with the character at index 1 (m) and ends with the character before index 2.

263
Q

What should the instance variables of an immutable class be declared?

A

final and private

264
Q

Which Collector creates a single String from a Stream?

A

joining()

265
Q

What class implements both List and Deque?

A

LinkedList

266
Q

Which order does Java use when looking for matches in overloaded methods of: autoboxing, exact match, widening primitives, varargs?

A

exact match, widening primitives, autoboxing, varargs

267
Q

True or false? The logical complement operator, -, flips the value of a boolean expression.

A

False. The logical complement operator is !.

268
Q

Name the methods in ObjectInputStream and ObjectOutputStream used to work with Object values.

A

readObject() and writeObject(Object obj)

269
Q

What option does the jlink command use for the directory it creates with the runtime image?

A

--output

270
Q

What ScheduledExecutorService method allows a task to be completed at the same time every hour?

A

scheduleAtFixedRate()

271
Q

What is the advantage of using a Buffered I/O class?

A

It often improves performance, especially when reading/writing large amounts of data.

272
Q

How do you create an Optional with the value “hi”?

A

Optional.of("hi")

273
Q

What is a final static variable commonly referred to as?

A

A constant

274
Q

When is a return statement not required in a method?

A

When the return type is void

275
Q

True or false? A switch expression is always required to have a default statement when assigning the result to an int value.

A

True, since handling every possible int value would be untenable.

276
Q

What is the parent class for all exception types in Java?

A

Throwable

277
Q

What does ObjectIntegerConsumer do?

A

Nothing. This is not part of the Java API.

278
Q

When reading byte values from an InputStream, what is the proper way to detect the end of the stream?

A

A -1 value will be returned.

279
Q

What is a stateful lambda expression?

A

A lambda expression whose results depend on any state that might change during the execution of a pipeline

280
Q

What aspects of the following statement are invalid?

Consumer p = (p) -> {int var = 3; var++; return;};
A

The p variable is reused inside the lambda expression. The rest of the statement is valid.

281
Q

True or false? The NIO.2 Files class includes a method, newBufferedInputStream(), that reads the contents of a file into an I/O stream.

A

False. It does contain a newBufferedReader() method, though.