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.

LogicalOperation OperatorSymbol Example Description
AND && a && b Returns logical AND of a and b.
OR || a || b Returns logical OR of a and b.
NOT ! !a Returns logical Not of a.

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.