SlideShare a Scribd company logo
Operator
Kinds of Operator
Precedence of Operator
Type Casting
Operator
 Decide the semantics of expression
 Meaning of operator given in language system
Kinds of Operator
Arithmetic Op. : + - * / %
Relational Op. : > >= < <= == !=
Logical Op. : && || !
Inc/Dec Op. : ++ --
Bit Op. : & | ^ ~ << >> >>>
Operators of Java
Conditional Op. : ?:
Assign Op. : = += -= *= /= %= &= ^= |= >>= <<= >>>=
Casting Op. : (Data Type)
Array Op. : []
Method Op. : () .
instanceof Op. : instanceof
Arithmetic Operator
 Operator for arithmetic operation
 Single term operator : +, -
 Binary term operator : +, -, *, /, %
 [ArithmeticOperators.java]
x = -5 ;
x = -(-5) ;
x = -(3-5) ;
Arithmetic Operator
 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
 Add, Substract
 Multiply, Divide
x y x+y x-y
+I.F +I.F +I.F NaN
+I.F - I.F NaN +I.F
- I.F +I.F NaN - I.F
- I.F - I.F - I.F NaN
NaN +I.F NaN NaN
x y x/y x%y
Finite 0.0  I.F NaN
Finite I.F 0.0 
0.0 0.0 NaN NaN
I.F Finite  I.F NaN
I.F I.F NaN NaN
 [InfinityArithmetic.java]
Relational Operator
 Compare two value
 Result : true or false
 Expression include relational operator
 for, while, ...
 Operator
 , , , , , 
 precedence 
 [RelationalOperators.java]
a > b + c ===> a > (b + c)
b == x < y ===> b == (x < y)
Conditional Operator
 Conditional Logical Relationship of two
operands
 Operator
 ! , && , ||
 [LogicalOperators.java]
a < b && b < c
1 2
3
Increment & Decrement Operator
 Operator
 ++, --
 Prefix operator
 Postfix operator
 Cannot use at expression, only at variable
 Cannot apply at real type
 [IncDecOperators.java]
n = 1;
x = ++n; // x=2, n=2
n = 1;
x = n++; // x=1, n=2
(a + b)++ // error
Bitwise Operator
 Operator
 &, |, <<, >>, >>>, ^, ~
 Operand should be integer type
 Precedence
Operator Precedence
~
<< >> >>>
&
^
|
(H)
(L)
Bitwise Operator
 Bitwise AND
 10012 & 00112 = 00012
 To extract the special area in variable by masking that
area
 Bit OR
 10012 | 00112 = 10112
 Exclusive AND
 10012 ^ 00112 = 10102
 1’s Complement
 ~ 000010102 = 111101012
 [BitOperators.java]
Bitwise Operator
 Bitwise Shift Operator
 Shift lefe(<<)
 Shift right(>>)
 Unsigned shift right(>>>)
 Give this operator because Java does not support unsigned integer.
 [ShiftOperators.java]
x << y = x * 2y
x >> y = x / 2y
The Conditional Operator
 Operator
 Expr1 ? Expr2 : Expr3 (3 Terms Operator)
 [ConditionalOperator.java]
 [PrintTenItem.java]
m = a > b ? (c > a ? c : a) : (c > b ? c : b) ;
max = x > y ? x : y ;
if (x > y) max = x;
else max = y;
Assignment Operators
 Operator
 Arithmetic operator : + - * / %
 Bitwise operator : & | ^ << >> >>>
 [AssignmentOperators.java]
Expr 1 = Expr 1 op Expr2 Expr1 op= Expr 2
x = x * y + 1; x *= y + 1;
x = x * (y+1)
sum = sum + i ; sum += i ;
Cast Operator
 Data Type Casting Operator
 Cast operator : ( , )
 [CastOperator.java]
(Data Type) 식
(int) 3.75 ===> 3
(float) 3 ===> 3.0
(float) (1 / 2) ===> 0.0
(float)1/2 ===> 0.5
Operator Precedence
Operator Association Precedence
() [] .
! ~ ++ -- + - (Data Type)
* / %
+ -
<< >> >>>
< <= > >= instance
== !=
&
^
|
&&
||
? :
= += -= *= /= %= &= ^= |= <<= >>= >>>=
Left Assoc. (High)
Left Assoc.
Left Assoc.
Left Assoc.
Left Assoc.
Left Assoc.
Left Assoc.
Left Assoc.
Left Assoc.
Left Assoc.
Left Assoc.
Left Assoc.
Left Assoc.
Left Assoc. (Low)

