SlideShare une entreprise Scribd logo
1  sur  33
Various types of operators




                             1
Objectives

On completion of this period, you would be able to
    know:

•   Various operators in Java




                                                     2
Recap

•   What is an array
•   What is one dimensional array
•   What is two dimensional array




                                    3
Operators
•   An operator performs an operation on data items
    (also known as operands)
•   Java operators can be classified as follows
    •   Arithmetic operators
    •   Relational operators
    •   Logical operators



                                                      4
Contd..
             Operators

•   Assignment operators
•   Increment/Decrement operators
•   Conditional operators
•   Bit-wise operators
•   Special operators




                                              5
Arithmetic Operators

•   Java provides all the basic arithmetic operators
    like + , - , * , / , %
•   These can operate on any built in numeric data
    types like any other languages




                                                       6
Contd..
             Arithmetic Operators

•   We can not use these operators on boolean data
    type
          eg. : These are used as
                   a+b , a-b , a*b , a/b , a% b
•   Here a, b are variables or constants known as
    operands



                                                              7
Relational Operators

•   These operators are used for compare two
    quantities
•   Java supports the following relational operators
•   < , <= , > , >= , = = , !=
•   The value of the relational expression is either true
    or false


                                                        8
Contd..

               Relational Operators

•   The syntax for relational operator is


    Expression1 <relational operator> Expession2

•   Here, Expression1 and Expression2 are arithmetic
    expressions



                                                         9
Contd..

            Relational Operators
•   When arithmetic expressions are used , it must be
    evaluated first and then results compared.
              eg. : a<b
                     a<=b
                     a>b
                     a>=b
                     a= = b
                     a!=b

                                                          10
Logical Operators

•   Java has three logical operators
              &&                - Logical AND
               ||               - Logical OR
                !               - Logical NOT




                                                11
Contd..
               Logical Operators
•   An expression which combines two or more
    relational expressions
•   It is called as logical expression or compound
    expression
              eg. : a >b && c <d
•   The logical expression given above is true only if
    both conditions are true
•   If either of them are false the expression is false

                                                              12
Assignment Operator

•   These are used to assign the value of an
    expression to a variable
•   The assignment operator is ‘= ‘




                                               13
Contd..

             Assignment Operator

•   These operators are used for shorthand assignment
    in the following form


           V op = value;
•   Here, V is variable ,op is operator.
               eg. : a+ = 9;



                                                         14
Contd..

          Assignment Operator

•   The above form is equivalent to


    V = V op value;
    eg. : a+ = 1 means a= a+1




                                                15
Contd..

              Assignment Operator

•   Advantages of shorthand assignment operators are

    •   What appears on the left hand side need not be

        repeated and therefore it becomes easier

    •   The statement is more easier to read



                                                             16
Increment/Decrement Operators

•   Java has two useful operators
•   These are increment(++) and decrement(--)
    operators.
•   The operator ++ adds one to the operand and the
    operator -- subtracts one




                                                      17
Contd..

          Increment/Decrement Operators

•   Both are unary operators and these are in different
    forms.

    eg. : ++m or m++ ,this is equivalent to m+1

        --m or m-- ,this is equivalent to m-1




                                                            18
Contd..

        Increment/Decrement Operators
•   The difference occurs only the operator is a part of
    another expression
        eg. : m = 9, k =++ m ;
•    In this case the value of k would be 10

       eg. : m = 9, k = m++ ;
•   In this case the value of k would be 9 and m
    would be 10


                                                             19
Conditional Operator

•   The character pair ‘?:’ is a ternary operator
    available in Java
•   This operator is used to construct conditional
    expressions of the form
     Expression1 ? Expression2 : Expression3 ;




                                                     20
Contd..
               Conditional Operator

•   Here, ?: works as follows
•   Expression1 is evaluated first if it is true
•   Then the Expression2 is evaluated and becomes
    the value of the conditional expression




                                                             21
Contd..
               Conditional Operator

•   If Expression1 is false, Expression3 is evaluated
•   And its value becomes the value of the conditional
    expression

    eg. : x = (a > b ) ? a : b;




                                                           22
Bitwise Operators

•   Java has a distinction of      supporting special
    operators known as ‘Bitwise Operators’


•   These manipulate data at values of bit level




                                                   23
Contd..

                  Bitwise Operators

