| Relational Operator |
Purpose | Form | Value |
| > | greater than | expr1 operator expr2 where expr1 and expr2 are integers and/or floating point numbers |
true or false |
| >= | greater than or equal to | ||
| < | less than | ||
| <= | less than or equal to | ||
| == | equal to | expr1 operator expr2 where expr1 and expr2 are integers and/or floating point numbers * or * "object variables" (references) with compatible types (discussed later in the course) |
|
| != | not equal to |
| Logical Operator |
Purpose | Form | Value |
| && | and | expr1 && expr2 | True if both expr1 AND expr2 are true. If expr1 is false, Java doesn't bother to evaluate expr2 (lazy evaluation). |
| || | or | expr1 || expr2 | True if either expr1 OR expr2 is true or both are true. If expr1 is true, Java doesn't bother to evaluate expr2 (lazy evaluation). |
| ! | not | !expr1 | True if expr1 is NOT true; otherwise false. |
| a | b | a && b | a || b | ! (a && b) | (! a) && b |
| T | T | ||||
| T | F | ||||
| F | T | ||||
| F | F |
> boolean a = true; > boolean b = true; > a && b true