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
Which Lock method will wait indefinitely for a lock if it cannot be acquired?
lock()
26
Which of the following requires an explicit cast to be assigned to a short value? int, byte, float, bit
int and float require an explicit cast, while byte does not. Note that bit is not a primitive type in Java.
27
Given an interface Fly with no abstract methods, how would you create an instance of an anonymous class that implements it?
new Fly() {}
28
Which of these are required in a stream pipeline: source, intermediate operation, terminal operation?
Source and terminal operation
29
Given an outer class Rooster and its inner class Wattle, how would you create an instance of Wattle within an instance method of Rooster?
new Wattle()
30
What type of module is on the classpath?
Unnamed module
31
True or false? **All operators are evaluated from left to right.**
**False**. The **assignment operator** is **evaluated from right to left.**
32
True or false? Overloaded methods have the same method signatures.
False. The parameter lists must be different.
33
**True or false? A static method is allowed to reference an instance variable.**
False (except through a reference to a class instance)
34
**Which Collections method provides a thread-safe version of an existing Map?**
Collections.synchronizedMap()
35
Either of which two complementary operators can be used to test if x is greater than or equal to y?
>= or <
36
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)); ```
1 1
37
If an interface is annotated with @FunctionalInterface, what three common abstract methods can the interface declare in addition to the custom single abstract method?
toString(), hashCode(), and equals()
38
True or false? A vararg that takes a list of int values can be written within a method declaration using int... or int[].
False. Only ... can be used to declare a vararg.
39
True or false? If a text block ends with gerbil""", a new line is added.
False
40
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.
True
41
On what class do you call a method to create a CallableStatement?
**Connection**
42
**True or false?** All **method references** can be rewritten as a **lambda**.
**True**. A **method reference** is a short form of a **lambda**.
43
**var** can be used as the type for which of the following: **instance variable, static variable, local variable, constructor parameter, method parameter?**
**var can be used only as a local variable.**
44
**Which functional interface takes two parameters and returns a boolean?**
**BiPredicate**
45
**Without using any variables, what could you write to negate the value `-5`?**
``` -(-5) ```
46
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.
True
47
**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.**
**concrete**
48
**What does JAR stand for?**
**Java archive**
49
True or false? A class must implement Closeable to be used in a try-with-resources statement.
False. The class must implement AutoCloseable.
50
Fill in the blank with explicit or implicit: Accessing an object by one of its supertypes can be done with an `_________` cast.
implicit
51
What parameter type can fill in the blank for a CallableStatement for the following? `cs.setInt(_____, 1);`
int or String
52
Which functional interface is declared with two generics and has an apply() method?
Function
53
What will equals() return when comparing a List and Set with the same elements?
false
54
True or false? Unary operators have the highest order of precedence.
True
55
What is the name of the method that creates Path objects in the Paths class?
**Paths.get()**
56
How do you create an Optional without a value?
Optional.empty()
57
True or false? In a JDBC URL, the port is required.
False
58
Fill in the blank to make this code compile: ``` List<______ Number> listOfNumbers = new ArrayList(); ```
? super (this is a lower bound)
59
How many operators in Java take three values?
Just one, the ternary operator
60
Name a terminal operation that can always terminate on an infinite stream.
findAny() or findFirst()
61
What methods can remove whitespace from the end of a String ?
trim(), strip(), stripTrailing()
62
What symbol is used to represent a bind variable in a PreparedStatement?
Question mark (?)
63
Where can a call to super() or this() occur within a constructor?
As the first statement of the constructor
64
What character is used to escape values in a date formatter?
A single quote (')
65
What is it called when two threads are stuck forever but appear to be active and making progress?
Livelock
66
Which data types are supported as the target of an if statement’s conditional clause?
Only boolean
67
When passing an object to a method, how can the method be written to change the object that the caller references?
It cannot. A method cannot directly change the reference the caller passes so that the caller sees the change.
68
What **functional interface** does Java provide that declares a single method that returns a **boolean**?
**Predicate**
69
What Map method gives you all the keys?
keySet()
70
Write a for-each loop that iterates over an int[] data in reverse.
Trick question. For-each loops cannot be used to iterate over a data structure in reverse order.
71
Fill in the blank: An instance initializer can access `_________` variables declared in the class.
static and instance
72
True or false? If an automatic module name is not specified, Java keeps dots in the generated name.
True
73
Which keyword(s) can be used to access a member declared within the class?
this
74
When calling a String.format() method, what is the meaning of the symbols %n and %d?
The %n symbol is used to indicate a new line, while the %d symbol is used for integer values.
75
Name the **four rules** an **overridden method** must follow.
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.**
76
What is the purpose of using a try-with-resources statement?
Ensures that resources like files and database connections are properly closed at the conclusion of the try section
77
What does the Path resolve() method do?
It joins two paths. If the input argument to the method is an absolute path, then that value is returned.
78
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.
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.
79
**What is the most common signature of a main() method?**
``` public static void main(String[] args) ```
80
**What does the following expression return?** ``` new StringBuilder("Hello").equals("Hello") ```
**false, as they are not the same object type**
81
When converting from an IntStream to a CharStream, what mapping method do you call?
Trick question. There is no CharStream.
82
Does **Duration** or **Period** support hours?
**Duration**
83
Which option should you use when calling Files.copy() if you want to overwrite the target file if it already exists?
``` StandardCopyOption.REPLACE_EXISTING ```
84
What is the difference between the & and && operators when applied to boolean expressions?
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.
85
True or false? **Queue.of()** returns an immutable list.
**False**. This method does not exist.
86
True or false? Creating an instance variable with package access allows a subclass to access it under certain circumstances.
True, if the subclass is in the same package
87
What method should you call for OUT parameters when working with a CallableStatement?
``` registerOutParameter() ```
88
What functional interfaces have andThen() as a helper method?
Consumer and Function
89
Besides letters and numbers, what symbols are permitted to be used in identifiers?
_ and currency symbols
90
How many loop variables can a traditional for loop have?
There is no specified limit.
91
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?
``` Cat.super.meow() ```
92
Do lower or upper bounds allow you to add elements to a list?
Lower bounds do because they specify the class that all types must be above using super.
93
True or false? Garbage collection is guaranteed to run at a fixed schedule and when the JVM is low on memory.
False. The JVM controls when garbage collection is run, and when it occurs is not guaranteed.
94
Which keyword(s) can be used to access a member of the parent class?
super or this
95
True or false? If one lambda parameter uses var as the type, all other parameters in that lambda must as well.
True. The type format must be consistent within a lambda.
96
True or false? An anonymous class can only be declared as extending one class or implementing one interface.
True
97
What are acceptable data types on the right-hand side of a for-each loop?
A built-in array or class that implements java.lang.Iterable
98
What String method returns the position of a value in a String?
indexOf()
99
True or false? A class can implement two interfaces that have the same method signature.
True, provided the methods are compatible using the rules for overridden methods
100
What is a compile-time constant variable?
A variable that is marked final and initialized with a literal value when it is declared
101
What is the purpose of sealing an interface?
To restrict which interfaces can extend the interface or classes that can implement the interface
102
Rank these operators from highest operator precedence to lowest: + (addition) * ! == ++ ||
`++ ` `!` `*` `+` `==` `||`
103
True or false? An instance method is allowed to reference a static variable.
True
104
True or false? indent(x) can take positive or negative integers as a parameter.
True. Negative integers will remove leading whitespace.
105
Besides itself, which numeric primitive types can be implicitly cast to double?
byte, short, int, float, long
106
Which sorts first: letters or numbers?
Numbers
107
What Collector would you use to return the type `Map>`?
Collectors.groupingBy()
108
Which operator can be used to avoid cast exceptions at runtime?
instanceof
109
True or false? Records are both immutable and encapsulated.
True
110
A sealed class most closely resembles what other top-level type?
An enum
111
What Java Collections Framework interface requires unique elements?
Set
112
A thread has started but is waiting for a lock to become available. What state is it in?
BLOCKED
113
True or false? A vararg that takes a list of int values can be written within a method declaration using int... or int[].
False. Only ... can be used to declare a vararg.
113
True or false? Calling rs.getString(1) before calling rs.next() throws a SQLException on a ResultSet.
True
113
What return types are covariant with void?
Only void.
114
How are suppressed exceptions created?
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
When closing a Statement, what other resources get closed?
ResultSet, if there is one opened by the statement
116
What is the name of the parameter that can enable or disable the helpful NullPointerException feature?
ShowCodeDetailsInExceptionMessages
117
True or false? If the database field is a **String**, calling **resultSet.getObject()** returns an object that can be cast to a **String**.
**True**
118
If you have a large file, which NIO.2 method should you use to read the lines of the file and why?
Files.lines() since the data is read using lazy evaluation
119
What primitive has exactly one predefined functional interface?
Boolean with the functional interface BooleanSupplier
120
Which ExecutorService method will synchronously wait for an entire Collection of tasks to complete?
invokeAll()
121
What is the most restrictive access modifier?
private
122
Name the four types of nested classes.
Inner class, static nested class, local class, and anonymous class
123
When autocommit mode is turned off, what method saves the data to the database?
commit()
124
Write a static import to import the static LENGTH variable of a.b.C.
import static a.b.C.LENGTH; or import static a.b.C.*;
125
True or false? Pattern matching allows you to avoid performing a separate cast operator.
True
126
In what order should a Connection, PreparedStatement, and ResultSet be closed?
ResultSet PreparedStatement Connection
127
In a top-down migration of three modules, how many modules are on the module path after migrating the first module?
Three
128
True or false? Nested loops can only be used with for loops.
False. Other types of loops, such as while and do while, can be used as nested loops.
129
Which NIO.2 method returns the index of the first differing position of the contents of two files?
Files.mismatch()
130
Which modifier is used to indicate a field should not be serialized?
transient
131
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.
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
What wrapper class goes with int?
Integer
133
Which two static methods create an infinite stream of int primitives?
IntStream.generate() and IntStream.iterate()
134
What is the value of 10 % 3 and 10 / 3?
1 and 3
135
In a bottom-up migration of three modules, how many modules are on the module path after migrating the first module?
One
136
True or false? **Math.round()** returns the same primitive type it is passed.
**False**. It returns **int/long** when passed **float/double**, respectively.
137
True or false? The **NIO.2 Files class** includes an **overloaded copy() method** that can write a file to an **I/O stream.**
True
138
How many objects are created in String[] s = new String[5];?
Just **one**. **The references are all set to null by default.**
139
List all the access modifiers.
**public**, **private**, **protected**, and **package**. The first three are keywords. The last is specified with the lack of a keyword.
140
What does the Collection removeIf() operation do, and what parameter does it take?
The removeIf() operation takes a Predicate and removes all elements from a Collection for which the Predicate evaluates to true.
141
Which **java.io.File** method is used to **create a single directory**?
**mkdir()**
142
In a **service**, what is the name of the artifact that implements an interface?
**Service provider**
143
What are the names of the options available to set a **classpath** in a **java** or **javac** command?
**-cp, -classpath, and --class-path**
144
What is **operator precedence**?
Some operators have higher precedence and therefore are executed before other operators when reading from left to right.
145
What is **flow scoping**?
Flow scoping means the variable is only in scope when the compiler can definitively determine its type.
146
What type of module is on the module path but does not have a module-info.java file?
Automatic module
147
Which **operator** increments a value and returns the original value?
The **post-increment** operator: variable**++**
148
What is wrong with public void method(String... s, int... b) {}?
A **vararg** parameter **must be the last parameter in a parameter list**, and **only one is allowed per method.**
149
What is printed if you fail to catch an **unchecked exception**?
A stack trace
150
What method can you call on **IntStream** to get the **sum** and **average**?
**summaryStatistics()**
151
True or false? If a resource bundle for the requested locale is not available, the default locale may be used.
True
152
Which List class creates a new underlying instance of the class anytime it is modified?
CopyOnWriteArrayList
153
Which **functional interface** takes **one parameter** and returns a **(possibly) different Object type**?
**Function**
154
What **terminal operation** has **three overloaded signatures** where one returns an Optional and two do not?
**reduce()**
155
True or false? **stripIndent()** can get rid of the extra space characters in "happy birthday".
False. strip() only gets rid of whitespace from the ends of the string.
156
What is **unboxing**?
The process of **converting a *wrapper class* into its equivalent *primitive***
157
What module is automatically made available to all other modules?
java.base
158
True or false? Abstract classes do not contain constructors.
False
159
Which operator or statement can be used to combine case values within a switch statement?
A comma (,)
160
What method in **Thread** is used to spawn an asynchronous task?
**start()**
161
Name the four abstract base I/O stream classes.
InputStream, OutputStream, Reader, Writer
162
What modifiers are implicitly applied to all interface methods without a body?
public and abstract
163
Which characters in this statement are optional? () -> { System.out.println(); return true; }
None. The parentheses are required when there aren’t any parameters. The braces are required because there are multiple statements.
164
True or false? An abstract class must contain at least one abstract method.
False
164
What method does DoubleBinaryOperator declare?
applyAsDouble()
165
What is the return type of the java.io.Console readPassword() method?
char[]
166
How is 123\_456\_789 printed by a CompactNumberFormat using the Short style?
123M
167
When working with a number formatter, which symbol omits the digit if it does not exist?
#
168
What source can create an infinite stream and takes two or three parameters?
Stream.iterate()
169
True or false? The absolute path /zoo/data.txt may refer to a file or a directory.
True. Directories can have extensions in their names.
170
What is the difference between a switch statement and switch expression?
A switch expression is a compact form of a switch statement that uses the arrow operator (->) and is capable of returning a value.
171
How do you override a static method declared in a parent class?
Trick question! Only instance methods can be overridden.
172
True or false? A class containing an abstract method must be marked abstract.
True
173
Which looping statement guarantees that the body is executed at least once?
do {} while ()
174
What access modifiers are permitted for enum constructors?
private
175
What keyword in the module declaration is used to specify that calling code can use a package?
exports
176
What do FIFO and LIFO stand for, and what Java Collections Framework interface are they associated with?
First-in/first-out and last-in/first-out. Associated with Deque.
177
Fill in the blank: An instance of a class is called a(n) `_________________`.
Object
178
Define the proper format for a locale String, and provide an example of one.
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
Define serialization and deserialization.
Serialization is the process of converting an in-memory object to a byte stream, while deserialization is the reciprocal process.
180
True or false? An if statement can have one or more associated else statements.
False. An if statement can have at most one associated else statement.
181
What Collector would you use to get the number of elements in a stream?
Collectors.counting()
182
Which elements are inserted by the compiler into a record declaration?
A constructor, accessor methods, and useful implementations of equals(), hashCode(), and toString()
183
What is the first parameter type that preparedStatement.setNull() takes?
int. It represents the data type the null value will be stored in.
184
What parameter type can fill in the blank for a PreparedStatement in the following code? ps.setInt(`_____`, 1);
int
185
True or false? The ExecutorService method execute()takes a Callable instance.
False. The execute() method is for Runnable expressions only.
186
What characters may a variable name end with?
A letter, number, currency symbol ($), or underscore (_)
187
What access modifiers can be applied to a member inner class?
public, protected, package, and private
188
When working with the MessageFormat class, what is the syntax for parameterized values in text strings?
A number, surrounded by braces {}, indicating the numeric order in which the parameter is provided
189
What method do you need to implement in a Comparator, and how many parameters does it take?
compare(), and it takes two parameters
190
Does this compile? ``` List<> l = new ArrayList(); ```
No. The diamond operator must be on the right side.
191
Rewrite this code using a method reference given that a List is passed in: x -> x.isEmpty()
List::isEmpty
192
What can you pass to the java command option to view the modules without running the program?
--list-modules
193
Write a statement to create a two-dimensional primitive integer array initialized with the values `[1 2] [3 4]`.
`int[][] array = {{1,2}, {3,4}};`
194
What is the output of `(true ? false : 4 ? 5 : 6)`?
The code does not compile.
195
What is the difference between a checked and an unchecked exception?
A checked exception must be handled or declared in the method in which it is thrown, while an unchecked exception does not.
196
What three methods taking a lambda as a parameter can you call directly on an ArrayList (without using a stream)?
forEach, removeIf, and replaceAll
197
What parameter type does Collection forEach() take?
Consumer
198
What does the Path relativize() method do?
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
What goes in the module declaration to specify that modules requiring your module can access specific other modules?
requires transitive
200
Which of these have a return type of Stream: source, intermediate operation, terminal operation?
Source and intermediate operation
201
Under what circumstances can the extends clause of the subclass of a sealed class be omitted?
Trick question! It cannot be omitted.
202
What parameter on Stream.iterate() is optional?
Predicate for when to stop
203
What modifiers are implicitly applied to all interface variables?
public, static, and final
204
Which statement can be used to stop the current loop execution and immediately evaluate the loop condition?
continue
205
Which of these can exist multiple times in a stream pipeline: source, intermediate operation, terminal operation?
Intermediate operation
206
What are the three valid formats for comments?
`//, /* */, and /** */`
207
What character is used in a text block to avoid a line break?
\
208
What must be the same for two methods to be considered overloaded?
The method name
209
What is it called when a single thread is perpetually denied access to a resource and hangs forever?
Starvation
210
True or false? It is a good idea to catch Throwable in your code.
False. Error is a subtype of Throwable, and Error should not be caught.
211
Which functional interface takes two parameters and has an accept() method?
BiConsumer
212
What class is used to read text values based on a particular locale?
ResourceBundle
213
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;} ```
T
214
When calling the String.format() method, what is the meaning of the symbols %05.2f?
They will display a floating-point number as five digits, with leading 0s, rounding to two digits after the decimal.
215
What is the advantage of using Files.lines() over Files.readAllLines()?
Files.lines() reads the results via lazy evaluation as a stream.
216
What represents a specific moment in time in GMT?
Instant
217
True or false? The CyclicBarrier may trigger its barrier more than once.
True. Once the barrier has been reached, it may be used again.
218
What is the purpose of a label statement?
It allows the program to break or continue for a specific loop within a group of nested loops.
219
What object does a static synchronized method synchronize on?
The static object associated with the class
220
What Java Collections Framework interface has an offerFirst() method?
Deque
221
Fill in the blank: `_____` is used to reliably check if two String values are the same.
equals()
222
What does execute() return in JDBC?
Boolean
223
What is the data type of z? ``` short x = 20; var z = x + 10 ```
int
224
When a thread calls interrupt() on another thread in the WAITING state, what is the new thread state?
RUNNABLE
225
What is the result of extending a class marked final?
It does not compile.
226
What is an unperformed side effect?
An expression that could modify a variable but is never executed because of a short-circuit operation
227
What ScheduledExecutorService method allows a task to be completed at the same time every hour?
scheduleAtFixedRate()
228
True or false? A case statement can use effectively final variables.
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
What are the short and long forms of the java command option used to describe the details of a module?
-d and --describe-module
230
What aspects of the following statement are invalid? ``` Consumer p = (p) -> {int var = 3; var++; return;}; ```
The p variable is reused inside the lambda expression. The rest of the statement is valid.
231
What modifier can be used to prevent a method parameter from being reassigned?
final
232
Which functional interface converts from int to double?
IntToDoubleFunction
233
What is the advantage of using a Buffered I/O class?
It often improves performance, especially when reading/writing large amounts of data.
234
Which order does Java use when looking for matches in overloaded methods of: autoboxing, exact match, widening primitives, varargs?
exact match, widening primitives, autoboxing, varargs
235
Name three ways to obtain a locale object.
Call a Locale constructor, use the Locale.Builder class, or use a built-in constant (such as Locale.CHINA)
236
The bytecode for a class named Hello in the a.b.c package must appear in what directory structure?
The file Hello.class must be in the subdirectory a/b/c.
237
List the order of class and instance initialization within a single class.
static variable declarations, static initializers, instance variable declarations, instance initializers, constructors
238
True or false? In JDBC, autocommit mode is enabled automatically.
True
239
What is the name of the file that must be in the root directory of your module?
module-info.java
240
What is the syntax for creating an instance initializer?
{} with zero or more statements inside the block
241
How do you create an Optional with the value "hi"?
``` Optional.of("hi") ```
242
What does ObjectIntegerConsumer do?
Nothing. This is not part of the Java API.
243
What is a stateful lambda expression?
A lambda expression whose results depend on any state that might change during the execution of a pipeline
244
What are the default values for these instance variables: ``` String s; int num; boolean b; double d ```
``` s = null; num = 0; b = false; d = 0.0 ```
245
True or false? A case statement can use effectively final variables.
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
Fill in the blank: An abstract method must be `_______` in the first concrete subclass that inherits the method.
overridden
247
When performing pattern matching, which operator is primarily used?
instanceof
248
What is the syntax for creating an instance initializer?
{} with zero or more statements inside the block
249
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.
True
250
**What are the short and long forms of the java command option used to describe the details of a module?**
`-d and --describe-module`
251
**True or false? In JDBC, autocommit mode is enabled automatically.**
True
252
**What exception is thrown if print() is called on a closed PrintStream?**
Trick question! PrintStream does not throw an exception. Use checkError() to check for an error.
253
**When do you need to call the get() method on Provider when working with a service?**
When calling the stream() method on ServiceLoader
254
**Name the data types supported by a switch statement.**
int and Integer, byte and Byte, short and Short, char and Character, String, enum, and var
255
**True or false? A no-argument constructor may only be inserted by the compiler.**
False. It can be explicitly declared.
256
**Which I/O stream class is best suited for reading a text file?**
**FileReader**
257
**Which functional interface converts from int to double?**
**IntToDoubleFunction**
258
**What is an unperformed side effect?**
**An expression that could modify a variable but is never executed because of a short-circuit operation**
259
**Which Lock method returns immediately if the lock cannot be acquired?**
**tryLock()**
260
**What method do you call on an IntStream instance to convert it to a Stream``?**
**mapToObj() or boxed()**
261
**What String method converts `\\n` to the new line escape character?**
**translateEscapes()**
262
**What does this code print?** ``` String s = "hmm"; System.out.println(s.substring(1, 2)); ```
m. The substring starts with the character at index 1 (m) and ends with the character before index 2.
263
**What should the instance variables of an immutable class be declared?**
**final and private**
264
**Which Collector creates a single String from a Stream?**
**joining()**
265
**What class implements both List and Deque?**
**LinkedList**
266
**Which order does Java use when looking for matches in overloaded methods of: autoboxing, exact match, widening primitives, varargs?**
**exact match, widening primitives, autoboxing, varargs**
267
**True or false? The logical complement operator, `-`, flips the value of a boolean expression.**
**False. The logical complement operator is !.**
268
**Name the methods in ObjectInputStream and ObjectOutputStream used to work with Object values.**
**readObject() and writeObject(Object obj)**
269
**What option does the jlink command use for the directory it creates with the runtime image?**
**`--output`**
270
**What ScheduledExecutorService method allows a task to be completed at the same time every hour?**
**scheduleAtFixedRate()**
271
**What is the advantage of using a Buffered I/O class?**
**It often improves performance, especially when reading/writing large amounts of data.**
272
**How do you create an Optional with the value "hi"?**
**`Optional.of("hi")`**
273
**What is a final static variable commonly referred to as?**
**A constant**
274
**When is a return statement not required in a method?**
**When the return type is void**
275
**True or false? A switch expression is always required to have a default statement when assigning the result to an int value.**
**True, since handling every possible int value would be untenable.**
276
**What is the parent class for all exception types in Java?**
**Throwable**
277
**What does ObjectIntegerConsumer do?**
**Nothing. This is not part of the Java API.**
278
**When reading byte values from an InputStream, what is the proper way to detect the end of the stream?**
**A -1 value will be returned.**
279
**What is a stateful lambda expression?**
**A lambda expression whose results depend on any state that might change during the execution of a pipeline**
280
**What aspects of the following statement are invalid?** ``` Consumer p = (p) -> {int var = 3; var++; return;}; ```
**The p variable is reused inside the lambda expression. The rest of the statement is valid.**
281
**True or false? The NIO.2 Files class includes a method, newBufferedInputStream(), that reads the contents of a file into an I/O stream.**
**False. It does contain a newBufferedReader() method, though.**