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.
1. Operator – Symbol – Example – Description
Java supports the following Logical Operators.
Logical Operation | Operator Symbol | 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 . |
2. Example for Logical Operators
In the following example, we take two boolean values, and perform different Logical Operations on these values.
Main.java
</>
Copy
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
3. Tutorials for Each of the Logical Operators
The following Java tutorials cover each of these Logical Operators in detail.