•   These operators are used for testing the bits or
    shifting them to the right or left
•   Bitwise operators may not be applied to float or
    double




                                                            24
Contd..

                   Bitwise Operators
•   The bitwise operators are
        &                  Bitwise AND
         |                 Bitwise OR
        ^                  Bitwise exclusive OR
        ~                 Ones complement
        <<                Shift left
        >>                Shift right
       >>>                 Shift right with zero fill

                                                              25
Special Operators

•   Java supports some special operators

•   Such as ‘ instanceOf ‘ operator

•   And ‘Dot’ operator or member selection operators




                                                 26
instanceOf Operator

•   The instanceOf operator is an object reference
    operator

•   It returns true if the object on the left hand side is
    an instance of the class given on the right hand
    side




                                                             27
Contd..
                instanceOf Operator

•   This operator allows us to determine the object
    belongs to a particular class or not
        eg. : s instanceof Student;
•   The above statement is true if the object belongs
    to the class Student
•   Otherwise it is false



                                                          28
Dot Operator

•   The Dot operator is used to access the instance of
    variables and methods of a class
                  eg. : a.dispaly();

•   It is also used to access classes and sub packages
    from packages




                                                         29
Summary

•   Different types of Operators




                                   30
Quiz

1.An Operator Operates______

a)   Variables
b)   Operators
c)   Operands
d)   All the Above



                               31
Frequently Asked Questions

•   List any Three Logical operator
•   List any Four Bitwise Operators
•   Explain various operators available in Java




                                                  32
 
swings
Struts
                      
jdbc
hibernate
home
java previous question papers
 OCT/NOV-2012 QUESTION PAPER
April / May 2012 c-09
October/ November-2011 c-09
April/ May 2011 c-09
April/ May 2011 c-05



                 Home
                                33

Contenu connexe

Tendances

Operators and expressions
Operators and expressionsOperators and expressions
Operators and expressionsvishaljot_kaur
 
Operators and Expressions in Java
Operators and Expressions in JavaOperators and Expressions in Java
Operators and Expressions in JavaAbhilash Nair
 
CBSE Class XI :- Operators in C++
CBSE Class XI :- Operators in C++CBSE Class XI :- Operators in C++
CBSE Class XI :- Operators in C++Pranav Ghildiyal
 
Operators and Expressions in C++
Operators and Expressions in C++Operators and Expressions in C++
Operators and Expressions in C++Praveen M Jigajinni
 
Variables, Data Types, Operator & Expression in c in detail
Variables, Data Types, Operator & Expression in c in detailVariables, Data Types, Operator & Expression in c in detail
Variables, Data Types, Operator & Expression in c in detailgourav kottawar
 
Precedence and associativity (Computer programming and utilization)
Precedence and associativity (Computer programming and utilization)Precedence and associativity (Computer programming and utilization)
Precedence and associativity (Computer programming and utilization)Digvijaysinh Gohil
 
Unit 4. Operators and Expression
Unit 4. Operators and Expression  Unit 4. Operators and Expression
Unit 4. Operators and Expression Ashim Lamichhane
 
itft-Operators in java
itft-Operators in javaitft-Operators in java
itft-Operators in javaAtul Sehdev
 
M.Florence Dayana / Basics of C Language
M.Florence Dayana / Basics of C LanguageM.Florence Dayana / Basics of C Language
M.Florence Dayana / Basics of C LanguageDr.Florence Dayana
 
Operator & Expression in c++
Operator & Expression in c++Operator & Expression in c++
Operator & Expression in c++bajiajugal
 
Expression and Operartor In C Programming
Expression and Operartor In C Programming Expression and Operartor In C Programming
Expression and Operartor In C Programming Kamal Acharya
 
Aae oop xp_04
Aae oop xp_04Aae oop xp_04
Aae oop xp_04Niit Care
 

Tendances (18)

COM1407: C Operators
COM1407: C OperatorsCOM1407: C Operators
COM1407: C Operators
 
Operators and expressions
Operators and expressionsOperators and expressions
Operators and expressions
 
Chap 3(operator expression)
Chap 3(operator expression)Chap 3(operator expression)
Chap 3(operator expression)
 
Operators and Expressions in Java
Operators and Expressions in JavaOperators and Expressions in Java
Operators and Expressions in Java
 
