1Z0-811 Java Basics and Syntax Practice Question
A developer writes the following code to compare two strings: String s1 = "Java"; String s2 = new String("Java");
if (s1 == s2) { System.out.println("Equal"); } else { System.out.println("Not equal"); }What is the output?
⚠ Common exam trap
Oracle often tests the distinction between reference equality (==) and value equality (.equals()) with String objects, trapping candidates who assume == compares the actual text content.
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
✓
Not equal
The == operator compares object references, not the actual string content. Variable s1 refers to a string literal from the string pool, while s2 is a new String object created on the heap, so they are different objects and the comparison returns false, printing 'Not equal'.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Compilation error
Why it's wrong here
Code compiles fine.
- ✓
Not equal
Why this is correct
== compares references, and they are different.
- ✗
Equal
Why it's wrong here
References are different.
- ✗
Runtime error
Why it's wrong here
Code runs without exception.
Go deeper
Related to this question
About these practice questions
This 1Z0-811 question is part of Courseiva's 481-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 →
Same concept, more angles
1 more way this is tested on 1Z0-811
These questions test the same concept from different angles. Work through them to make sure you can recognise it however the exam phrases it.
Variation 1. Given the code: String s1 = "Java"; String s2 = new String("Java"); if (s1 == s2) { System.out.print("Equal"); } else { System.out.print("Not Equal"); } What is the output?
hard- A.Runtime error
- B.Compilation error
- C.Equal
- ✓ D.Not Equal
Why D: The == operator compares object references, not the actual string content. s1 is a string literal stored in the string pool, while s2 is a new String object created on the heap, so they refer to different memory locations, making the comparison false and printing 'Not Equal'.
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This 1Z0-811 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-811 exam.