Practice 1Z0-811 Primitives, Strings and Operators questions with full explanations on every answer.
Start practicing
Primitives, Strings and Operators — choose a session length
Free · No account required
Click any question to see the full explanation and answer options, or start a focused practice session above.
Given the code snippet: int x = 5; int y = 2; double result = x / y; What is the value of result?
2A developer writes: String s = "Hello"; s.concat(" World"); System.out.println(s); What is the output?
3Given: String str = "Java"; str = str.concat(" SE"); str.replace('a', 'A'); System.out.println(str); What is the output?
4Which operator is used to compare two strings for value equality in Java?
5What is the result of: System.out.println(10 + 20 + "30");
6Given: boolean a = false; boolean b = true; boolean c = true; System.out.println(a || b && c); What is the output?
7Which of the following is a valid Java identifier?
8What is the output of: int i = 1; i = i++; System.out.println(i);
9Which primitive type can store a single character?
10Given: double d = 5.0; int i = d; What is the result?
11What is the default value of a boolean variable in Java?
12Which TWO of the following are valid ways to create a String?
13Which THREE of the following are valid Java operators?
14Which TWO of the following are primitive data types in Java?
15Which THREE of the following expressions evaluate to true? (Assume int a=5, b=10)
16What is the output?
17What is the value of y?
18What is the output?
19A 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?
20A 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?
21A developer writes the following code: int a = 5; int b = 2; double result = a / b; System.out.println(result); What is the output?
22Refer to the exhibit. What is the output?
23Arrange the steps to handle an exception using try-catch-finally in Java in the correct order.
24Arrange the steps to create and use a simple Java inheritance hierarchy in the correct order.
25Match each primitive data type to its default value.
26Match each Java tool to its function.
27A developer writes the following code: String s1 = "Hello"; String s2 = "Hello"; System.out.println(s1 == s2); What is the output?
28What is the result of the following code snippet? int a = 5; int b = 2; double c = (double) (a / b); System.out.println(c);
29Given: short s = 10; s = s + 5; What is the result?
30What is the output of System.out.println(1 + 2 + "3" + 4 + 5);?
31Which of the following correctly uses the ternary operator to set int max to the larger of two ints x and y?
32Given boolean a = true, b = false, c = true; What is the result of (a || b) && (b || c)?
33Which primitive type can store a single character?
34What is the output of the following? int x = Integer.MAX_VALUE; x++; System.out.println(x);
35What is the value of z after executing: int x = 3; int y = 2; int z = x++ * --y;
36Which TWO of the following are valid declarations and initializations of primitive variables?
37Which TWO of the following operations on String objects result in a new String object?
38Which THREE of the following statements about operators in Java are true?
39What is the output of the program?
40What is the output?
41What is the output?
42A developer writes: int a = 9; int b = 2; double result = a / b; System.out.println(result); What is the output?
43Given: int i = 1; int j = i++ + ++i; What is the value of j?
44A method returns a String. The team debates using == vs equals(). Which correctly describes String comparison in Java?
45A developer needs to store a currency value with two decimal places. Which primitive type is most appropriate?
46Given: String s1 = "Java"; String s2 = new String("Java"); What does (s1 == s2) evaluate to?
47A method has parameters: int x, double y. It performs x += y; and returns x. What is the range behavior?
48A developer writes: boolean b = !true && false; What is the value of b?
49A developer wants to assign the largest possible long value to a variable. Which is correct?
50A developer writes: char c = 'A'; int i = c + 1; System.out.println(i); What is the output?
51Which TWO of the following are valid Java identifiers? (Choose 2)
52Which TWO statements are true about the String class in Java? (Choose 2)
53Which THREE of the following expressions compile without error? (Choose 3)
54Refer to the exhibit. What is the output?
55Refer to the exhibit. What is the output?
56Refer to the exhibit. What is the output?
57Given: int a = 9; int b = 2; double c = a / b; System.out.println(c); What is the output?
58A developer wants to compare two String objects for content equality. Which code snippet will work correctly?
59Given: String s1 = "Hello"; String s2 = "Hello"; String s3 = new String("Hello"); Which of the following is true?
60Which of the following is NOT a primitive data type?
61What is the output of the following code? int i = 0; i = i++ + ++i; System.out.println(i);
62Which of the following is a valid declaration of a float variable?
63What is the value of 10 % 3?
64Which keyword is used to declare a constant in Java?
65What is the result of the following code? Integer a = 100; Integer b = 100; System.out.println(a == b);
66Refer to the exhibit. What is the output?
67Refer to the exhibit. What is the result?
68Refer to the exhibit. What is the output?
69Which two of the following are primitive data types in Java? (Choose two)
70Which two expressions evaluate to true? (Choose two)
71Which three statements about String immutability are true? (Choose three)
72What is the result of the following code snippet? int x = 5; int y = 2; double z = x / y; System.out.println(z);
73Which of the following is a valid Java primitive type?
74A developer needs to concatenate several string values in a loop. Which approach is most efficient for performance?
75Given: int a = 10; int b = 20; boolean flag = a++ > 10 && ++b > 20; What are the values of a and b after execution?
76What is the output of the following code? String s1 = "Hello"; String s2 = "Hello"; System.out.println(s1 == s2);
77Given: byte b = 10; b = b + 1; What is the result?
78Which operator is used to compare two values for equality in Java?
79What is the value of the expression: 2 + 3 * 4 / 2 - 1?
80Which of the following statements about the String class is true?
81Which two of the following are primitives in Java? (Choose two.)
82Which three of the following are valid ways to declare and initialize a variable of type int? (Choose three.)
83Which two of the following operators are logical operators in Java? (Choose two.)
84What is the cause of the compilation error?
85Why does the code output false?
86What is the output?
87A 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?
88An 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?
89Given the code snippet: double d = 10.5; int i = (int) d; System.out.println(i); What is the output?
90A developer needs to build a SQL query string by concatenating many parts. Which approach is most efficient for repeated concatenation?
91Evaluate the following expression: int x = 5; int y = (x > 5) ? 10 : 20; What is y?
92Given: byte b = 10; b = b + 1; Which statement is true?
93Which primitive type has a default value of 0.0f?
94What is the result of the following code? int a = 8; int b = 3; System.out.println(a >> 1);
95Given: int x = 3 + 4 * 2; What is x?
96Which two of the following are valid ways to create a String object?
97Which three of the following statements about primitive type conversion are true?
98Which three of the following code snippets produce the output '5'?
99You 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?
100You 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?
101A 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?
102A junior developer is implementing a method to calculate the average of three exam scores stored as integers. The method should return a double representing the average, rounded to one decimal place. The developer writes: double avg = (score1 + score2 + score3) / 3; However, the result is always an integer. Which of the following modifications ensures the correct result?
103Which 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.)
104Which three of the following are valid Java operators that can be used with primitive numeric types?
105A 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?
106A 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?
107A 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?
108A 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?
109A 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?
110Which two statements are true about primitive data types in Java?
111Refer to the exhibit. Given the code, what is the value printed to the console?
112A 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?
The Primitives, Strings and Operators domain covers the key concepts tested in this area of the 1Z0-811 exam blueprint published by Oracle. Courseiva provides free domain-focused practice, mock exams, missed-question review, and readiness tracking across all 1Z0-811 domains — no account required.
The Courseiva 1Z0-811 question bank contains 112 questions in the Primitives, Strings and Operators domain. Click any question to see the full explanation and answer breakdown.
Start with a 10-question focused session to identify your baseline accuracy in this domain. Read every explanation — even for questions you answer correctly — to understand the reasoning. Once you score consistently above 80%, move to a 20–30 question session to confirm depth before moving to the next domain.
Yes — the session launcher on this page draws questions exclusively from the Primitives, Strings and Operators domain. Choose 10, 20, 30, or 50 questions for a focused session, or click individual questions to review them one by one.
Save your results, see per-domain analytics, and get readiness scores — free, for every certification.
Sign Up FreeFree forever · Every certification included