Operators >
Siva Nookala - 25 Aug 2016
Boolean logical operators operate only on boolean operands. These operators combine one or two boolean values to form a new boolean depending upon the operation. Logical operators produce results or outputs in the form of boolean values i.e., either true or false.

The logical operators are used when we want to form compound conditions by combining two or more relations.
example : a > b && X == 25
The following logical operators are supported for boolean type.

The below boolean logical table shows the results of various operators. This table is important and needs to be remembered for future.

Boolean Logic
class BoolLogic
{
    public static void main(String arg[])
    {
        boolean a = true;
        boolean b = false;
        boolean c = a | b;
        boolean d = a & b;
        boolean e = a ^ b;
        boolean f = (!a & b) | (a & !b);
        boolean g = !a;
        
        System.out.println("        a = " + a);
        System.out.println("        b = " + b);
        System.out.println("      a|b = " + c);
        System.out.println("      a&b = " + d);
        System.out.println("      a^b = " + e);
        System.out.println("!a&b|a&!b = " + f);
        System.out.println("       !a = " + g);    
    }
}
OUTPUT

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

DESCRIPTION