Java Logical Operators
Logical Operators are used to evaluate a condition, to check if an expression is true or false. Later in the course, you will find these very useful in conditional statements and loops.
In java, the logical operators are:
&& for logical AND that will return true if both expressions are true
|| for logical OR that will return true if either expression is true
! for logical NOT will return true if the expression is false, or false if the expression is true (basically the opposite of the expression)
For example, imagine we have two expressions called exp1 and exp2:
exp1&&exp2 (exp1 AND exp2) will return true if both exp1 and exp2 are true. If either or both are false, it would return false.
exp1||exp2 (exp1 OR exp2) will return true if either exp1 or exp2 are true. If both are false it would return false.
!exp (NOT exp) would return the opposite of exp, so it would return false if exp is true and it would return true if exp is false.