Courseiva

1Z0-811 · domain

Primitives, Strings and Operators

Practise Oracle Java Foundations 1Z0-811 Primitives, Strings and Operators practice questions — original exam-style scenarios with answer choices, explanations, and analysis of common mistakes.

105 questions32 easy39 medium34 hard

Focused practice

Practice Primitives, Strings and Operators questions

Scored sessions drawing only from this domain — pick a length below.

Start 20-question practice test →

What this domain covers

What to know about Primitives, Strings and Operators

Primitives, Strings and Operators questions test whether you can apply the concept in context, not just recognise a definition.

How the topic appears in realistic exam-style scenarios.

Which detail in the question changes the correct answer.

How to eliminate plausible but wrong options.

How to connect the question back to the wider exam objective.

Watch out for

Common Primitives, Strings and Operators exam traps

  • Answering from memory before reading the full scenario.
  • Missing a constraint such as cost, availability, security, scope or command context.
  • Choosing a broad answer when the question asks for the most specific fix.
  • Ignoring why the wrong options are tempting.

Question index

All Primitives, Strings and Operators questions (105)

Click any question to see the full explanation, or start a practice session above.

1

Given: boolean a = false; boolean b = true; boolean c = true; System.out.println(a || b && c); What is the output?

Hard
2

A developer writes the following code: String s1 = "Hello"; String s2 = "Hello"; System.out.println(s1 == s2); What is the output?

Easy
3

A social media platform processes user login requests. Each request generates a welcome message by concatenating the username with a fixed greeting using the + operator inside a loop that runs hundreds of times per second for thousands of users. The development team notices that the application suffers from high memory consumption and slow response times under load. They profile the code and discover that the method building the welcome message is a bottleneck. The team considers several options to improve performance while maintaining thread safety. Which approach should the team implement?

Easy
4

Which of the following is a valid declaration of a float variable?

Hard
5

Which operator is used to compare two strings for value equality in Java?

Medium
6

Refer to the exhibit. What is the result?

Hard
7

Which three of the following statements about primitive type conversion are true?

Hard
8

Which TWO statements are true about the String class in Java? (Choose 2)

Medium
9

What is the result of: System.out.println(10 + 20 + "30");

Easy
10

A stock trading system calculates daily profit using an int variable. During periods of high volatility, the profit can exceed Integer.MAX_VALUE (2,147,483,647). When this happens, the profit value wraps around to a negative number, leading to incorrect reporting. The lead developer wants to detect the overflow and throw an ArithmeticException rather than silently producing wrong results. The code cannot use long or BigInteger due to legacy constraints. Which approach should be taken?

Medium
11

What is the output of the following code? int x = 5; int y = 16; System.out.print(x + "," + y);

Hard
12

A developer needs to store a currency value with two decimal places. Which primitive type is most appropriate?

Easy
13

Match each Java tool to its function.

Medium
14

Which of the following is NOT a primitive data type?

Easy
15

Given: byte b = 10; b = b + 1; What is the result?

Hard
16

Refer to the exhibit. What is the output?

Hard
17

A developer writes: boolean b = !true && false; What is the value of b?

Easy
18

A developer is implementing a login system where users enter a password that is then hashed using SHA-256. The system stores the hash as a String in the database. On login, the entered password is hashed and compared to the stored hash using the == operator. Occasionally, valid users are denied access, even though the hashes are identical when printed. The developer has confirmed that the hash algorithm is correctly implemented and that the stored hash is exactly the same string as the computed hash. What is the most likely cause and correct fix?

Easy
19

What is the result of the following code? Integer a = 100; Integer b = 100; System.out.println(a == b);

Hard
20

Given: byte b = 10; b = b + 1; Which statement is true?

Hard
21

Which two of the following are primitives in Java? (Choose two.)

Medium
22

Given the code snippet: int x = 5; int y = 2; double result = x / y; What is the value of result?

Easy
23

What is the output of: int i = 1; i = i++; System.out.println(i);

Easy
24

A developer writes: char c = 'A'; int i = c + 1; System.out.println(i); What is the output?

Hard
25

Given the code snippet: double d = 10.5; int i = (int) d; System.out.println(i); What is the output?

Easy
26

You are developing a high-frequency trading application where performance is critical. You need to parse and concatenate trade messages. The messages are received as strings and must be combined into a single output string for logging. Each message is appended to the log string. Currently, you are using String concatenation with the '+' operator inside a loop that processes up to 10,000 messages per second. However, performance monitoring shows that the application experiences frequent garbage collection pauses, affecting throughput. Which approach should you take to reduce garbage collection overhead and improve performance?

Medium
27

What is the output of the following? int x = Integer.MAX_VALUE; x++; System.out.println(x);

Medium
28