CBSE Class XI :- Operators in C++
CBSE Class XI :- Operators in C++CBSE Class XI :- Operators in C++
CBSE Class XI :- Operators in C++
 
Operators and Expressions in C++
Operators and Expressions in C++Operators and Expressions in C++
Operators and Expressions in C++
 
Variables, Data Types, Operator & Expression in c in detail
Variables, Data Types, Operator & Expression in c in detailVariables, Data Types, Operator & Expression in c in detail
Variables, Data Types, Operator & Expression in c in detail
 
Precedence and associativity (Computer programming and utilization)
Precedence and associativity (Computer programming and utilization)Precedence and associativity (Computer programming and utilization)
Precedence and associativity (Computer programming and utilization)
 
Unit 4. Operators and Expression
Unit 4. Operators and Expression  Unit 4. Operators and Expression
Unit 4. Operators and Expression
 
itft-Operators in java
itft-Operators in javaitft-Operators in java
itft-Operators in java
 
Operators in java
Operators in javaOperators in java
Operators in java
 
M.Florence Dayana / Basics of C Language
M.Florence Dayana / Basics of C LanguageM.Florence Dayana / Basics of C Language
M.Florence Dayana / Basics of C Language
 
Operator & Expression in c++
Operator & Expression in c++Operator & Expression in c++
Operator & Expression in c++
 
What is c
What is cWhat is c
What is c
 
Expression and Operartor In C Programming
Expression and Operartor In C Programming Expression and Operartor In C Programming
Expression and Operartor In C Programming
 
Aae oop xp_04
Aae oop xp_04Aae oop xp_04
Aae oop xp_04
 
C Operators
C OperatorsC Operators
C Operators
 
Programming for Problem Solving
Programming for Problem SolvingProgramming for Problem Solving
Programming for Problem Solving
 

Similaire à 9 cm604.10

L3 operators
L3 operatorsL3 operators
L3 operatorsteach4uin
 
L3 operators
L3 operatorsL3 operators
L3 operatorsteach4uin
 
Operator in c programming
Operator in c programmingOperator in c programming
Operator in c programmingManoj Tyagi
 
4_A1208223655_21789_2_2018_04. Operators.ppt
4_A1208223655_21789_2_2018_04. Operators.ppt4_A1208223655_21789_2_2018_04. Operators.ppt
4_A1208223655_21789_2_2018_04. Operators.pptRithwikRanjan
 
OPERATORS OF C++
OPERATORS OF C++OPERATORS OF C++
OPERATORS OF C++ANANT VYAS
 
IOS Swift Language 3rd tutorial
IOS Swift Language 3rd tutorialIOS Swift Language 3rd tutorial
IOS Swift Language 3rd tutorialHassan A-j
 
operat in vb .pptx
operat in vb .pptxoperat in vb .pptx
operat in vb .pptxclassall
 
OPERATORS IN C.pptx
OPERATORS IN C.pptxOPERATORS IN C.pptx
OPERATORS IN C.pptxSKUP1
 
OPERATORS IN C.pptx
OPERATORS IN C.pptxOPERATORS IN C.pptx
OPERATORS IN C.pptxLECO9
 
Unit ii chapter 1 operator and expressions in c
Unit ii chapter 1 operator and expressions in cUnit ii chapter 1 operator and expressions in c
Unit ii chapter 1 operator and expressions in cSowmya Jyothi
 
OCA JAVA - 3 Programming with Java Operators
 OCA JAVA - 3 Programming with Java Operators OCA JAVA - 3 Programming with Java Operators
OCA JAVA - 3 Programming with Java OperatorsFernando Gil
 
Operation and expression in c++
Operation and expression in c++Operation and expression in c++
Operation and expression in c++Online
 
OPERATORS IN C.pptx
OPERATORS IN C.pptxOPERATORS IN C.pptx
OPERATORS IN C.pptxAshokJ19
 

Similaire à 9 cm604.10 (20)

L3 operators
L3 operatorsL3 operators
L3 operators
 
L3 operators
L3 operatorsL3 operators
L3 operators
 
Operator in c programming
Operator in c programmingOperator in c programming
Operator in c programming
 
Operators and Expressions
Operators and ExpressionsOperators and Expressions
Operators and Expressions
 
4_A1208223655_21789_2_2018_04. Operators.ppt
4_A1208223655_21789_2_2018_04. Operators.ppt4_A1208223655_21789_2_2018_04. Operators.ppt
4_A1208223655_21789_2_2018_04. Operators.ppt
 
