Java Logical Operators

Java Logical Operators are used to create boolean conditions, modify a boolean expression, or combine two or more simple conditions to form a complex condition.

Operator – Symbol – Example – Description

Java supports the following Logical Operators.

LogicalOperationOperatorSymbolExampleDescription
AND&&a && bReturns logical AND of a and b.
OR||a || bReturns logical OR of a and b.
NOT!!aReturns logical Not of a.
ADVERTISEMENT

Tutorials

The following Java tutorials cover each of these Logical Operators in detail.

Example

In the following example, we take two boolean values, and perform different Logical Operations on these values.

Main.java

public class Main {
    public static void main(String[] args) {
        boolean a = true;
        boolean b = false;
        
        boolean andResult = a && b;
        boolean orResult = a || b;
        boolean notResult = !a;

        System.out.println("a && b = " + andResult);
        System.out.println("a || b = " + orResult);
        System.out.println("!a     = " + notResult);
    }
}

Output

a && b = false
a || b = true
!a     = false

Conclusion

In this Java Tutorial, we learned about Logical Operators, their syntax, and usage with examples.