A banking application uses a method to calculate interest: double calculateInterest(double balance) { return balance * 0.05; }. The method is called with an int argument: int accountBalance = 1000; double interest = calculateInterest(accountBalance); System.out.println(interest); The output is 50.0, but the expected output is 50.0. However, the developer notices that if the method is changed to return int, the output becomes 50.0 as well. Which statement about implicit casting is true?

Medium
29

A method has parameters: int x, double y. It performs x += y; and returns x. What is the range behavior?

Hard
30

Refer to the exhibit. Given the code, what is the value printed to the console?

Hard
31

Given: double d = 5.0; int i = d; What is the result?

Hard
32

What is the output of the following code? String s1 = "Hello"; String s2 = "Hello"; System.out.println(s1 == s2);

Medium
33

What is the cause of the compilation error?

Medium
34

You are part of a team maintaining a legacy order processing system. The system stores order totals as primitive double values. A recent bug report shows that for very large orders (around $1,000,000.00), the total after adding a tax of 8.25% is sometimes off by a few cents. The calculation is: total = orderTotal * (1 + taxRate). The taxRate is defined as double taxRate = 0.0825; The orderTotal is received as a double. The application needs exact monetary precision to two decimal places. Which solution best addresses the precision issue while minimizing changes to the existing code?

Hard
35

Which two of the following are valid ways to check if two String objects contain the same characters? (Assume s1 and s2 are non-null String references.)

Easy
36

Which operator is used to compare two values for equality in Java?

Easy
37

A developer writes the following code: int a = 5; int b = 2; double result = a / b; System.out.println(result); What is the output?

Medium
38

Which keyword is used to declare a constant in Java?

Medium
39

What is the value of the expression: 2 + 3 * 4 / 2 - 1?

Medium
40

Refer to the exhibit. What is the output?

Medium
41

What is the output of the following code? String str1 = "Java"; String str2 = new String("Java"); System.out.println(str1 == str2);

Easy
42

Which two expressions evaluate to true? (Choose two)

Medium
43

Given: int a = 9; int b = 2; double c = a / b; System.out.println(c); What is the output?

Easy
44

Which three statements about String immutability are true? (Choose three)

Hard
45

Which TWO of the following are primitive data types in Java?

Easy
46

Which of the following correctly uses the ternary operator to set int max to the larger of two ints x and y?

Medium
47

Given: String s1 = "Hello"; String s2 = "Hello"; String s3 = new String("Hello"); Which of the following is true?

Hard
48

Which two of the following are primitive data types in Java? (Choose two)

Easy
49

Arrange the steps to handle an exception using try-catch-finally in Java in the correct order.

Medium
50

Arrange the steps to create and use a simple Java inheritance hierarchy in the correct order.

Medium
51

Which THREE of the following expressions compile without error? (Choose 3)

Hard
52

Which primitive type can store a single character?

Medium
53

Refer to the exhibit. What is the output?

Easy
54

Given: String s1 = "Java"; String s2 = new String("Java"); What does (s1 == s2) evaluate to?

Medium
55

An integer counter variable is incremented in a loop that runs 3 billion times. Initially counter = 0. After the loop, the value is printed. Which code snippet correctly handles potential overflow?

Hard
56

What is the result of the following code snippet? int a = 5; int b = 2; double c = (double) (a / b); System.out.println(c);

Medium
57

What is the result of the following code? int a = 8; int b = 3; System.out.println(a >> 1);

Hard
58

What is the value of z after executing: int x = 3; int y = 2; int z = x++ * --y;

Hard
59

Which two of the following operators are logical operators in Java? (Choose two.)

Easy
60

A developer is writing a bitmask validation method. The method should return true if both input integers (x and y) have exactly the same least significant bit set. The developer writes: if (x & y == 1) { return true; } However, the condition never evaluates to true even when both numbers are odd (least significant bit = 1). Debugging shows that x and y are positive integers. What is the root cause and the correct fix?

Hard
61

A junior developer wrote the following code to compare two strings entered by a user: if (username == "admin") { grantAccess(); } else { denyAccess(); }. The code always denies access even when the user enters 'admin'. What is the most likely cause, and how should the code be fixed?

Easy
62

Given: String str = "Java"; str = str.concat(" SE"); str.replace('a', 'A'); System.out.println(str); What is the output?

Hard
63

Given boolean a = true, b = false, c = true; What is the result of (a || b) && (b || c)?

Hard
64

Which three of the following code snippets produce the output '5'?

Medium
65

Which primitive type can store a single character?

Easy
66

Which TWO of the following are valid Java identifiers? (Choose 2)

Easy
67

A developer needs to build a SQL query string by concatenating many parts. Which approach is most efficient for repeated concatenation?

Medium
68

Given: int a = 10; int b = 20; boolean flag = a++ > 10 && ++b > 20; What are the values of a and b after execution?

Hard
69

