Logical Operators in Java

In this class, We discuss Logical Operators in Java.

The reader should have prior knowledge of relational operators. Click here.

Logical Operators:

Logical AND &&

Logical OR ||

The above two operators are logical operators.

We take an example to understand the logical operators.

Example:

a=2, b = 5, and c=8

((a<b)&&(b<c))

The above expression uses the logical AND operator.

a<b is a relational operator that results in true.

b<c is a relational operator that results in true.

The logical AND operator is applied between the results obtained from the relational operator.

The two conditions, a<b, and b<c, results true, so the entire condition is true.

Both conditions are true logical AND results to true.

The below diagram shows the table for Logical AND.

Similarly, Logical OR results are true if any one condition is true.

The below diagram shows the table for Logical OR.