# Java – Boolean and Logical Operators

Java – Boolean and Logical Operators 2017-08-09T09:42:49+00:00
 OPERATOR MEANING EXPLANATION EXAMPLE RESULT & Logical AND Produce true if both operands are also true otherwise false True & false false | Logical OR Produce true if one of them operand is true, otherwise false True | false true ^ Logical XOR (exclusive OR) if exactly one operand is true, then the result is true. Otherwise, the result is false True ^ false true || Short-circuit OR Check below program Check below program – && Short-circuit AND It will not check the second condition if the first one is false Check below program – ! Logical unary NOT This sign is used for invert the result !true false &= AND assignment This is a short sign of Produce true if both operands are also true otherwise false on the same operand Check below program – |= OR assignment This is a short sign of Produce true if one of the operand is true otherwise false on the same operand Check below program – ^= XOR assignment This is a short sign of produce true if exactly one operand is true, otherwise, the result is false on the same operand Check below program –

EX.

Output :
…………..Boolean Logical Operators……………..
<———Basic Boolean Logical Operators———>
a = false
b = true
Boolean Logical OR : a | b = true
Boolean Logical AND : a & b = false
Boolean Logical XOR(exclusive OR) : a ^ b = true
(!a & b) | (a & !b) = true
!a = true
<———Boolean Logical Assignment Operators———>
Before apply assignment operator, the value of a = false
After apply assignment operator : a &= b means a = a & b hence now the value of a : false

Output :
<———Boolean Short-Circuit Operators———>
In Short-circuit AND operator(&&):
Not checked the second condition in IF-BLECK if first condition is false………
So,the value of j = 20