More Related Content

PDF
Java basic operators
PDF
Java basic operators
PDF
10)OPERATORS.pdf
PPTX
Opeartor &amp; expression
PDF
itft-Operators in java
PPT
9 cm604.10
PDF
Java 2
PPTX
PPT ON JAVA AND UNDERSTANDING JAVA'S PRINCIPLES
Java basic operators
Java basic operators
10)OPERATORS.pdf
Opeartor &amp; expression
itft-Operators in java
9 cm604.10
Java 2
PPT ON JAVA AND UNDERSTANDING JAVA'S PRINCIPLES

Similar to operators.ppt (20)

PPTX
Oop using JAVA
PPTX
Operators
PPTX
Computer programming 2 Lesson 7
PPTX
OOPJ_PPT2,JAVA OPERATORS TPYE WITH EXAMPLES.pptx
PPTX
Logical Operators C/C++ language Programming
PPT
Shubhrat operator &amp; expression
PPTX
presentation on array java program operators
PPTX
Java Operators with Simple introduction.pptx
PPTX
Java Operators with Simple introduction.pptx
PPT
4_A1208223655_21789_2_2018_04. Operators.ppt
PPT
PPT
Java - Operators
PPTX
Python operators part2
DOCX
Operators
PPTX
Lecture - Operators in C++ (Book: Tony Gaddis).pptx
PPT
object oriented programming java lectures
PPTX
OPERATORS OF C++
PPTX
OCA JAVA - 3 Programming with Java Operators
PPTX
DOC
Week2 dq4
Oop using JAVA
Operators
Computer programming 2 Lesson 7
OOPJ_PPT2,JAVA OPERATORS TPYE WITH EXAMPLES.pptx
Logical Operators C/C++ language Programming
Shubhrat operator &amp; expression
presentation on array java program operators
Java Operators with Simple introduction.pptx
Java Operators with Simple introduction.pptx
4_A1208223655_21789_2_2018_04. Operators.ppt
Java - Operators
Python operators part2
Operators
Lecture - Operators in C++ (Book: Tony Gaddis).pptx
object oriented programming java lectures
OPERATORS OF C++
OCA JAVA - 3 Programming with Java Operators
Week2 dq4
Ad

Recently uploaded (20)

PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
O7-L3 Supply Chain Operations - ICLT Program
PPTX
PPH.pptx obstetrics and gynecology in nursing
PDF
Sports Quiz easy sports quiz sports quiz
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
Basic Mud Logging Guide for educational purpose
PDF
Classroom Observation Tools for Teachers
PPTX
Cell Types and Its function , kingdom of life
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PPTX
Lesson notes of climatology university.
PPTX
Cell Structure & Organelles in detailed.
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
Insiders guide to clinical Medicine.pdf
PPTX
master seminar digital applications in india
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PPTX
Pharma ospi slides which help in ospi learning
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
O5-L3 Freight Transport Ops (International) V1.pdf
Renaissance Architecture: A Journey from Faith to Humanism
Microbial diseases, their pathogenesis and prophylaxis
O7-L3 Supply Chain Operations - ICLT Program
PPH.pptx obstetrics and gynecology in nursing
Sports Quiz easy sports quiz sports quiz
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Basic Mud Logging Guide for educational purpose
Classroom Observation Tools for Teachers
Cell Types and Its function , kingdom of life
Supply Chain Operations Speaking Notes -ICLT Program
Lesson notes of climatology university.
Cell Structure & Organelles in detailed.
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Insiders guide to clinical Medicine.pdf
master seminar digital applications in india
102 student loan defaulters named and shamed – Is someone you know on the list?
Pharma ospi slides which help in ospi learning
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
Ad