OPERATORS OF C++
OPERATORS OF C++OPERATORS OF C++
OPERATORS OF C++
 
Operators in java By cheena
Operators in java By cheenaOperators in java By cheena
Operators in java By cheena
 
IOS Swift Language 3rd tutorial
IOS Swift Language 3rd tutorialIOS Swift Language 3rd tutorial
IOS Swift Language 3rd tutorial
 
operat in vb .pptx
operat in vb .pptxoperat in vb .pptx
operat in vb .pptx
 
OPERATORS IN C.pptx
OPERATORS IN C.pptxOPERATORS IN C.pptx
OPERATORS IN C.pptx
 
OPERATORS IN C.pptx
OPERATORS IN C.pptxOPERATORS IN C.pptx
OPERATORS IN C.pptx
 
Unit ii chapter 1 operator and expressions in c
Unit ii chapter 1 operator and expressions in cUnit ii chapter 1 operator and expressions in c
Unit ii chapter 1 operator and expressions in c
 
OCA JAVA - 3 Programming with Java Operators
 OCA JAVA - 3 Programming with Java Operators OCA JAVA - 3 Programming with Java Operators
OCA JAVA - 3 Programming with Java Operators
 
operators in c++
operators in c++operators in c++
operators in c++
 
operators in c++
operators in c++operators in c++
operators in c++
 
Operators in C Programming
Operators in C ProgrammingOperators in C Programming
Operators in C Programming
 
Operation and expression in c++
Operation and expression in c++Operation and expression in c++
Operation and expression in c++
 
OPERATORS IN C.pptx
OPERATORS IN C.pptxOPERATORS IN C.pptx
OPERATORS IN C.pptx
 
OPERATORS IN C.pptx
OPERATORS IN C.pptxOPERATORS IN C.pptx
OPERATORS IN C.pptx
 
Types of Operators in C
Types of Operators in CTypes of Operators in C
Types of Operators in C
 

Plus de myrajendra (20)

Fundamentals
FundamentalsFundamentals
Fundamentals
 
Data type
Data typeData type
Data type
 
Hibernate example1
Hibernate example1Hibernate example1
Hibernate example1
 
Jdbc workflow
Jdbc workflowJdbc workflow
Jdbc workflow
 
2 jdbc drivers
2 jdbc drivers2 jdbc drivers
2 jdbc drivers
 
3 jdbc api
3 jdbc api3 jdbc api
3 jdbc api
 
4 jdbc step1
4 jdbc step14 jdbc step1
4 jdbc step1
 
Dao example
Dao exampleDao example
Dao example
 
Sessionex1
Sessionex1Sessionex1
Sessionex1
 
Internal
InternalInternal
Internal
 
3. elements
3. elements3. elements
3. elements
 
2. attributes
2. attributes2. attributes
2. attributes
 
1 introduction to html
1 introduction to html1 introduction to html
1 introduction to html
 
Headings
HeadingsHeadings
Headings
 
Forms
FormsForms
Forms
 
Css
CssCss
Css
 
Views
ViewsViews
Views
 
Views
ViewsViews
Views
 
Views
ViewsViews
Views
 
Starting jdbc
Starting jdbcStarting jdbc
Starting jdbc
 

