Courseiva

1Z0-829 Practice Question: Handling Date, Time, Text, Numeric and Boolean Values

Exhibit

Boolean b1 = Boolean.valueOf("true");
Boolean b2 = Boolean.valueOf("True");
System.out.println(b1 == b2);

Refer to the exhibit. What is the output?

⚠ Common exam trap

The trap here is that candidates mistakenly think `Boolean.valueOf(true)` returns a primitive `boolean` or a new object each time, leading them to believe `==` compares values or that the result is `false`, when in fact `valueOf` returns the cached singleton `Boolean.TRUE`.

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

true

The code uses `Boolean.valueOf(true)` which returns the `Boolean` constant `Boolean.TRUE`, and `Boolean.TRUE` is a singleton object that is `==` to itself. The `==` operator compares object references, not values, so the comparison `Boolean.valueOf(true) == Boolean.TRUE` evaluates to `true` because both refer to the same cached `Boolean` instance from the `Boolean` class's static final fields.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • compile error

    Why it's wrong here

    Incorrect: The code compiles and runs.

  • null

    Why it's wrong here

    Incorrect: valueOf never returns null.

  • false

    Why it's wrong here

    Incorrect: b1 and b2 reference the same Boolean.TRUE object.

  • true

    Why this is correct

    Correct: Both return Boolean.TRUE, so == compares reference and is true.

About these practice questions

This 1Z0-829 question is part of Courseiva's 513-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

JA

Written by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

This 1Z0-829 practice question is part of Courseiva's free Oracle certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the 1Z0-829 exam.