PRACTICE • LEARN • GROW
Module 12: File Handling & Advanced Topics - Final Quiz MCQs
Solve topic-wise placement questions and improve your skills.
Module 12: File Handling & Advanced Topics - Final Quiz Progress
0 of 12 completed
0%
Topic Track
You are viewing MCQs in preview mode. Log in to select options, submit answers, and track your progress.
Log In to Answer
1
What is the primary architectural advantage of Java 7's
try-with-resources statement?
A.
It speeds up disk drive hardware
B.
It automatically closes any resource implementing
AutoCloseable at the end of the block, even if exceptions are thrown, eliminating resource leaks
C.
It suppresses all compilation errors
D.
It converts text files to binary format automatically
Explanation & Key
Correct Answer:
2
What is the compile-time benefit of Java Generics in the following snippet?
List list = new ArrayList<>();
list.add("ReadyToGo");
// list.add(100); // What happens here?
A.
The compiler catches adding an Integer at compile time, eliminating runtime ClassCastException errors and removing the need for explicit type casting
B.
Generics make the list run 10x faster in hardware
C.
Generics encrypt the elements in memory
D.
Generics allow primitive types directly without wrapper classes
Explanation & Key
Correct Answer:
3
Which Lambda expression correctly implements this functional interface?
interface MathOp {
int operate(int a, int b);
}
A.
MathOp op = (a, b) -> a + b;
B.
MathOp op = int (a, b) => a + b;
C.
MathOp op = function(a, b) { return a + b; };
D.
MathOp op = (a, b) : a + b;
Explanation & Key
Correct Answer:
4
What are the three essential stages of a Java 8 Stream pipeline as visualized in Figure 12.1?
A.
Allocation -> Compilation -> Execution
B.
Source -> Intermediate Operations (lazy) -> Terminal Operation (eager)
C.
Input -> Sorting -> Output
D.
Try -> Catch -> Finally
Explanation & Key
Correct Answer:
5
What is the primary purpose of Java packages (e.g.,
com.readytogo.service)?
A.
To compress classes into .zip files
B.
To prevent naming collisions between classes and provide modular namespace encapsulation and access protection
C.
To encrypt source code against reverse engineering
D.
To control CPU thread scheduling
Explanation & Key
Correct Answer:
6
Why is wrapping a
FileReader in a BufferedReader recommended when reading text files?
A.
FileReader is deprecated in Java 17
B.
BufferedReader buffers 8192 characters in memory, avoiding costly physical disk reads for every individual character and providing readLine()
C.
FileReader only works with binary image files
D.
BufferedReader automatically translates languages
Explanation & Key
Correct Answer:
7
What is the requirement for an interface to be declared with
@FunctionalInterface?
A.
It must contain at least 5 methods
B.
It must have exactly ONE abstract method (Single Abstract Method - SAM), though it may contain default and static methods
C.
It cannot have any default methods
D.
It must be declared static
Explanation & Key
Correct Answer:
8
What is printed by the following Stream pipeline?
List names = List.of("Anna", "Bob", "Alex", "Brian");
long count = names.stream()
.filter(n -> n.startsWith("A"))
.map(String::toUpperCase)
.count();
System.out.println(count);
A.
4
B.
2
C.
1
D.
0
Explanation & Key
Correct Answer:
9
What will happen if you attempt to mutate a local variable that is referenced inside a lambda expression?
int factor = 10;
List nums = List.of(1, 2, 3);
nums.forEach(n -> System.out.print((n * factor) + " "));
// factor = 20; // What happens if this line is uncommented?
A.
It compiles and prints 20 40 60
B.
Compile-time error: local variables referenced from a lambda expression must be final or effectively final
C.
Runtime ConcurrentModificationException
D.
It compiles and prints 10 20 30
Explanation & Key
Correct Answer:
10
What will be printed by the following Stream snippet?
List items = List.of("apple", "banana", "cherry");
items.stream().filter(s -> {
System.out.print(s + " ");
return s.startsWith("b");
});
System.out.print("End");
A.
apple banana cherry End
B.
End
C.
banana End
D.
apple End
Explanation & Key
Correct Answer:
11
In Java Generics, what does the PECS guideline stand for, and when should you use
extends T> versus super T>?
A.
Parameter Extends, Class Super
B.
Producer Extends, Consumer Super: use extends T> when reading/producing items from a collection, and super T> when writing/consuming items into a collection
C.
Private Extends, Constant Super
D.
Primitive Extends, Cast Super
Explanation & Key
Correct Answer:
12
What is printed by the following code utilizing Java 8's Optional API?
Optional opt = Optional.ofNullable(null);
String result = opt.orElse("Default");
System.out.println(result);
A.
Throws NullPointerException
B.
Default
C.
null
D.
Optional.empty
Explanation & Key
Correct Answer:
Question Palette
Answered
Current
Not Attempted
Wrong