What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
When two Java integers have the same absolute magnitude, the result still needs a tie policy. In Mauricio Ramirez’s DEV Community article about an absolute-maximum exercise, the method chooses the greater signed value on a tie—so it returns 5 for both (-5, 5) and (5, -5). That detail makes the result independent of input order. The example also has a boundary caveat: Java’s Math.abs does not produce a positive result for Integer.MIN_VALUE.
What does “absolute maximum” mean here?
The exercise’s goal is to select the input integer with the greatest absolute magnitude. That is not the same as selecting the numerically largest signed integer: for example, -10 has a greater absolute magnitude than 5.
As an Amazon Associate I earn from qualifying purchases.
Ramirez’s example uses a varargs method, AbsoluteMax.getMaxValue(int... numbers). It starts by selecting the first number, then scans the remaining values. A candidate replaces the current selection if its absolute magnitude is larger, or if the magnitudes are equal and the candidate’s signed value is greater.
Why compare the signed values when magnitudes tie?
Opposite-sign values can have equal absolute magnitudes. For -5 and 5, both magnitudes are 5, so magnitude alone cannot decide which value to return. The second comparison supplies the rule: return the greater signed value. Thus 5 wins whether the input is (-5, 5) or (5, -5).
Without that comparison, a scan that keeps the current value on a magnitude tie would return whichever tied value appeared first. The output would then depend on input order rather than the method’s stated preference. A tie-breaker makes that behavior explicit.
How the example handles inputs
The article’s examples cover mixed-sign values, all-negative values, a single value, repeated equal-magnitude cases, and an empty varargs call. A single value is already the only possible result; with an empty input there is no first value to select.
Rank #2
The method checks for a null or empty array and throws IllegalArgumentException in either case. In Java, a call with no arguments to a varargs method supplies an empty array, so the no-argument example exercises the empty-input guard.
Do these 3 things before closing this tab:
1Repair Windows errors before they cause bigger problems2Fix the driver behind crashes, sound loss and screen glitches3Clear out junk files and repair common Windows errorsWhat the example misses: Integer.MIN_VALUE
The tie-break lesson is sound, but the displayed use of Math.abs(int) does not correctly rank every possible Java int by mathematical magnitude. Oracle’s Java SE 21 documentation explains that Math.abs(Integer.MIN_VALUE) returns Integer.MIN_VALUE, still negative, because the positive magnitude cannot fit in an int. See the Java SE 21 Math.abs(int) documentation.
That creates a concrete failure for the displayed comparison: because the computed “absolute value” of Integer.MIN_VALUE is negative, a routine comparing these results as ordinary integers can treat it as smaller than other magnitudes. Tests that use values such as -5 and 5 do not expose this boundary.
Choose the boundary policy before changing the code
If the contract is to rank by mathematical magnitude across the full int range, convert each value to long before taking its absolute value. A long can represent the positive magnitude of every Java int, including Integer.MIN_VALUE. The method can then use the same signed-value tie-break after comparing widened magnitudes.
Rank #4
If instead the contract treats an unrepresentable absolute value as an error, Java SE 21 provides Math.absExact(int), which throws ArithmeticException when the result overflows. That is an overflow policy, not a complete absolute-maximum algorithm: the method still needs to define how such an exception is handled and how ties are decided. See the Math.absExact(int) documentation.
Quick wins for a faster PC:
Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Repair Windows errors before they cause bigger problemsFix Now →The broader lesson from the edge case
Ramirez describes the experience personally: “Coding on "automatic mode" for a long time made me overlook these details.” The example shows why it helps to make the method’s contract precise: specify what “maximum” measures, how ties are resolved, which inputs are rejected, and what happens at numeric boundaries. A few ordinary examples can demonstrate the intended tie rule, but boundary values are needed to establish whether the implementation fulfills the contract across Java’s full integer range.
Quick Recap
Best Value
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




