Finals Mock Exam Review
(Questions & Solutions)
2025
©2025
, Question 1:
In Java, when using the `volatile` keyword, which property is primarily
guaranteed?
- A. Atomicity of compound actions
- B. Visibility of changes across threads
- C. Immunity from deadlocks
- D. Synchronization of method execution
ANS: B. Visibility of changes across threads
Rationale: The `volatile` keyword in Java ensures that a variable’s
changes are visible to all threads immediately. It does not provide
atomicity for compound operations (for which synchronization is
required) nor does it guarantee mutual exclusion or deadlock avoidance.
---
Question 2:
A developer uses an `ExecutorService` to manage concurrent tasks.
Which method call should be used to initiate an orderly shutdown where
previously submitted tasks are executed, but no new tasks are accepted?
- A. shutdownNow()
- B. halt()
- C. terminate()
- D. shutdown()
ANS: D. shutdown()
Rationale: The `shutdown()` method initiates an orderly shutdown by
ceasing acceptance of new tasks while allowing already submitted tasks
to complete. In contrast, `shutdownNow()` attempts to halt all executing
tasks abruptly.
---
©2025
, Question 3:
Which feature introduced in Java 8 allows for concise expression of
single-method interfaces and enables functional programming
techniques?
- A. Annotations
- B. Lambda expressions
- C. Generics
- D. Enumeration
ANS: B. Lambda expressions
Rationale: Lambda expressions, introduced in Java 8, allow you to
implement functional interfaces concisely and enable operations on
streams, greatly simplifying the coding of function objects.
---
Question 4:
In Java generics, what concept explains why generic type information is
not preserved at runtime?
- A. Type encapsulation
- B. Type induction
- C. Type erasure
- D. Type reflection
ANS: C. Type erasure
Rationale: Type erasure is the process by which Java’s compiler
removes generic type information during compilation. This means that
generic types are replaced with their upper bounds (often Object), and as
a result, the runtime does not retain explicit information about generic
parameters.
---
Question 5:
©2025
, Considering exception handling improvements in Java 7 and later, which
of the following constructs automatically closes resources when they are
no longer needed?
- A. try-catch-finally
- B. try-with-resources
- C. synchronized blocks
- D. catch-only statements
ANS: B. try-with-resources
Rationale: The try-with-resources statement ensures that resources
opened in the try block (which implement `AutoCloseable`) are
automatically closed at the end of the statement, even if exceptions
occur.
---
Question 6:
Which Java feature, introduced in Java 9, is designed to improve
modularity by allowing developers to define modules and control their
dependencies explicitly?
- A. Lambda expressions
- B. The Java Module System (Project Jigsaw)
- C. Enhanced for-loop
- D. Reflection API Extensions
ANS: B. The Java Module System (Project Jigsaw)
Rationale: The Java Module System, introduced in Java 9, provides a
framework for modularizing code, specifying module dependencies, and
encapsulating packages, thereby improving maintainability and security.
---
Question 7:
Which garbage collector, introduced in later versions of Java, is designed
for low pause times and high throughput by dividing the heap into
©2025