A useful Java quiz checks whether you can predict behavior and explain its cause. Guessing the right option once is weaker evidence than tracing the relevant values or naming the API contract. This chapter review covers fundamentals, control flow, object behavior, collections, exceptions, and advanced execution. Try the questions before reading their explanations. The three complete programs provide worked reasoning examples, while the quiz blocks test additional rules from the course. Use the Java quiz hub for the larger course assessment.
Fundamentals: types and expressions
Start with the declared operand types. Integer division discards the fractional part for positive operands, so twenty-five divided by four produces six when both operands are int. Converting an operand before division changes that calculation to floating point; converting the integer result afterward does not restore the lost fraction. For strings, distinguish identity from content equality. A new String can hold matching text without being the same object reference.
Control flow: inspect the exact loop boundary
Trace initialization, condition, body, and update in that order. The loop example starts at one and includes four, so all four values contribute to the sum. Changing less-than-or-equal to less-than excludes the final value. break exits its enclosing loop, while continue skips the remainder of an iteration and proceeds according to that loop's update and condition. Read where the statement occurs instead of assuming its effect from the keyword alone.
Objects: separate declared type from actual instance
For an overridden instance method, Java selects the implementation according to the actual object's class. The variable's declared type still limits which members source code can access directly. Static methods do not use the same overriding mechanism. Constructors initialize new instances and are not inherited like ordinary methods. Encapsulation questions should connect private state to controlled operations rather than merely asking you to memorize that private is an access modifier.
Collections: know the operation contract
List.of returns an unmodifiable list. Attempting to add an element throws UnsupportedOperationException rather than quietly increasing the list. Copying it into ArrayList creates a modifiable list containing the same element references. Sets enforce uniqueness according to their equality contract; maps associate keys with values. Do not infer insertion order from HashMap or HashSet just because one printed example appears ordered on your machine.
Exceptions: identify the responsible boundary
Some checked exceptions must be caught or declared, such as IOException from file operations. RuntimeException subclasses do not have that compile-time requirement, but still need sensible application handling when expected. A catch block should match the relevant failure, and finally normally performs cleanup regardless of ordinary success or exception flow. Try-with-resources closes eligible resources. A quiz about exceptions should distinguish compile-time obligations from runtime outcomes instead of treating all errors as interchangeable.
Advanced concepts: execution and completion
A stream's intermediate operations describe work that a terminal operation triggers. A lambda describes an implementation that runs when its functional method is invoked. Thread.start requests execution on another thread, while run directly calls the method on the current thread. join waits for thread completion; it does not make unsafe increments atomic. These distinctions are ideal quiz subjects because short source expressions can hide very different execution boundaries.
Practice tasks and checks
Choose one question from each group and write the rule that determines its answer. For expressions, compare integer division with a cast applied before division. For loops, change one boundary and trace the visited values. For objects, override a method in a small subclass and call it through the parent type. For collections, compare a direct edit of List.of with editing an ArrayList copy. For exceptions, identify a checked declaration and decide where handling belongs. For concurrency, explain why waiting for completion does not repair a lost-update race. Keep wrong predictions in a learning log with corrected reasoning; this makes later revision target actual gaps instead of repeatedly answering already comfortable questions.
Java Summary
- Trace types, boundaries, and execution order before choosing an answer.
- Explain why alternatives are wrong instead of memorizing option positions.
- Combine quiz results with tested coding variations.
- Continue with targeted coding exercises when these examples are clear.
Java Examples
Each example shows the code, the output it produces and what each part does.
Compare string content and identity
Save this program as QuizStringIdentity.java. Compile it with javac QuizStringIdentity.java and run it with java QuizStringIdentity.
Expected output:
Each new expression constructs a separate String object, so the references differ and identity comparison is false. equals compares the stored text and returns true. This program deliberately avoids relying on string-literal interning. In everyday content comparisons, use equals or Objects.equals when a nullable value is allowed. A correct answer should state which kind of equality each line asks about.
public class QuizStringIdentity {
public static void main(String[] args) {
String first = new String("Cedar");
String second = new String("Cedar");
System.out.println(first == second);
System.out.println(first.equals(second));
}
}false
trueTrace an inclusive loop
Save this program as QuizLoopBoundary.java. Compile it with javac QuizLoopBoundary.java and run it with java QuizLoopBoundary.
Expected output:
The loop visits one, two, three, and four. Adding them produces ten. After the update makes value five, the condition fails and execution continues after the loop. If the condition were value < 4, the sum would be six instead. The declared loop variable is scoped to the loop statement, so reading value afterward would require a different declaration rather than simply another print.
public class QuizLoopBoundary {
public static void main(String[] args) {
int sum = 0;
for (int value = 1; value <= 4; value++) sum += value;
System.out.println(sum);
}
}10Copy an unmodifiable list before editing
Save this program as QuizListCopy.java. Compile it with javac QuizListCopy.java and run it with java QuizListCopy.
Expected output:
The source list contains two elements and cannot be edited through its API. The ArrayList constructor creates another collection with those two references, and add appends C to that new collection. The original size stays two. This is a shallow collection copy, not a deep clone of elements. Strings are immutable here, making element mutation irrelevant to the demonstrated list independence.
import java.util.ArrayList;
import java.util.List;
public class QuizListCopy {
public static void main(String[] args) {
List<String> fixed = List.of("A", "B");
List<String> editable = new ArrayList<>(fixed);
editable.add("C");
System.out.println(fixed);
System.out.println(editable);
}
}[A, B]
[A, B, C]Java FAQ
How should I use a wrong answer?
Identify the rule your prediction violated, then write a small variation that tests that rule. Rereading the explanation is useful, but a second correct trace provides stronger evidence that the misunderstanding is resolved.
Does passing a quiz prove project readiness?
It shows understanding of sampled concepts, not complete development ability. Pair quizzes with coding exercises and a project that requires validation, testing, and useful handling of failures.
How often should I retake the quizzes?
Space them out: retake a chapter quiz a day after studying, again after a week and once more after a month. Getting answers right after a gap shows real understanding; repeating a quiz immediately mostly measures short-term memory.
Which chapter should I review first?
Start with the chapter where you scored lowest, and check whether the mistakes share a cause, such as integer division or object references. Fixing an early concept often improves results in later chapters that depend on it.
Is it useful to take a quiz before reading a chapter?
Yes. A quick attempt beforehand shows what you already know and what to focus on, and trying to answer, even incorrectly, makes the explanation more memorable when you read it. Retake the quiz afterwards to see the difference.
Java Exercises
Answer each one and check it instantly. If you get stuck, open the hint before the answer.
What is 25 / 4 when both operands are int?
Why is the first QuizStringIdentity output false?
Java Quiz
6 questions to check what you learned.
What sum results from changing value <= 4 to value < 4?
- 6
- 10
- 4
Which class supplies an overridden instance method at runtime?
- The actual object class
- Only the variable declared type
- The source filename
What does adding directly to List.of("A", "B") do?
- Throws UnsupportedOperationException
- Adds a third item
- Returns a new list automatically
How must ordinary Java code handle IOException from a declared file operation?
- Catch it or declare it
- Ignore it because all exceptions are unchecked
- Convert every method to static
Which stream operation triggers the described traversal?
- A terminal operation such as count
- Every map call immediately
- Only the package import
What does join guarantee for a completed worker?
- The caller waits for its termination
- Every worker update was atomic
- The worker never threw