9 cm604.10

  • 1. Various types of operators 1
  • 2. Objectives On completion of this period, you would be able to know: • Various operators in Java 2
  • 3. Recap • What is an array • What is one dimensional array • What is two dimensional array 3
  • 4. Operators • An operator performs an operation on data items (also known as operands) • Java operators can be classified as follows • Arithmetic operators • Relational operators • Logical operators 4
  • 5. Contd.. Operators • Assignment operators • Increment/Decrement operators • Conditional operators • Bit-wise operators • Special operators 5
  • 6. Arithmetic Operators • Java provides all the basic arithmetic operators like + , - , * , / , % • These can operate on any built in numeric data types like any other languages 6
  • 7. Contd.. Arithmetic Operators • We can not use these operators on boolean data type eg. : These are used as a+b , a-b , a*b , a/b , a% b • Here a, b are variables or constants known as operands 7
  • 8. Relational Operators • These operators are used for compare two quantities • Java supports the following relational operators • < , <= , > , >= , = = , != • The value of the relational expression is either true or false 8
  • 9. Contd.. Relational Operators • The syntax for relational operator is Expression1 <relational operator> Expession2 • Here, Expression1 and Expression2 are arithmetic expressions 9
  • 10. Contd.. Relational Operators • When arithmetic expressions are used , it must be evaluated first and then results compared. eg. : a<b a<=b a>b a>=b a= = b a!=b 10
  • 11. Logical Operators • Java has three logical operators && - Logical AND || - Logical OR ! - Logical NOT 11
  • 12. Contd.. Logical Operators • An expression which combines two or more relational expressions • It is called as logical expression or compound expression eg. : a >b && c <d • The logical expression given above is true only if both conditions are true • If either of them are false the expression is false 12
  • 13. Assignment Operator • These are used to assign the value of an expression to a variable • The assignment operator is ‘= ‘ 13
  • 14. Contd.. Assignment Operator • These operators are used for shorthand assignment in the following form V op = value; • Here, V is variable ,op is operator. eg. : a+ = 9; 14
  • 15. Contd.. Assignment Operator • The above form is equivalent to V = V op value; eg. : a+ = 1 means a= a+1 15
  • 16. Contd.. Assignment Operator • Advantages of shorthand assignment operators are • What appears on the left hand side need not be repeated and therefore it becomes easier • The statement is more easier to read 16
  • 17. Increment/Decrement Operators • Java has two useful operators • These are increment(++) and decrement(--) operators. • The operator ++ adds one to the operand and the operator -- subtracts one 17
  • 18. Contd.. Increment/Decrement Operators • Both are unary operators and these are in different forms. eg. : ++m or m++ ,this is equivalent to m+1 --m or m-- ,this is equivalent to m-1 18
  • 19. Contd.. Increment/Decrement Operators • The difference occurs only the operator is a part of another expression eg. : m = 9, k =++ m ; • In this case the value of k would be 10 eg. : m = 9, k = m++ ; • In this case the value of k would be 9 and m would be 10 19
  • 20. Conditional Operator • The character pair ‘?:’ is a ternary operator available in Java • This operator is used to construct conditional expressions of the form Expression1 ? Expression2 : Expression3 ; 20
  • 21. Contd.. Conditional Operator • Here, ?: works as follows • Expression1 is evaluated first if it is true • Then the Expression2 is evaluated and becomes the value of the conditional expression 21
  • 22. Contd.. Conditional Operator • If Expression1 is false, Expression3 is evaluated • And its value becomes the value of the conditional expression eg. : x = (a > b ) ? a : b; 22
  • 23. Bitwise Operators • Java has a distinction of supporting special operators known as ‘Bitwise Operators’ • These manipulate data at values of bit level 23
  • 24. Contd.. Bitwise Operators • These operators are used for testing the bits or shifting them to the right or left • Bitwise operators may not be applied to float or double 24
  • 25. Contd.. Bitwise Operators • The bitwise operators are & Bitwise AND | Bitwise OR ^ Bitwise exclusive OR ~ Ones complement << Shift left >> Shift right >>> Shift right with zero fill 25
  • 26. Special Operators • Java supports some special operators • Such as ‘ instanceOf ‘ operator • And ‘Dot’ operator or member selection operators 26
  • 27. instanceOf Operator • The instanceOf operator is an object reference operator • It returns true if the object on the left hand side is an instance of the class given on the right hand side 27
  • 28. Contd.. instanceOf Operator • This operator allows us to determine the object belongs to a particular class or not eg. : s instanceof Student; • The above statement is true if the object belongs to the class Student • Otherwise it is false 28
  • 29. Dot Operator • The Dot operator is used to access the instance of variables and methods of a class eg. : a.dispaly(); • It is also used to access classes and sub packages from packages 29
  • 30. Summary • Different types of Operators 30
  • 31. Quiz 1.An Operator Operates______ a) Variables b) Operators c) Operands d) All the Above 31
  • 32. Frequently Asked Questions • List any Three Logical operator • List any Four Bitwise Operators • Explain various operators available in Java 32
  • 33.   swings Struts   jdbc hibernate home java previous question papers  OCT/NOV-2012 QUESTION PAPER April / May 2012 c-09 October/ November-2011 c-09 April/ May 2011 c-09 April/ May 2011 c-05 Home 33