operators.ppt

  • 1. Operator Kinds of Operator Precedence of Operator Type Casting
  • 2. Operator  Decide the semantics of expression  Meaning of operator given in language system
  • 3. Kinds of Operator Arithmetic Op. : + - * / % Relational Op. : > >= < <= == != Logical Op. : && || ! Inc/Dec Op. : ++ -- Bit Op. : & | ^ ~ << >> >>> Operators of Java Conditional Op. : ?: Assign Op. : = += -= *= /= %= &= ^= |= >>= <<= >>>= Casting Op. : (Data Type) Array Op. : [] Method Op. : () . instanceof Op. : instanceof
  • 4. Arithmetic Operator  Operator for arithmetic operation  Single term operator : +, -  Binary term operator : +, -, *, /, %  [ArithmeticOperators.java] x = -5 ; x = -(-5) ; x = -(3-5) ;
  • 5. Arithmetic Operator  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)
  • 6. Arithmetic Operator  Add, Substract  Multiply, Divide x y x+y x-y +I.F +I.F +I.F NaN +I.F - I.F NaN +I.F - I.F +I.F NaN - I.F - I.F - I.F - I.F NaN NaN +I.F NaN NaN x y x/y x%y Finite 0.0  I.F NaN Finite I.F 0.0  0.0 0.0 NaN NaN I.F Finite  I.F NaN I.F I.F NaN NaN  [InfinityArithmetic.java]
  • 7. Relational Operator  Compare two value  Result : true or false  Expression include relational operator  for, while, ...  Operator  , , , , ,   precedence   [RelationalOperators.java] a > b + c ===> a > (b + c) b == x < y ===> b == (x < y)
  • 8. Conditional Operator  Conditional Logical Relationship of two operands  Operator  ! , && , ||  [LogicalOperators.java] a < b && b < c 1 2 3
  • 9. Increment & Decrement Operator  Operator  ++, --  Prefix operator  Postfix operator  Cannot use at expression, only at variable  Cannot apply at real type  [IncDecOperators.java] n = 1; x = ++n; // x=2, n=2 n = 1; x = n++; // x=1, n=2 (a + b)++ // error
  • 10. Bitwise Operator  Operator  &, |, <<, >>, >>>, ^, ~  Operand should be integer type  Precedence Operator Precedence ~ << >> >>> & ^ | (H) (L)
  • 11. Bitwise Operator  Bitwise AND  10012 & 00112 = 00012  To extract the special area in variable by masking that area  Bit OR  10012 | 00112 = 10112  Exclusive AND  10012 ^ 00112 = 10102  1’s Complement  ~ 000010102 = 111101012  [BitOperators.java]
  • 12. Bitwise Operator  Bitwise Shift Operator  Shift lefe(<<)  Shift right(>>)  Unsigned shift right(>>>)  Give this operator because Java does not support unsigned integer.  [ShiftOperators.java] x << y = x * 2y x >> y = x / 2y
  • 13. The Conditional Operator  Operator  Expr1 ? Expr2 : Expr3 (3 Terms Operator)  [ConditionalOperator.java]  [PrintTenItem.java] m = a > b ? (c > a ? c : a) : (c > b ? c : b) ; max = x > y ? x : y ; if (x > y) max = x; else max = y;
  • 14. Assignment Operators  Operator  Arithmetic operator : + - * / %  Bitwise operator : & | ^ << >> >>>  [AssignmentOperators.java] Expr 1 = Expr 1 op Expr2 Expr1 op= Expr 2 x = x * y + 1; x *= y + 1; x = x * (y+1) sum = sum + i ; sum += i ;
  • 15. Cast Operator  Data Type Casting Operator  Cast operator : ( , )  [CastOperator.java] (Data Type) 식 (int) 3.75 ===> 3 (float) 3 ===> 3.0 (float) (1 / 2) ===> 0.0 (float)1/2 ===> 0.5
  • 16. Operator Precedence Operator Association Precedence () [] . ! ~ ++ -- + - (Data Type) * / % + - << >> >>> < <= > >= instance == != & ^ | && || ? : = += -= *= /= %= &= ^= |= <<= >>= >>>= Left Assoc. (High) Left Assoc. Left Assoc. Left Assoc. Left Assoc. Left Assoc. Left Assoc. Left Assoc. Left Assoc. Left Assoc. Left Assoc. Left Assoc. Left Assoc. Left Assoc. (Low)