Solutions Latest Update 2026/2027 | Verified Questions and
Answers, Complete Examination - 188 Questions
This midterm examination assesses advanced proficiency in Java programming, covering core language features,
object-oriented design, concurrency, collections, exception handling, functional programming, and JVM internals.
It emphasizes analytical reasoning and the application of best practices in complex problem-solving scenarios. It
contains 188 multiple-choice questions, each with four distractors and a fully worked rationale that explains why
the keyed answer is correct. Questions are organized into clearly labelled sections that mirror the major content
areas of the course. Targeted learning outcomes include: Analyze and predict the behavior of complex Java code
involving inheritance, generics, and lambda expressions.; Evaluate and apply concurrency control mechanisms to
ensure thread safety and avoid deadlocks.; Design robust exception handling strategies that adhere to Java best
practices.; Interpret and debug JVM memory and performance issues using knowledge of garbage collection and
class loading.. Every item has been reviewed for clinical accuracy, current guidelines, and clarity so that students
can study with confidence and self-correct as they work through the bank. Use it as a high-yield review
immediately before the exam, or as a structured practice tool during the unit - the rationales double as concise
teaching notes. The recommended writing time is 3 hours, with a passing score of 70%. Aligned with Compliant
with ACM/IEEE Computer Science Curricula 2023 and ABET computing accreditation standards. standards and
reflects the question style commonly seen on accredited program examinations. Students consistently achieving
Section 1: General (Questions 1-188)
1 Given the following code snippet, what is the output when the
program is executed?
A) Base.m1()
Derived.m2()
B) Derived.m1()
Derived.m2()
C) Base.m1()
Base.m2()
D) Compilation error
Answer: A
Rationale: The method m1() is static and is invoked on the reference
type Base, so Base.m1() runs. m2() is an instance method overridden
in Derived, so dynamic dispatch calls Derived.m2(). Hence, A is
correct.
, 2 Which of the following best describes the behavior of a method
reference to an instance method of an arbitrary object of a particular
type?
A) It is equivalent to a lambda expression that captures the object as
a free variable.
B) It requires the object to be effectively final and captured from the
enclosing scope.
C) It is compiled to an invokedynamic call that uses the first
functional interface argument as the receiver.
D) It always creates a new object for each invocation.
Answer: C
Rationale: A method reference of the form Class::instanceMethod is
treated as a lambda where the first parameter becomes the receiver.
The JVM uses invokedynamic to adapt the method reference to the
functional interface. It does not capture an object; the receiver is
supplied as an argument.
3 Consider the following code. What is the result of executing this
method?
A) It prints 'Found' if the list contains any string starting with 'A'.
B) It prints 'Found' if all strings start with 'A'.
C) It throws a ConcurrentModificationException.
D) It prints 'Found' if the first string starts with 'A'.
Answer: A
Rationale: The stream's anyMatch() short-circuits and returns true if
any element satisfies the predicate. The method prints 'Found' if at
least one string starts with 'A'. The code does not modify the list, so no
ConcurrentModificationException is thrown.
4 Which of the following is a guaranteed benefit of using the
Fork/Join framework over a custom thread pool for recursive tasks?
A) It automatically uses a fixed number of threads equal to the
number of CPU cores.
,B) It implements work-stealing, which balances load among worker
threads.
C) It eliminates the need for synchronization on shared data.
D) It guarantees that tasks will complete in the order they were
submitted.
Answer: B
Rationale: The Fork/Join framework uses a work-stealing algorithm
where idle threads steal tasks from busy threads, improving load
balancing. It does not guarantee ordering or eliminate synchronization
needs; the pool size is typically based on parallelism, not fixed to
cores.
5 Which of the following best describes the purpose of the new
`SequencedCollection` interface introduced in Java 21?
A) It provides a uniform API for collections that maintain a defined
encounter order.
B) It replaces all existing list and set implementations.
C) It adds support for parallel stream processing.
D) It is a new concurrency utility for thread-safe collections.
Answer: A
Rationale: SequencedCollection defines methods like getFirst(),
getLast(), addFirst(), addLast(), and reversed(), providing a common
interface for ordered collections (e.g., List, Deque). It does not replace
implementations or address concurrency.
6 Given the following code snippet, what is the output?
A) 10
B) 8
C) 6
D) Compilation error
Answer: C
Rationale: The lambda captures the effectively final variable x=2. The
function multiplies its argument by 2, so apply(3) returns 6. The
, variable x is not modified, so no compilation error.
7 Which of the following is a valid reason to prefer
`ThreadLocalRandom` over `Math.random()` in concurrent
applications?
A) `ThreadLocalRandom` produces cryptographically secure random
numbers.
B) `ThreadLocalRandom` reduces contention by providing a separate
generator per thread.
C) `Math.random()` is deprecated and will be removed in future Java
versions.
D) `ThreadLocalRandom` can be used without importing any
package.
Answer: B
Rationale: ThreadLocalRandom uses a separate RandomGenerator
instance per thread, eliminating contention on a shared seed.
Math.random() uses a single global Random instance, causing
contention. ThreadLocalRandom is not cryptographically secure, and
Math.random() is not deprecated.
8 Which of the following statements is correct regarding the use of
`var` in Java?
A) `var` can be used for method parameters and return types.
B) `var` can be used for local variables with an explicit initializer.
C) `var` is a reserved keyword and cannot be used as a variable
name.
D) `var` is only available when compiling with `--release 8` or
higher.
Answer: B
Rationale: `var` is a reserved type name that can be used for local
variables, but the type is inferred from the initializer. It cannot be used
for method parameters or return types. `var` is not a keyword, so it can
be used as a variable name (though discouraged). It requires Java 10+.