Logical operators are binary operators that allow you to combine different boolean expressions (a boolean expression is basically something that can evaluate to either true
or false
). Look at the tables below to learn about them. The tables are divided into 2 sections: a truth table, and examples. For the truth table section, p refers to any boolean expression.
<aside> 💡 For a deeper explanation, you can also watch this Crash Course video (note: don’t worry too much about the logic gates and transistors — focus on what AND, OR, XOR, and NOT mean conceptually).
</aside>
Credit: Y. Daniel Liang, Introduction to Java Programming (Comprehensive Version), 10th ed.
<aside> ⚠️ NOTE: There is an error in the first example. It should say that the overall expression is false because (age > 28) is false.
</aside>
Credit: Y. Daniel Liang, Introduction to Java Programming (Comprehensive Version), 10th ed.
Credit: Y. Daniel Liang, Introduction to Java Programming (Comprehensive Version), 10th ed.