De Morgan's laws explain how negation changes Boolean operators: !(a || b) equals !a && !b, while !(a && b) equals !a || !b. Applying the transformation requires changing both the negation of each operand and the operator. section 2.8
Use the laws to avoid conditions that silently accept invalid values or process the wrong branch:
- Review impossible range checks such as byteValue < 0 && byteValue > 255; no value can satisfy both comparisons. section 2.8
- When excluding either of two alternatives, preserve the grouped negation or change || to && and negate both operands. section 2.8
- Prefer parentheses when they make the intended logic clearer, especially in conditions combining exclusions and ranges. section 2.8
Correcting a printable-character check
The faulty condition uses && between c < 0x20 and c > 0x7E, so it can never reject characters outside the printable range. The corrected condition uses (c < 0x20 || c > 0x7E), while separately allowing tab and newline. section 2.8
void processLine(String line) {
// Ignore comments
if (!line.startsWith("#") || !line.startsWith("//")) {
processContentLine(line);
}
}
Inspect the treacherous manually negated condition: with mutually exclusive prefixes, !startsWith("#") || !startsWith("//") is always true, so comment lines are not skipped. section 2.8

