chapter4 operators
DESCRIPTION
chapterTRANSCRIPT
Slide 1
UNIT- ICHAPTER IN BOOK- 4operators in java-K. IndhuSYLLABUS COVERED HEREK. INDHU2Operators in JavaGoalsK. INDHU3The Conditional OperatorThe Assignment OperatorBoolean Logical OperatorsShort Circuit Logical OperatorShift OperatorLeft Shift Operator ExampleOperators in Precedence
The conditional operatorK. INDHU4The ? Operator is called the Conditional Operator.The ? has this general form-> expression1 ? expression2 : expression3
The assignment oPeratorK. INDHU5The general form is ->var = expression;
Example ->int x, y, z;x = y = z = 100; // set x, y, and z to 100
Boolean logical operatorsK. INDHU6
Short circuit logical operatorK. INDHU7They are secondary version of Boolean AND & OR.&& is short circuit AND. || is short circuit OR.
If you use the || and && forms, rather than the | and & forms of these operators, Java will not bother to evaluate the right-hand operand when the outcome of the expression can be determined by the left operand alone.
Example->if (denom != 0 && num / denom > 10)Since the short-circuit form of AND (&&) is used, there is no risk of causing a run-time exception when denom is zero.
If this line of code were written using the single & version of AND, both sides would have to be evaluated, causing a run-time exception when denom is zero.shift operatorsK. INDHU8
Left shift operator exampleK. INDHU9
Shift operatorsK. INDHU10The shift operators include->left shift " (only right shift) andunsigned right shift ">>>".
DIFFERENCE BETWEEN RIGHT SHIFT & UNSIGNED RIGHT SHIFT:-The value ofn>>sisnright-shiftedsbit positions withsign-extension. The value ofn>>>sisnright-shiftedsbit positions withzero-extension.
>>> will always put a 0 in the left most bit, while >> will put a 1 or a 0 depending on what the sign of it is.
oPerators in precedenceK. INDHU11
So far we studiedK. INDHU12Operators in JavaHAPPY LEARNING!!!