Presentation is loading. Please wait.

Presentation is loading. Please wait.

Operator Kinds of Operator Precedence of Operator Type Casting.

Similar presentations


Presentation on theme: "Operator Kinds of Operator Precedence of Operator Type Casting."— Presentation transcript:

1 Operator Kinds of Operator Precedence of Operator Type Casting

2  Decide the semantics of expression  Meaning of operator given in language system Operator

3 Kinds of Operator Arithmetic Op. : + - * / % Relational Op. : > >= >= < <= == != Logical Op. : && || ! Inc/Dec Op. : ++ -- Bit Op. : & | ^ ~ > >>> Operators of Java Conditional Op. : ?: Conditional Op. : ?: Assign Op. : = += -= *= /= %= &= ^= |= >>= >>= Casting Op. : (Data Type) Array Op. : [] Method Op. : (). instanceof Op. : instanceof

4  Operator for arithmetic operation  Single term operator : +, -  Binary term operator : +, -, *, /, %  [ArithmeticOperators.java] Arithmetic Operator x = -5 ; x = -(-5) ; x = -(3-5) ; x = -5 ; x = -(-5) ; x = -(3-5) ;

5  Real type operation  Floating point discription and operation: IEEE754 Standard  underflow, overflow  Infinitive arithmetic  java.lang.Float, java.lang.Double, POSITIVE_INFINITY, NEGATIVE_INFINITY constant  NaN(Not a Number) Arithmetic Operator

6  Compare two value  Result : true or false  Expression include relational operator  for, while,...  Operator , , , , ,   precedence   [RelationalOperators.java] Relational Operator a > b + c ===>a > (b + c) b == x b == (x < y)

7  Conditional Logical Relationship of two operands  Operator  !, &&, ||  [LogicalOperators.java] Conditional Operator a < b && b < c 1 2 3

8  Operator  ++, --  Prefix operator  Postfix operator  Cannot use at expression, only at variable  Cannot apply at real type  [IncDecOperators.java] Increment & Decrement Operator n = 1; x = ++n; // x=2, n=2 n = 1; x = ++n; // x=2, n=2 n = 1; x = n++; // x=1, n=2 n = 1; x = n++; // x=1, n=2 (a + b)++ // error

9  Operator  &, |, >, >>>, ^, ~  Operand should be integer type  Precedence Bitwise Operator Operator Precedence Operator Precedence ~ > >>> & ^ | (H) (L)

10  Bitwise AND  1001 2 & 0011 2 = 0001 2  To extract the special area in variable by masking that area  Bit OR  1001 2 | 0011 2 = 1011 2  Exclusive AND  1001 2 ^ 0011 2 = 1010 2  1’s Complement  ~ 00001010 2 = 11110101 2  [BitOperators.java] Bitwise Operator

11  Bitwise Shift Operator  Shift lefe(<<)  Shift right(>>)  Unsigned shift right(>>>)  Give this operator because Java does not support unsigned integer.  [ShiftOperators.java] Bitwise Operator x << y = x * 2 y x >> y = x / 2 y

12  Operator  Expr1 ? Expr2 : Expr3 (3 Terms Operator)  [ConditionalOperator.java]  [PrintTenItem.java] The Conditional Operator m = a > b ? (c > a ? c : a) : (c > b ? c : b) ; max = x > y ? x : y ; if (x > y) max = x; else max = y; if (x > y) max = x; else max = y;

13  Operator  Arithmetic operator : + - * / %  Bitwise operator : & | ^ > >>>  [AssignmentOperators.java] Assignment Operators Expr 1 = Expr 1 op Expr2 Expr 1 op= Expr 2 x = x * y + 1; x *= y + 1; x = x * (y+1) sum = sum + i ; sum += i ;

14 Operator Precedence Operator Association Precedence () []. ! ~ ++ -- + - (Data Type) * / % + - > >>> >= instance == != & ^ | && || ? : = += -= *= /= %= &= ^= |= >= >>>= Left Assoc. (High) Left Assoc. Left Assoc. (Low)


Download ppt "Operator Kinds of Operator Precedence of Operator Type Casting."

Similar presentations


Ads by Google