You must read short Java snippets and state the exact output or the declaration that compiles, and pick the correct primitive or String type for a described value. The single most important thing: integer division truncates, and floating-point literals default to double unless suffixed with f.
Start practicing
Primitives, Strings and Operators — choose a session length
Free · No account required
Domain overview
This domain covers Java's eight primitive types, String immutability, and operator behavior including integer division, numeric promotion, and literal typing. Questions present short code snippets or design scenarios and ask you to predict output, choose a declaration that compiles, or select the type matching a stated requirement.
Exam objectives
Selecting boolean, char, int, long, float, double, byte, or short for a stated storage need
Predicting results of integer division, modulo, and mixed-type arithmetic with implicit widening
Recognizing why a float literal needs an f suffix and when a cast is required
Using String for immutable text such as fixed-length identifiers, and comparing with equals not ==
Assuming int / int yields a decimal; it truncates before assignment to double, so 9 / 2 prints 4.0.
Writing double d = 3.5; float f = 3.5; without the f suffix, which fails to compile.
Comparing String contents with == instead of equals, or treating String as mutable when it is immutable.
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?
2Given: String str = "Java"; str = str.concat(" SE"); str.replace('a', 'A'); System.out.println(str); What is the output?
3Which operator is used to compare two strings for value equality in Java?
4What is the result of: System.out.println(10 + 20 + "30");
5Given: boolean a = false; boolean b = true; boolean c = true; System.out.println(a || b && c); What is the output?
6Which of the following is a valid Java identifier?
7What is the output of: int i = 1; i = i++; System.out.println(i);
8Which primitive type can store a single character?
9Given: double d = 5.0; int i = d; What is the result?
10What is the default value of a boolean variable in Java?
11Which THREE of the following are valid Java operators?
12Which TWO of the following are primitive data types in Java?
13Which THREE of the following expressions evaluate to true? (Assume int a=5, b=10)
14What is the value of y after executing the following code? ```java int y = 10 + 12; ```
15Given the following Java code: ```java public class Main { public static void main(String[] args) { int a = 10, b = 5, c = 15; int result = (a > b) ? (a > c) ? a : c : (b > c) ? b : c; System.out.println(result == 15 ? "Yes" : "No"); } } ``` What is the output?
16A 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?
17A developer writes the following code: int a = 5; int b = 2; double result = a / b; System.out.println(result); What is the output?
18Arrange the steps to handle an exception using try-catch-finally in Java in the correct order.
19Arrange the steps to create and use a simple Java inheritance hierarchy in the correct order.
20Match each Java tool to its function.
21A developer writes the following code: String s1 = "Hello"; String s2 = "Hello"; System.out.println(s1 == s2); What is the output?
22What is the result of the following code snippet? int a = 5; int b = 2; double c = (double) (a / b); System.out.println(c);
23Given: short s = 10; s = s + 5; What is the result?
24What is the output of System.out.println(1 + 2 + "3" + 4 + 5);?
25Which of the following correctly uses the ternary operator to set int max to the larger of two ints x and y?
26Given boolean a = true, b = false, c = true; What is the result of (a || b) && (b || c)?
27What is the output of the following? int x = Integer.MAX_VALUE; x++; System.out.println(x);
28Which TWO of the following are valid declarations and initializations of primitive variables?
29Which TWO of the following operations on String objects result in a new String object?
30What is the output of the program?
31What is the output of the following code? int x = 5; int y = 16; System.out.print(x + "," + y);
32A developer writes: int a = 9; int b = 2; double result = a / b; System.out.println(result); What is the output?
33Given: int i = 1; int j = i++ + ++i; What is the value of j?
34A method returns a String. The team debates using == vs equals(). Which correctly describes String comparison in Java?
35A developer needs to store a currency value with two decimal places. Which primitive type is most appropriate?
36Given: String s1 = "Java"; String s2 = new String("Java"); What does (s1 == s2) evaluate to?
37A developer writes: boolean b = !true && false; What is the value of b?
38A developer writes: char c = 'A'; int i = c + 1; System.out.println(i); What is the output?
39Which TWO of the following are valid Java identifiers? (Choose 2)
40Which THREE of the following expressions compile without error? (Choose 3)
41Given: int a = 9; int b = 2; double c = a / b; System.out.println(c); What is the output?
42Given: String s1 = "Hello"; String s2 = "Hello"; String s3 = new String("Hello"); Which of the following is true?
43Which of the following is NOT a primitive data type?
44What is the output of the following code? int i = 0; i = i++ + ++i; System.out.println(i);
45What is the value of 10 % 3?
46Which keyword is used to declare a constant in Java?
47What is the result of the following code? Integer a = 100; Integer b = 100; System.out.println(a == b);
48What is the output of the following code? String str1 = "Java"; String str2 = new String("Java"); System.out.println(str1 == str2);
49Refer to the exhibit. What is the result?
50Which two of the following are primitive data types in Java? (Choose two)
51Which two expressions evaluate to true? (Choose two)
52Which three statements about String immutability are true? (Choose three)
53What is the result of the following code snippet? int x = 5; int y = 2; double z = x / y; System.out.println(z);
54Which of the following is a valid Java primitive type?
55A developer needs to concatenate several string values in a loop. Which approach is most efficient for performance?
56What is the output of the following code? String s1 = "Hello"; String s2 = "Hello"; System.out.println(s1 == s2);
57Given: byte b = 10; b = b + 1; What is the result?
58Which operator is used to compare two values for equality in Java?
59What is the value of the expression: 2 + 3 * 4 / 2 - 1?
60Which of the following statements about the String class is true?
61Which two of the following are primitives in Java? (Choose two.)
62Which three of the following are valid ways to declare and initialize a variable of type int? (Choose three.)
63What is the cause of the compilation error?
64Given: int x = 10; int y = 20; What is the output of System.out.println(x + y * 2);?
65Given the code snippet: double d = 10.5; int i = (int) d; System.out.println(i); What is the output?
66A developer needs to build a SQL query string by concatenating many parts. Which approach is most efficient for repeated concatenation?
67Evaluate the following expression: int x = 5; int y = (x > 5) ? 10 : 20; What is y?
68Given: byte b = 10; b = b + 1; Which statement is true?
69Which primitive type has a default value of 0.0f?
70What is the result of the following code? int a = 8; int b = 3; System.out.println(a >> 1);
71Which two of the following are valid ways to create a String object?
72Which three of the following statements about primitive type conversion are true?
73You 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?
74You 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?
75A 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?
76Which three of the following are valid Java operators that can be used with primitive numeric types?
77A 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?
78A 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?
79A 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?
80A 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?
81Which two statements are true about primitive data types in Java?
82Refer to the exhibit. Given the code, what is the value printed to the console?
83A logging component builds a status line from a String named label that is currently "OK" and an int named code equal to 7. The developer writes: String line = label + code + 1; The intent is to append the numeric sum of code and 1 to the label. What is the actual value of line?
84A logistics application needs to store a shipment's unique tracking code, which is a fixed 12-character alphanumeric identifier. The code must not be modified after it is assigned. Which Java type is the most appropriate to declare for storing this tracking code?
85A developer is reviewing code that declares several numeric variables. Which of the following declarations correctly assigns a floating-point literal to a variable of type float without causing a compile-time error?
86A developer writes the following code in a Java application: String s = "Hello"; s.concat(" World"); System.out.println(s); What is printed?
87A developer is writing a method that must accept and manipulate whole-number values that can be negative, and also needs a type suitable for storing a single Unicode character. Which two primitive types are appropriate for these requirements? (Choose two.)
88A logistics company stores shipment weights in a Java program. A developer writes the following statement: int weight = 15.75; What is the result when this line is compiled?
89A programmer is writing code that needs to store the result of a comparison that checks whether a number is greater than 10. Which primitive type should be used for the variable that holds this result?
90A developer is reviewing code that declares several variables for a sensor-monitoring application. Which two declarations are valid in Java? (Choose two.)
91A developer is comparing user input strings in a login module. The code is: String input = new String("admin"); String stored = "admin"; boolean match = input == stored; What is the value of match and why?
Deep-dive questions
The most-searched questions in this domain — detailed explanations, worked examples, full answer breakdowns.
You must read short Java snippets and state the exact output or the declaration that compiles, and pick the correct primitive or String type for a described value. The single most important thing: integer division truncates, and floating-point literals default to double unless suffixed with f.
The Courseiva 1Z0-811 question bank contains 91 questions in the Primitives, Strings and Operators domain, covering the 14% of the exam attributed to this domain in the official Oracle blueprint. 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