Index

chapter1

chapter2page2

chapter2page1

chapter2page3

chapter2page4

chapter2page5

chapter2page6

chapter2page7

chapter2page8

chapter2page9

chapter2page10

chapter2page11

chapter2page12

chapter2page13

chapter2page14

chapter2page15

chapter2page16

chapter2page17

chapter2page18

chapter2page19

chapter2page20

chapter2page22

chapter2page23

chapter2page24

chapter2page25

chapter2page26

chapter2page27

chapter2page28

chapter2page29

chapter2page30

chapter2page31

chapter2page32

chapter2page33

chapter2page34

chapter3

link one

link one

link one

link one

link one

link one

2.6.5.2 - Binary Logical Operators

Binary logical operators take two operands and return single boolean value depending the logical operator and the boolean values of the both operands. Binary logical operators are logical AND &, logical exclusive OR ^ and logical OR ||. They applications are covered in this section.

2.6.5.2.1 - Logical AND Operator &

The logical AND operator returns true, only when both of his operands are true, it returns false otherwise. The most important fact about this operator is both operands are always evaluated whatever the result of one of the parties. One explanatory example is given below:

package preliminary;
public class LogicalAND {
public static void main(String[] args){
boolean controlFalse = false;
boolean controlTrue = true;
System.out.print(" true & true = "  +  controlTrue & controlTrue);
System.out.print(" true & false = "  +  controlTrue & controlFalse);
System.out.print(" false & false = "  +  controlFalse & controlFalse);
 } // end main
} //end class LogicalAnd

The result of this program :

        true & true = true
        true & false = false
        false & false = false

As it can be understood from the results of the above program, logical AND returns true only if both of the operands are true. It will return false in all other cases.

2.6.5.2.2 - Logical OR Operator |

The logical OR operator returns true, only when one of his operands is true, it returns false otherwise. An example is given below:

package preliminary;
public class LogicalOR {
public static void main(String[] args){
boolean controlFalse = false;
boolean controlTrue = true;
System.out.print(" true | true = "  +  (controlTrue | controlTrue));
System.out.print(" true | false = "  +  (controlTrue | controlFalse));
System.out.print(" false | false = "  +  (controlFalse | controlFalse));
 } // end main
} //end class LogicalOR

The result of this program :

true | true = true
true | false = true
false | false = false

Logical OR returns true only if only one or both of the operands is true. It will return false if both of the operands are false.

2.6.5.2.3 - Logical Exclusive OR (XOR) Operator^

The logical XOR operator returns true, only when one of his operands is the opposite of the other. It returns false otherwise.

package preliminary;
public class LogicalAND {
public static void main(String[] args){
boolean controlFalse = false;
boolean controlTrue = true;
System.out.print(" true & true = "  +  controlTrue & controlTrue);
System.out.print(" true & false = "  +  controlTrue & controlFalse);
System.out.print(" false & false = "  +  controlFalse & controlFalse);
 } // end main
} //end class LogicalAnd

The result of this program :

        true & true = true
        true & false = false
        false & false = false

As it can be understood from the results of the above program, logical AND returns true only if both of the operands are true. It will return false in all other cases.

<< Index

Polyglott HTML5(XHTML5 compliant HTML5 code)