In Java ||
is short-circuit OR
and &&
is short-circuit AND
.
When using the || and && forms, Java will not evaluate the right-hand operand when the outcome of the expression can be determined by the left operand alone.
The following code uses short-circuit logical evaluation to avoid dividing by zero.
if (denom != 0 && num / denom > 10) {
}