- A
Use bitwise AND with a mask to detect overflow.
Why wrong: Manually detecting overflow with bitwise operations is complex, error-prone, and not a standard solution. Math.addExact is far simpler and reliable.
- B
Use Math.addExact() for the addition and catch or let the exception propagate.
Math.addExact precisely detects overflow and throws ArithmeticException, fitting the requirement to alert about overflow.
- C
Cast the operands to long before addition and then cast back to int.
Why wrong: Casting to long avoids overflow temporarily, but casting back to int can still produce incorrect values without detection. It also violates the no-type-change constraint.
- D
Use BigInteger for the calculation and convert back to int.
Why wrong: Using BigInteger changes the data type, which is prohibited by the legacy constraint.
Quick Answer
The correct approach is to use Math.addExact() for the addition and catch or let the ArithmeticException propagate. This method performs integer addition with built-in overflow detection, throwing an ArithmeticException precisely when the result exceeds Integer.MAX_VALUE or falls below Integer.MIN_VALUE, thus preventing silent wraparound to negative values. On the Oracle Java Foundations 1Z0-811 exam, this question tests your understanding of the Math.addExact() family of methods, which are specifically designed for safe arithmetic in legacy code where data types cannot be changed. A common trap is assuming that casting to long or using bitwise operators provides reliable overflow detection, but these approaches either change the required type or introduce complexity without guaranteed detection. Remember the memory tip: "addExact catches the wrap" — when you need exact integer math without type changes, let addExact throw the exception for you.
1Z0-811 Primitives, Strings and Operators Practice Question
This 1Z0-811 practice question tests your understanding of primitives, strings and operators. The scenario asks you to isolate a root cause — eliminate options that address a different problem before choosing. After answering, compare your reasoning against the explanation and wrong-answer breakdown below. Once you have made your selection, read the full explanation to reinforce the concept and understand why each distractor is designed to mislead on exam day.
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?
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
Use Math.addExact() for the addition and catch or let the exception propagate.
Math.addExact() performs integer addition with overflow detection, throwing an ArithmeticException if the result overflows. Option A directly addresses the requirement. Option B (BigInteger) changes the data type, which is ruled out. Option C (casting to long before addition) changes the type, also not allowed. Option D (bitwise operators) is complex and error-prone, and does not inherently detect overflow.
Key principle: Count usable hosts — not total addresses — and remember that the network and broadcast addresses are not available to hosts in standard IPv4 subnets.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Use bitwise AND with a mask to detect overflow.
Why it's wrong here
Manually detecting overflow with bitwise operations is complex, error-prone, and not a standard solution. Math.addExact is far simpler and reliable.
- ✓
Use Math.addExact() for the addition and catch or let the exception propagate.
Why this is correct
Math.addExact precisely detects overflow and throws ArithmeticException, fitting the requirement to alert about overflow.
Related concept
CIDR notation defines the prefix length.
- ✗
Cast the operands to long before addition and then cast back to int.
Why it's wrong here
Casting to long avoids overflow temporarily, but casting back to int can still produce incorrect values without detection. It also violates the no-type-change constraint.
- ✗
Use BigInteger for the calculation and convert back to int.
Why it's wrong here
Using BigInteger changes the data type, which is prohibited by the legacy constraint.
Common exam traps
Common exam trap: usable hosts are not the same as total addresses
Subnetting questions often tempt you into counting all addresses. In normal IPv4 subnets, the network and broadcast addresses are not usable host addresses.
Detailed technical explanation
How to think about this question
Subnetting questions test whether you can identify the network, broadcast address, usable range, mask and correct subnet. Slow down enough to calculate the block size correctly.
KKey Concepts to Remember
- CIDR notation defines the prefix length.
- Block size helps identify subnet boundaries.
- Network and broadcast addresses are not usable hosts in normal IPv4 subnets.
- The required host count determines the smallest suitable subnet.
TExam Day Tips
- Write the block size before choosing the subnet.
- Check whether the question asks for hosts, subnets or a specific address range.
- Do not confuse /24, /25, /26 and /27 host counts.
Key takeaway
Count usable hosts — not total addresses — and remember that the network and broadcast addresses are not available to hosts in standard IPv4 subnets.
Real-world example
How this comes up in practice
A network engineer segments a warehouse floor into three subnets: 20 scanners, 5 printers, and 2 management hosts. Picking the wrong mask wastes addresses or leaves too few usable hosts. Exam questions test whether you can apply CIDR notation, calculate block size, and identify the correct usable-host range for a given prefix.
What to study next
Got this wrong? Here's your next step.
Review block sizes, usable host formulas (2^n − 2), and how to find network and broadcast addresses for /24 through /30. Then practise related 1Z0-811 subnetting questions on CIDR, address ranges, and subnet selection.
- →
Primitives, Strings and Operators — study guide chapter
Learn the concepts, then practise the questions
- →
Primitives, Strings and Operators practice questions
Targeted practice on this topic area only
- →
All 1Z0-811 questions
509 questions across all exam domains
- →
Oracle Java Foundations 1Z0-811 study guide
Full concept coverage aligned to exam objectives
- →
1Z0-811 practice test guide
How to use practice tests most effectively before exam day
Related practice questions
Related 1Z0-811 practice-question pages
Use these pages to review the topic behind this question. This is how one missed question becomes focused revision.
What is Java practice questions
Practise 1Z0-811 questions linked to What is Java.
Java Basics and Syntax practice questions
Practise 1Z0-811 questions linked to Java Basics and Syntax.
Primitives, Strings and Operators practice questions
Practise 1Z0-811 questions linked to Primitives, Strings and Operators.
Control Flow and Loops practice questions
Practise 1Z0-811 questions linked to Control Flow and Loops.
Arrays and Methods practice questions
Practise 1Z0-811 questions linked to Arrays and Methods.
Object-Oriented Programming practice questions
Practise 1Z0-811 questions linked to Object-Oriented Programming.
Exception Handling and Development Tools practice questions
Practise 1Z0-811 questions linked to Exception Handling and Development Tools.
1Z0-811 fundamentals practice questions
Practise 1Z0-811 questions linked to 1Z0-811 fundamentals.
1Z0-811 scenario practice questions
Practise 1Z0-811 questions linked to 1Z0-811 scenario.
1Z0-811 troubleshooting practice questions
Practise 1Z0-811 questions linked to 1Z0-811 troubleshooting.
Practice this exam
Start a free 1Z0-811 practice session
Short sessions build daily habit. Longer sessions build exam-day stamina. Try a timed session to simulate real conditions.
FAQ
Questions learners often ask
What does this 1Z0-811 question test?
Primitives, Strings and Operators — This question tests Primitives, Strings and Operators — CIDR notation defines the prefix length..
What is the correct answer to this question?
The correct answer is: Use Math.addExact() for the addition and catch or let the exception propagate. — Math.addExact() performs integer addition with overflow detection, throwing an ArithmeticException if the result overflows. Option A directly addresses the requirement. Option B (BigInteger) changes the data type, which is ruled out. Option C (casting to long before addition) changes the type, also not allowed. Option D (bitwise operators) is complex and error-prone, and does not inherently detect overflow.
What should I do if I get this 1Z0-811 question wrong?
Review block sizes, usable host formulas (2^n − 2), and how to find network and broadcast addresses for /24 through /30. Then practise related 1Z0-811 subnetting questions on CIDR, address ranges, and subnet selection.
What is the key concept behind this question?
CIDR notation defines the prefix length.
About these practice questions
Courseiva creates original exam-style practice questions with explanations and wrong-answer analysis. It does not publish real exam questions, exam dumps, or protected exam content. Learn why practice questions differ from exam dumps →
Keep practising
More 1Z0-811 practice questions
- Arrange the steps to compile and run a Java program from the command line in the correct order.
- Arrange the steps to handle an exception using try-catch-finally in Java in the correct order.
- Arrange the steps to use the Scanner class to read user input in Java in the correct order.
- Arrange the steps to create an object from a class in Java in the correct order.
- Arrange the steps to use a for loop to iterate over an array in Java in the correct order.
- Arrange the steps to overload a method in Java in the correct order.
Last reviewed: Jun 23, 2026
This 1Z0-811 practice question is part of Courseiva's free Oracle certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the 1Z0-811 exam.
Question Discussion
Share a tip, memory trick, or ask about the reasoning behind this question. Do not post real exam questions, leaked content, braindumps, or copyrighted exam material. Comments are moderated and may be removed without notice.
Sign in to join the discussion.