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.
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.
Given: boolean a = false; boolean b = true; boolean c = true; System.out.println(a || b && c); What is the output?
Hard2A developer writes the following code: String s1 = "Hello"; String s2 = "Hello"; System.out.println(s1 == s2); What is the output?
Easy3A 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?
Easy4Which of the following is a valid declaration of a float variable?
Hard5Which operator is used to compare two strings for value equality in Java?
Medium6Refer to the exhibit. What is the result?
Hard7Which three of the following statements about primitive type conversion are true?
Hard8Which TWO statements are true about the String class in Java? (Choose 2)
Medium9What is the result of: System.out.println(10 + 20 + "30");
Easy10A 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?
Medium11What is the output of the following code? int x = 5; int y = 16; System.out.print(x + "," + y);
Hard12A developer needs to store a currency value with two decimal places. Which primitive type is most appropriate?
Easy13Match each Java tool to its function.
Medium14Which of the following is NOT a primitive data type?
Easy15Given: byte b = 10; b = b + 1; What is the result?
Hard16Refer to the exhibit. What is the output?
Hard17A developer writes: boolean b = !true && false; What is the value of b?
Easy18A 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?
Easy19What is the result of the following code? Integer a = 100; Integer b = 100; System.out.println(a == b);
Hard20Given: byte b = 10; b = b + 1; Which statement is true?
Hard21Which two of the following are primitives in Java? (Choose two.)
Medium22Given the code snippet: int x = 5; int y = 2; double result = x / y; What is the value of result?
Easy23What is the output of: int i = 1; i = i++; System.out.println(i);
Easy24A developer writes: char c = 'A'; int i = c + 1; System.out.println(i); What is the output?
Hard25Given the code snippet: double d = 10.5; int i = (int) d; System.out.println(i); What is the output?
Easy26You 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?
Medium27What is the output of the following? int x = Integer.MAX_VALUE; x++; System.out.println(x);
Medium28A 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?
Medium29A method has parameters: int x, double y. It performs x += y; and returns x. What is the range behavior?
Hard30Refer to the exhibit. Given the code, what is the value printed to the console?
Hard31Given: double d = 5.0; int i = d; What is the result?
Hard32What is the output of the following code? String s1 = "Hello"; String s2 = "Hello"; System.out.println(s1 == s2);
Medium33What is the cause of the compilation error?
Medium34You 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?
Hard35Which 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.)
Easy36Which operator is used to compare two values for equality in Java?
Easy37A developer writes the following code: int a = 5; int b = 2; double result = a / b; System.out.println(result); What is the output?
Medium38Which keyword is used to declare a constant in Java?
Medium39What is the value of the expression: 2 + 3 * 4 / 2 - 1?
Medium40Refer to the exhibit. What is the output?
Medium41What is the output of the following code? String str1 = "Java"; String str2 = new String("Java"); System.out.println(str1 == str2);
Easy42Which two expressions evaluate to true? (Choose two)
Medium43Given: int a = 9; int b = 2; double c = a / b; System.out.println(c); What is the output?
Easy44Which three statements about String immutability are true? (Choose three)
Hard45Which TWO of the following are primitive data types in Java?
Easy46Which of the following correctly uses the ternary operator to set int max to the larger of two ints x and y?
Medium47Given: String s1 = "Hello"; String s2 = "Hello"; String s3 = new String("Hello"); Which of the following is true?
Hard48Which two of the following are primitive data types in Java? (Choose two)
Easy49Arrange the steps to handle an exception using try-catch-finally in Java in the correct order.
Medium50Arrange the steps to create and use a simple Java inheritance hierarchy in the correct order.
Medium51Which THREE of the following expressions compile without error? (Choose 3)
Hard52Which primitive type can store a single character?
Medium53Refer to the exhibit. What is the output?
Easy54Given: String s1 = "Java"; String s2 = new String("Java"); What does (s1 == s2) evaluate to?
Medium55An 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?
Hard56What is the result of the following code snippet? int a = 5; int b = 2; double c = (double) (a / b); System.out.println(c);
Medium57What is the result of the following code? int a = 8; int b = 3; System.out.println(a >> 1);
Hard58What is the value of z after executing: int x = 3; int y = 2; int z = x++ * --y;
Hard59Which two of the following operators are logical operators in Java? (Choose two.)
Easy60A 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?
Hard61A 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?
Easy62Given: String str = "Java"; str = str.concat(" SE"); str.replace('a', 'A'); System.out.println(str); What is the output?
Hard63Given boolean a = true, b = false, c = true; What is the result of (a || b) && (b || c)?
Hard64Which three of the following code snippets produce the output '5'?
Medium65Which primitive type can store a single character?
Easy66Which TWO of the following are valid Java identifiers? (Choose 2)
Easy67A developer needs to build a SQL query string by concatenating many parts. Which approach is most efficient for repeated concatenation?
Medium68Given: int a = 10; int b = 20; boolean flag = a++ > 10 && ++b > 20; What are the values of a and b after execution?
Hard69Which THREE of the following are valid Java operators?
Hard70Given: int i = 1; int j = i++ + ++i; What is the value of j?
Medium71A developer writes: int a = 9; int b = 2; double result = a / b; System.out.println(result); What is the output?
Easy72Given: int x = 10; int y = 20; What is the output of System.out.println(x + y * 2);?
Easy73Which of the following statements about the String class is true?
Hard74Which two statements are true about primitive data types in Java?
Medium75What is the output?
Easy76Which three of the following are valid Java operators that can be used with primitive numeric types?
Medium77A 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?
Medium78Which TWO of the following are valid declarations and initializations of primitive variables?
Medium79Which primitive type has a default value of 0.0f?
Easy80Which of the following is a valid Java primitive type?
Easy81Refer to the exhibit. What is the output?
Medium82What is the output of the following code? int i = 0; i = i++ + ++i; System.out.println(i);
Medium83A method returns a String. The team debates using == vs equals(). Which correctly describes String comparison in Java?
Hard84What is the value of y after executing the following code? ```java int y = 10 + 12; ```
Hard85Given: int x = 3 + 4 * 2; What is x?
Easy86Given the following code, String s1 = new String("example"); String s2 = "example"; System.out.println(s1 == s2); Why does the code output false?
Hard87What is the value of 10 % 3?
Easy88A 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?
Hard89Which THREE of the following statements about operators in Java are true?
Easy90A developer needs to concatenate several string values in a loop. Which approach is most efficient for performance?
Medium91Which THREE of the following expressions evaluate to true? (Assume int a=5, b=10)
Medium92What is the result of the following code snippet? int x = 5; int y = 2; double z = x / y; System.out.println(z);
Easy93A developer writes: String s = "Hello"; s.concat(" World"); System.out.println(s); What is the output?
Medium94A developer wants to assign the largest possible long value to a variable. Which is correct?
Medium95Evaluate the following expression: int x = 5; int y = (x > 5) ? 10 : 20; What is y?
Medium96Which of the following is a valid Java identifier?
Medium97Given: short s = 10; s = s + 5; What is the result?
Hard98What is the output of System.out.println(1 + 2 + "3" + 4 + 5);?
Easy99Which TWO of the following operations on String objects result in a new String object?
Hard100Which two of the following are valid ways to create a String object?
Medium101What is the default value of a boolean variable in Java?
Easy102Which TWO of the following are valid ways to create a String?
Medium103A 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?
Hard104Which three of the following are valid ways to declare and initialize a variable of type int? (Choose three.)
Hard105A 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?
MediumOther domains
All 1Z0-811 exam domains
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.