Index

chapter1

chapter2page1

chapter2page2

chapter2page3

chapter2page4

chapter2page5

chapter2page6

chapter2page7

chapter2page8

chapter2page9

chapter2page10

chapter2page11

chapter2page12

chapter2page13

chapter2page14

chapter2page15

chapter2page16

chapter2page17

chapter2page18

chapter2page19

chapter2page21

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.3 - Bitwise Operators

There are four bitwise operators used for changing the bits of the integer data. These are bitwise AND (&), bitwise OR (|), bitwise exclusive OR (^) , bitwise complement (~)

Bitwise operators are intended to change the bits of the internally stored values of integer variables. A task not very compatible with the concept of Java, because Java is designed for saving the programmers from the need of bit hunting. We will not introduce these very unfrequently used operators. Anything they can do, may be done by more conventional ways in Java.

2.6.4 - Shift Operators

Shift operators are used for shifting the bits of the stored integer data. There are three shift operators. These are shift left(<<), shift right (>>), and shift right with zero filling (>>>) . We will not introduce these low- level shift operators.

2.6.5 - Logical Operators

Logical operators accept boolean operands and return boolean values. Returning boolean (logical) values may be stored in boolean variables. Logical operators are very important for any programming language including Java, because they provide true or false information. These logical data may be evaluated by the compiler and depending the results of the evaluation of logical (either true or false) values, the program may execute some statements instead of others. This is called branching. We will focus here to the obtention of boolean values relevant for program branching. Logical operators are here for that.

The result of any logical operator may be used for program branching as follows : If the result of the logical complement operator, is true let the program execute some statements, else execute other statements, otherwise continue to the program execution from the next step to the decision statement. By the way, there is no escape from implicit otherwise.

2.6.5.1 - Unary Logical Operator

The only unary logical operator is the logical complement operator! (NOT)

2.6.5.1.1 - Unary Logical Complement Operator !

Unary logical complement operator ! is simply a negation (NOT) operator. It returns the opposite of the boolean value of his operand. Example:

package preliminary;
public class Negation {
public static void main(String[] args){
boolean control = false;
System.out.print(" Result = "  +  ! control);
 } // end main
} //end class Negation

The result of this program :

       Result = true

Looking to the program above, the priority of the logical complement operator is higher than the addition operator (Section 2.6, Tables 1 ,2 ,3). Therefore, the expression "Result = "+ !control evaluates first the complement of the variable control, then concatenation of the result by the string "Result =".

<< Index

Polyglott HTML5(XHTML5 compliant HTML5 code)