Oracle Java SE Developer
Certification: Practice Questions
with Answers & Rationales
Section 1: Java Fundamentals (Questions 1-15)
Q1. Which of the following correctly describes the output of this code?
```java
String s1 = "Java";
String s2 = "Java";
String s3 = new String("Java");
System.out.println(s1 == s2);
System.out.println(s1 == s3);
```
A) true, true
B) true, false
C) false, true
,D) false, false
Answer: B
Rationale: String literals are interned—s1 and s2 reference the same object in the String pool, so
`==` returns true. `new String()` creates a new object in heap memory, so s3 references a
different object, making `==` false. Use `.equals()` for content comparison.
Q2. What is the output of this code?
```java
int x = 5;
int y = 2;
System.out.println(x / y);
System.out.println(x / (double) y);
```
A) 2, 2.5
B) 2.5, 2.5
C) 2, 2.0
D) Compilation error
Answer: A
Rationale: Integer division truncates the remainder, so 5/2 = 2. When one operand is a double,
numeric promotion occurs, yielding 2.5.
,Q3. Which of the following is a valid identifier in Java?
A) 1stPlace
B) _private
C) int
D) my-value
Answer: B
Rationale: Identifiers can start with a letter, underscore (_), or dollar sign ($). `1stPlace` starts
with a digit; `int` is a reserved keyword; `my-value` contains a hyphen (-), which is not allowed.
Q4. What does this code print?
```java
int a = 10;
int b = 20;
boolean result = a++ > 10 && ++b > 20;
System.out.println(a + ", " + b);
```
A) 10, 20
B) 11, 21
C) 11, 20
D) 10, 21
, Answer: C
Rationale: `a++` is post-increment (returns 10, then increments to 11). The first condition (10 >
10) is false, so short-circuit evaluation prevents `++b` from executing. b remains 20.
Q5. Which statement about text blocks in Java is true?
A) Text blocks can only contain ASCII characters
B) Text blocks preserve all whitespace by default
C) Text blocks are delimited by `"""` and can span multiple lines
D) Text blocks cannot contain escape sequences
Answer: C
Rationale: Text blocks (`""" ... """`) were introduced for multi-line strings. They preserve
indentation relative to the closing delimiter and can contain escape sequences. They support all
Unicode characters.
Q6. What is the output?
```java
System.out.println(10 + 20 + "30");
System.out.println("10" + 20 + 30);
```
Certification: Practice Questions
with Answers & Rationales
Section 1: Java Fundamentals (Questions 1-15)
Q1. Which of the following correctly describes the output of this code?
```java
String s1 = "Java";
String s2 = "Java";
String s3 = new String("Java");
System.out.println(s1 == s2);
System.out.println(s1 == s3);
```
A) true, true
B) true, false
C) false, true
,D) false, false
Answer: B
Rationale: String literals are interned—s1 and s2 reference the same object in the String pool, so
`==` returns true. `new String()` creates a new object in heap memory, so s3 references a
different object, making `==` false. Use `.equals()` for content comparison.
Q2. What is the output of this code?
```java
int x = 5;
int y = 2;
System.out.println(x / y);
System.out.println(x / (double) y);
```
A) 2, 2.5
B) 2.5, 2.5
C) 2, 2.0
D) Compilation error
Answer: A
Rationale: Integer division truncates the remainder, so 5/2 = 2. When one operand is a double,
numeric promotion occurs, yielding 2.5.
,Q3. Which of the following is a valid identifier in Java?
A) 1stPlace
B) _private
C) int
D) my-value
Answer: B
Rationale: Identifiers can start with a letter, underscore (_), or dollar sign ($). `1stPlace` starts
with a digit; `int` is a reserved keyword; `my-value` contains a hyphen (-), which is not allowed.
Q4. What does this code print?
```java
int a = 10;
int b = 20;
boolean result = a++ > 10 && ++b > 20;
System.out.println(a + ", " + b);
```
A) 10, 20
B) 11, 21
C) 11, 20
D) 10, 21
, Answer: C
Rationale: `a++` is post-increment (returns 10, then increments to 11). The first condition (10 >
10) is false, so short-circuit evaluation prevents `++b` from executing. b remains 20.
Q5. Which statement about text blocks in Java is true?
A) Text blocks can only contain ASCII characters
B) Text blocks preserve all whitespace by default
C) Text blocks are delimited by `"""` and can span multiple lines
D) Text blocks cannot contain escape sequences
Answer: C
Rationale: Text blocks (`""" ... """`) were introduced for multi-line strings. They preserve
indentation relative to the closing delimiter and can contain escape sequences. They support all
Unicode characters.
Q6. What is the output?
```java
System.out.println(10 + 20 + "30");
System.out.println("10" + 20 + 30);
```