SlideShare ist ein Scribd-Unternehmen logo
1 von 16
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)

Weitere ähnliche Inhalte

Ähnlich wie operators.ppt (20)

Chapter 3.3
Chapter 3.3Chapter 3.3
Chapter 3.3
 
Operators inc c language
Operators inc c languageOperators inc c language
Operators inc c language
 
Operators and expressions in c language
Operators and expressions in c languageOperators and expressions in c language
Operators and expressions in c language
 
Java - Operators
Java - OperatorsJava - Operators
Java - Operators
 
Java 2
Java 2Java 2
Java 2
 
object oriented programming java lectures
object oriented programming java lecturesobject oriented programming java lectures
object oriented programming java lectures
 
Operators in Python
Operators in PythonOperators in Python
Operators in Python
 
Operators
OperatorsOperators
Operators
 
Pj01 4-operators and control flow
Pj01 4-operators and control flowPj01 4-operators and control flow
Pj01 4-operators and control flow
 
Operators
OperatorsOperators
Operators
 
Operators in java
Operators in javaOperators in java
Operators in java
 
Mesics lecture 4 c operators and experssions
Mesics lecture  4   c operators and experssionsMesics lecture  4   c operators and experssions
Mesics lecture 4 c operators and experssions
 
Operators1.pptx
Operators1.pptxOperators1.pptx
Operators1.pptx
 
Intro to c chapter cover 1 4
Intro to c chapter cover 1 4Intro to c chapter cover 1 4
Intro to c chapter cover 1 4
 
C – operators and expressions
C – operators and expressionsC – operators and expressions
C – operators and expressions
 
Unit 2
Unit 2Unit 2
Unit 2
 
Lec 28 - operator overloading
Lec 28 - operator overloadingLec 28 - operator overloading
Lec 28 - operator overloading
 
Operators in C++
Operators in C++Operators in C++
Operators in C++
 
C Operators
C OperatorsC Operators
C Operators
 
Programming presentation
Programming presentationProgramming presentation
Programming presentation
 

Kürzlich hochgeladen

Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docxPoojaSen20
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxnegromaestrong
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterMateoGardella
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingTeacherCyreneCayanan
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.MateoGardella
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 

Kürzlich hochgeladen (20)

Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch Letter
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 

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)