Which THREE of the following are valid Java operators?

Hard
70

Given: int i = 1; int j = i++ + ++i; What is the value of j?

Medium
71

A developer writes: int a = 9; int b = 2; double result = a / b; System.out.println(result); What is the output?

Easy
72

Given: int x = 10; int y = 20; What is the output of System.out.println(x + y * 2);?

Easy
73

Which of the following statements about the String class is true?

Hard
74

Which two statements are true about primitive data types in Java?

Medium
75

What is the output?

Easy
76

Which three of the following are valid Java operators that can be used with primitive numeric types?

Medium
77

A scientific application performs calculations with double precision. A specific formula divides two double values: result = a / b; where a and b are calculated from sensor readings. The result is expected to be at most 10 decimal digits of precision. However, the output often shows small rounding errors, e.g., 0.1 + 0.2 = 0.30000000000000004. The application must meet strict accuracy requirements and cannot tolerate these small errors. Which strategy should be used to achieve exact decimal representation?

Medium
78

Which TWO of the following are valid declarations and initializations of primitive variables?

Medium
79

Which primitive type has a default value of 0.0f?

Easy
80

Which of the following is a valid Java primitive type?

Easy
81

Refer to the exhibit. What is the output?

Medium
82

What is the output of the following code? int i = 0; i = i++ + ++i; System.out.println(i);

Medium
83

A method returns a String. The team debates using == vs equals(). Which correctly describes String comparison in Java?

Hard
84

What is the value of y after executing the following code? ```java int y = 10 + 12; ```

Hard
85

Given: int x = 3 + 4 * 2; What is x?

Easy
86

Given the following code, String s1 = new String("example"); String s2 = "example"; System.out.println(s1 == s2); Why does the code output false?

Hard
87

What is the value of 10 % 3?

Easy
88

A financial trading application processes a batch of 10 million trade transactions every night. Each transaction is a String containing trade details such as ID, symbol, quantity, and price. The current implementation uses string concatenation with the += operator in a loop to build a summary report string. The application frequently runs out of memory and takes hours to complete. The server has 16 GB of RAM and runs Java 11. The code cannot be restructured significantly due to regulatory requirements, but performance improvements are allowed. Which course of action will most effectively resolve the performance and memory issues?

Hard
89

Which THREE of the following statements about operators in Java are true?

Easy
90

A developer needs to concatenate several string values in a loop. Which approach is most efficient for performance?

Medium
91

Which THREE of the following expressions evaluate to true? (Assume int a=5, b=10)

Medium
92

What is the result of the following code snippet? int x = 5; int y = 2; double z = x / y; System.out.println(z);

Easy
93

A developer writes: String s = "Hello"; s.concat(" World"); System.out.println(s); What is the output?

Medium
94

A developer wants to assign the largest possible long value to a variable. Which is correct?

Medium
95

Evaluate the following expression: int x = 5; int y = (x > 5) ? 10 : 20; What is y?

Medium
96

Which of the following is a valid Java identifier?

Medium
97

Given: short s = 10; s = s + 5; What is the result?

Hard
98

What is the output of System.out.println(1 + 2 + "3" + 4 + 5);?

Easy
99

Which TWO of the following operations on String objects result in a new String object?

Hard
100

Which two of the following are valid ways to create a String object?

Medium
101

What is the default value of a boolean variable in Java?

Easy
102

Which TWO of the following are valid ways to create a String?

Medium
103

A developer is working on a Java application that processes user input. The application reads a string from the console and needs to compare it with a predefined constant string "ADMIN". The developer writes the following code: if (input == "ADMIN") { grantAccess(); }. During testing, the condition sometimes fails even when the user enters ADMIN. The input string is obtained via Scanner.nextLine(). Which is the most likely cause and best fix?

Hard
104

Which three of the following are valid ways to declare and initialize a variable of type int? (Choose three.)

Hard
105

A developer is implementing a login verification method that compares a user-entered password against a stored hash. The passwords are stored as String objects. Which approach ensures correct comparison?

Medium

Frequently asked questions

What does the Primitives, Strings and Operators domain cover on the 1Z0-811 exam?
Primitives, Strings and Operators questions test whether you can apply the concept in context, not just recognise a definition.
How many questions are in this domain?
This page lists all 105 Primitives, Strings and Operators questions in the 1Z0-811 question bank. The actual exam draws from this domain proportionally to its weighting in the official exam blueprint.
What is the best way to practise this domain?
Start with a short focused session (10 questions) to identify gaps, then work through explanations. Repeat with a longer session once the weak areas feel solid.
Can I practise only Primitives, Strings and Operators questions?
Yes — the session launcher on this page filters questions to this domain only. Choose any session length for inline explanations and scoring.
oracle-java-foundations ORACLE-JAVA-FOUNDATIONS primitives strings operators Practice Questions