Test 2 - Free Java SE 25 certification Mock test - Exam Code 1Z0-831-Oracle certified Java SE 25 Professional
Primitive types seem pretty straightforward until you get to the exam and they're all traps. This free Java SE 25 mock test for the 1Z0-831 cert is all about the fundamentals of the numeric types: the primitives, the wrapper classes, arithmetic, type conversion and the Math API. Every question is in the same style as Oracle's own questions, with a very short snippet of code that in fact hides a rather subtle rule and you only ever get the right answer if you really think about it.
You'll be practising predicting the outcome of various scenarios: int and long mixed together, a char in an arithmetic expression, integer division (which quietly trims off the fractional part). You'll see why adding two byte values gives you an int, why the compound assignment operators all have an implicit cast built in and why a narrowing conversion can take a positive number and turn it negative. Overflow is a very common type of question so you'll also be looking at Math.addExact and the like which throw an exception rather than just silently wrapping around.
Wrapper classes get the same attention. Autoboxing and unboxing appear benign but the behaviour of using the == operator to compare two Integer objects is very different when done in and out of the cached range of -128 to 127. Unboxing a null reference will of course throw a NullPointerException and a ternary expression which mixes boxed and primitive operands can unbox in some very unexpected ways. There are questions on all of this, as well as on the various methods such as Integer.parseInt, Integer.valueOf and Integer.compare.
Operator precedence and short circuit evaluation is another one. You'll be looking at expressions involving pre-increment operators, bitwise and logical operators and the conditional operator where you have to evaluate the parts in order. You'll also come across the usual floating point oddities (NaN, positive and negative infinity) and the classic 0.1 + 0.2 comparison.
Our explanations walk you through each expression step by step so you can reproduce the logic on exam day without a compiler. Rather than trying to memorise the rules you learn how to apply them in a mechanical, confident way. Be very wary of implicit narrowing in compound assignments as those questions are designed to reward just one memorised rule.
Do the test, then go back and compare your answers against the rules you thought you knew. You'll invariably find that a fairly small number of conversion and promotion rules are responsible for the majority of the marks you've lost. Fix those and a whole lot of the questions in that category suddenly become easy. Keep going until every single rule is absolutely obvious, then move on to the next mock in the series to keep that momentum going.
