Search:

Submit Article

# Boolean Operators

Posted By: Betsy Fischer     Category: Java     Views: 26112

### This article lists and explains boolean operators available in java.

Boolean operator returns either true or false.  Below are the boolean operators listed.

### Boolean operators

 Operators Meaning a && b Conditional AND. If both variables a and b are true, the result is true.If  either of the variable is false, the result is false.If a is false then b is not evaluated. a & b Boolean AND.If both variables are true, the result is true. If either of the variable is false, the result is false. a || b Conditional OR.If either of the variable is true, the result is true.If a is true, b is not evaluated. a | b Boolean OR.If either of the variable is true, the result is true. ! a Boolean NOT.If a is true, the result is false.If a is false, the result is true. a ^ b Boolean XOR.If a is true and b is false, the result is true.If a is false and b is true, the result is true.In other cade, the result is false.

Examples of Boolean Operators

Example 1 : Program that displays use of boolean operators i.e &&, &, ||, |, !, ^

class BoolOptrDemo
public static void main(String args[])
{

boolean b1 = true;
boolean b2 = false;

System.out.println("b1|b2 = "+(b1|b2));
System.out.println("b1&b2 = "+(b1&b2));
System.out.println("!b1 = "+(!b1));
System.out.println("b1^b2 = "+(b1^b2));
System.out.println("(b1|b2)&b1 = "+((b1|b2)&b1));
}
}

Share:

Didn't find what you were looking for? Find more on Boolean Operators Or get search suggestion and latest updates.

 Betsy Fischer author of Boolean Operators is from Frankfurt, Germany. View All Articles

 Please enter your CommentComment should be atleast 30 Characters.Please put code inside [Code] your code [/Code]. No Comment Found, Be the First to post comment!