PRACTICE / UNDERSTAND / REPEAT

Java MCQ Practice

Work through Java types, collections, exceptions, strings, and object behavior.

281 questionsAnswers explainedFree · no login

Put your knowledge to the test.

A random set of up to 10 questions from Java. Your answers stay on this page.

Choose a topic

Try a few questions

Open a topic above to explore the complete question bank.

01 / Types & equality · MCQQuestion link ↗

What does `==` compare for two Java object references?

Choose one answer
Answer & explanation

Answer: Whether both references point to the same object

For objects, `==` compares reference identity. Use an appropriate `equals` implementation for value equality.

02 / Collections · MCQQuestion link ↗

Which collection type guarantees unique elements?

Choose one answer
Answer & explanation

Answer: Set

A `Set` models unique elements. A `List` permits duplicates and preserves positional order.

03 / Exceptions · MCQQuestion link ↗

Which block runs whether or not a `try` block throws?

Choose one answer
Answer & explanation

Answer: finally

`finally` normally runs after `try`/`catch`, making it useful for cleanup.

04 / Streams · MCQQuestion link ↗

Which stream operation transforms each element?

Choose one answer
Answer & explanation

Answer: map

`map` transforms elements; `filter` keeps matching elements; `forEach` performs an action.

05 / Concurrency · MCQQuestion link ↗

What does `synchronized` provide around a monitor?

Choose one answer
Answer & explanation

Answer: Mutual exclusion and memory visibility

A synchronized region is mutually exclusive for a monitor and establishes visibility guarantees.

06 / Declarations · Code recallQuestion link ↗

Complete the method declaration so it returns an integer.

public ___ size() {
    return 3;
}
Answer & explanation

Answer: int

The declared return type must match the returned value; `3` is an `int`.