SlideShare una empresa de Scribd logo
1 de 26
Operators in Java


Pre-assessment Questions
    1.   Predict the output of the expression, 16 % 3?
         a.   5
         b.   0
         c.   1
         d.   4
    •    What is the default value of the float data type?
         a.   0.0
         b.   0
         c.   1.0
         d.   1




 ©NIIT                    Java Fundamentals                  Lesson 3B / Slide 1 of 26
Operators in Java


Pre-assessment Questions (Contd.)
    3.   Consider the statements:
         Statement A: The name of a variable can begin with a digit.
         Statement B: The name of a variable can contain white spaces.
         Identify the correct option.
         a.   Statement A is true and statement B is false
         b.   Statement A is false and statement B is true
         c.   Both, statements, A and B, are true
         d.   Both, statements, A and B, are false




 ©NIIT                   Java Fundamentals                 Lesson 3B / Slide 2 of 26
Operators in Java


Pre-assessment Questions (Contd.)
    1.   _______variables are the local variables that are accessed by the function in
         which the variables are declared.
         a.   Static
         b.   Automatic
         c.   Instance
         d.   Class

    2.   _______literals are enclosed in single quotes
         a.  String
         b.  Character
         c.  Boolean
         d.  Integer




 ©NIIT                   Java Fundamentals                   Lesson 3B / Slide 3 of 26
Operators in Java


Solutions to Pre-assessment
Questions
    1.   c.
    2.   a.
    3.   d.
    4.   a.
    5.   b.




 ©NIIT         Java Fundamentals   Lesson 3B / Slide 4 of 26
Operators in Java


Objectives
    In this lesson, you will learn to:


         •   Use operators
               • Arithmetic assignment operators
               • bit-wise operators
               • shift operators
               • instance-of operator
         •   Identify the operators precedence




 ©NIIT                     Java Fundamentals       Lesson 3B / Slide 5 of 26
Operators in Java


Using Unary Operators
    •    Using the Increment and Decrement Operators
          • The increment and decrement operators are unary operators.
          • The increment operator (++) increases the value of an operand by 1.
          • The decrement operator (--) decreases the value of an operand by 1.
          • Prefix Form
                • The operator precedes the operand.
                • Operator operates on the operand before the value of operand is
                  used in the expression.
          • Postfix Form
                • In the postfix form, operator follows the operand.
                • Operator operates on the operand after the value of operand is used
                  in the expression.




 ©NIIT                     Java Fundamentals                 Lesson 3B / Slide 6 of 26
Operators in Java


Using the Arithmetic Assignment
Operators
    •    Arithmetic Assignment Operators
           • Addition(+), subtraction(-), multiplication(*), division(/), and modulo(%)
              are the arithmetic operators supported by Java.
           • Various arithmetic operators, such as +, -, /, *, and % are combined with
              the assignment operator (=) and are called arithmetic assignment
              operators.




 ©NIIT                     Java Fundamentals                  Lesson 3B / Slide 7 of 26
Operators in Java


Using the Arithmetic Assignment
Operators (Contd.)
         Operator       Use                       Description



         +=         op1 += op2        Adds operand, op1 and operand, op2
                                      and assigns the result to op1. This
                                      expression is equivalent to op1 =
                                      op1+op2.

         -=         op1 -= op2        Subtracts operand, op2 from
                                      operand, op1 and assigns the result
                                      to op1. This expression is equivalent
                                      to op1 = op1 – op2.


 ©NIIT                 Java Fundamentals                  Lesson 3B / Slide 8 of 26
Operators in Java


Using the Arithmetic Assignment
Operators (Contd.)
         Operator       Use                    Description


     *=             op1 *= op2      Multiplies operand, op1 and
                                    operand, op2 and assigns value of
                                    the result to op1. This expression
                                    is equivalent to op1 = op1*op2.

     /=             op1 /= op2      Divides operand, op1 by operand,
                                    op2, and assign the value of the
                                    result to op1. This expression is
                                    equivalent to op1 = op1/op2.



 ©NIIT                  Java Fundamentals                 Lesson 3B / Slide 9 of 26
Operators in Java


Using the Arithmetic Assignment
Operators (Contd.)


          Operator            Use           Description



         %=            op1 %= op2    Assigns the remainder of
                                     division of operand, op1
                                     and operand, op2 to op1.
                                     This expression is
                                     equivalent to op1 = op1%
                                     op2.


 ©NIIT           Java Fundamentals         Lesson 3B / Slide 10 of 26
Operators in Java


Using Bit-wise Operators
    •    Bit-wise operators
         • Operate on the individual bits of their operand.
         • Operands can be various data types like int, short, long, char, and byte.
         • Operands are converted into their binary equivalents before operation.
         • The result in the binary form after the operation is converted back into
              its decimal equivalent.




 ©NIIT                   Java Fundamentals                Lesson 3B / Slide 11 of 26
Operators in Java


Using Bit-wise Operators(Contd.)
    •    The following table lists the various bit-wise operators in Java:


                Operator           Use                 Operation

                &(AND)           x&y            Performs bit-wise AND
                                                operation. It evaluates to 1 if
                                                both bits, x and y are 1. If
                                                either or both bits are 0, the
                                                result is 0.


                |(OR)            x|y            Performs bit-wise OR
                                                operation. It evaluates to 0 if
                                                both bits, x and y are 0. If
                                                either or both bits are 1, the
                                                result is 1.




 ©NIIT                     Java Fundamentals                    Lesson 3B / Slide 12 of 26
Operators in Java


Using Bit-wise Operators(Contd.)

         Operator          Use                     Operation

         ~(inversion)    ~x                 Performs unary NOT
                                            operation. Converts all the
                                            1s into 0s and all the 0s into
                                            1s.

         ^(XOR)          x^y                Performs bit-wise XOR
                                            operation. It evaluates to 1 if
                                            bits have different values
                                            and 0 if both the bits have
                                            the same value.




 ©NIIT                  Java Fundamentals                    Lesson 3B / Slide 13 of 26
Operators in Java


Using Bit-wise Operators (Contd.)
•      Using the Bit-wise AND Operator
       • The Bit-wise AND operator (&) performs AND operation on two operands.
       • Displays 1 if both bits are 1 else 0 in all other cases.

                         Operation                       Result

                             0&0                             0

                             0&1                             0

                             1&1                             1

                             1&0                             0




    ©NIIT                 Java Fundamentals              Lesson 3B / Slide 14 of 26
Operators in Java


Using Bit-wise Operators (Contd.)
•      Using the Bit-wise OR Operator
       • The Bit-wise OR operator (|) performs OR operation on two operands.
       • Displays 0 if both bits are 0 else 1 in all other cases.

                         Operation                       Result

                              0|0                             0

                              0|1                             1

                              1|1                             1

                              1|0                             1




    ©NIIT                  Java Fundamentals              Lesson 3B / Slide 15 of 26
Operators in Java


Using Bit-wise Operators (Contd.)
•      Using the Bit-wise NOT Operator
       • Bit-wise NOT operator (~) is a unary operator and performs NOT operation
            on each bit of binary number.
       • The NOT operator inverts or complements each of the bits of a binary
            number.


                   Operation                           Result

            ~0                                 1

            ~1                                 0




    ©NIIT                  Java Fundamentals              Lesson 3B / Slide 16 of 26
Operators in Java


Using Bit-wise Operators (Contd.)
•      Using the Bit-wise XOR Operator
       • The Bit-wise XOR (^) operator performs XOR operation on two operands.
       • The XOR operator applied on two bits results in 1 if exactly one bit is 1 else 0
            in all other cases .


                        Operation                           Result

                             0^0                                 0

                             0 ^1                                1

                             1^1                                 0

                             1^0                                 1




    ©NIIT                   Java Fundamentals                 Lesson 3B / Slide 17 of 26
Operators in Java


Using Shift Operators
    •     Works on the bits of data.
    •     Shifts the bits of it’s operand either to left or right.



          Operator                 Use                         Operation

         >>                   val1 >> val2           Shifts the bits of the val1 operand
                                                     to the right by the number of
         (Right Shift)
                                                     positions specified by val2.

         <<                   val1<< val2            Shifts the bits of the val1 operand
                                                     to the left by the number of
         (Left Shift)
                                                     positions specified by val2.




 ©NIIT                      Java Fundamentals                        Lesson 3B / Slide 18 of 26
Operators in Java


Using Shift Operators (Contd.)

     Operator             Use                        Operation

    >>>               val1 >>> val2        Shifts the bits of the val1 operand
                                           to the right by the number of
    (Unsigned Shift
                                           positions specified by val2. A zero
    Operator)
                                           value is input in the high-order bit
                                           irrespective of the value of the
                                           high-order bit of val1. The high-
                                           order bit is the leftmost bit of the
                                           binary number.




 ©NIIT                 Java Fundamentals                   Lesson 3B / Slide 19 of 26
Operators in Java


Using Shift Operators (Contd.)
•      Using the Right Shift and Left Shift Operators
       • The right shift and the left shift operators are binary operators.
            • The right shift operator shifts all the bits of a binary number in the right
                  direction.
                  operand >> num
            • The left shift operator, <<, shifts all the bits of a binary number in the
                  left direction.
                  operand << num
•      Using the Unsigned Shift Operator
       • Unsigned shift operator (>>>) is used to shift the bits of a binary number to
            the right.
       • The operator fills the leftmost bits of a binary value with 0 irrespective of
            whether the number has 0 or 1 at the leftmost bit.




    ©NIIT                    Java Fundamentals                 Lesson 3B / Slide 20 of 26
Operators in Java


Using instance of Operator
    •    Used to test whether an object is an instance of a specific class.
    •    Used at the run time.
    •    The syntax of the instanceof operator is:
         op1 instanceof op2
    •    op1 is the name of an object and op2 is the name of a class.
    •    Returns a true value if the op1 object is an instance of the op2 class.




 ©NIIT                    Java Fundamentals                  Lesson 3B / Slide 21 of 26
Operators in Java


Operators Precedence
    •    Each operator in an expression is evaluated in a predetermined order called
         operator precedence.
    •    Operators on the same line have equal precedence.




                   Operators                              Category

         [], (), . , expr++, expr--             Array index, method call, member
                                                access, and postfix operators

         ++expr, --expr, +, -, !, ~             Unary postfix operators

         *, /, %                                Multiplicative Arithmetic operators

         +, -                                   Additive Arithmetic operators


 ©NIIT                      Java Fundamentals                   Lesson 3B / Slide 22 of 26
Operators in Java


Operators Precedence(Contd.)
                  Operators                            Category

         <<, >>, >>>                         Shift operators

         >, <, <=, >=, instanceof            Relational operators

         ==, !=                              Equality operator

         &                                   Bit-wise AND operator

         ^                                   Bit-wise XOR operator

         |                                   Bit-wise OR operator

         &&                                  Conditional AND operator

         ||                                  Conditional OR operator

         =, +=, -=, *=, /=, %=               Assignment operators

 ©NIIT                   Java Fundamentals                     Lesson 3B / Slide 23 of 26
Operators in Java


Demonstration-Precedence of
Operators in Java
    •    Problem Statement
          • Create a Java application to understand the order of
               precedence of various operators in Java.
    •    Solution
          • The Java application is created using the various operators in
               Java.
          • To solve the above problem, perform the following tasks:
          3. Code an application with an expression having multiple
               operators of different precedence
          4. Compile and execute the code.




 ©NIIT                 Java Fundamentals            Lesson 3B / Slide 24 of 26
Operators in Java


Summary
    •    In this lesson, you learned:
           • Operators are used to calculate, compare and compute values. The
              operators are classified as:
                 • Unary operators
                 • Binary operators
           • Unary operators operate on one operand, such as increment and
              decrement operators.
           • Binary operators operate on two operands, such as arithmetic operators
              +,-,/,*.
           • Arithmetic operators, such as, +, _, combined with assignment
              operator(=) are arithmetic assignment operators.
           • Bit-wise operators operate on one bit at a time.
           • The bit-wise operators operate on data types such as, int, short, long,
              char and byte.
           • The various bit-wise operators are bit-wise AND (&), bit-wise OR (|), bit-
              wise NOT (~), and bit-wise XOR (^).
 ©NIIT                     Java Fundamentals                  Lesson 3B / Slide 25 of 26
Operators in Java


Summary (Contd.)
    •    Shift operators are used to shift the bits of the number to the left or right.
         The various shift operators are right shift (>>), left shift (<<), and unsigned
         shift operator (>>>).
    •    The instanceof operator is used to test that whether an object is an instance
         of a particular class.
    •    An expression can have several operators and each operator is evaluated in
         order of their precedence.




 ©NIIT                    Java Fundamentals                  Lesson 3B / Slide 26 of 26

Más contenido relacionado

La actualidad más candente

09. session 9 operators and statements
09. session 9   operators and statements09. session 9   operators and statements
09. session 9 operators and statementsPhúc Đỗ
 
03 expressions.ppt
03 expressions.ppt03 expressions.ppt
03 expressions.pptBusiness man
 
Lecture21 categoriesof userdefinedfunctions.ppt
Lecture21 categoriesof userdefinedfunctions.pptLecture21 categoriesof userdefinedfunctions.ppt
Lecture21 categoriesof userdefinedfunctions.ppteShikshak
 
Tutorial on Markov Random Fields (MRFs) for Computer Vision Applications
Tutorial on Markov Random Fields (MRFs) for Computer Vision ApplicationsTutorial on Markov Random Fields (MRFs) for Computer Vision Applications
Tutorial on Markov Random Fields (MRFs) for Computer Vision ApplicationsAnmol Dwivedi
 
Inference & Learning in Linear Chain Conditional Random Fields (CRFs)
Inference & Learning in Linear Chain Conditional Random Fields (CRFs)Inference & Learning in Linear Chain Conditional Random Fields (CRFs)
Inference & Learning in Linear Chain Conditional Random Fields (CRFs)Anmol Dwivedi
 
Aaa ped-22-Artificial Neural Network: Introduction to ANN
Aaa ped-22-Artificial Neural Network: Introduction to ANNAaa ped-22-Artificial Neural Network: Introduction to ANN
Aaa ped-22-Artificial Neural Network: Introduction to ANNAminaRepo
 
Aaa ped-23-Artificial Neural Network: Keras and Tensorfow
Aaa ped-23-Artificial Neural Network: Keras and TensorfowAaa ped-23-Artificial Neural Network: Keras and Tensorfow
Aaa ped-23-Artificial Neural Network: Keras and TensorfowAminaRepo
 
High-order Finite Elements for Computational Physics
High-order Finite Elements for Computational PhysicsHigh-order Finite Elements for Computational Physics
High-order Finite Elements for Computational PhysicsRobert Rieben
 
Machine learning pt.1: Artificial Neural Networks ® All Rights Reserved
Machine learning pt.1: Artificial Neural Networks ® All Rights ReservedMachine learning pt.1: Artificial Neural Networks ® All Rights Reserved
Machine learning pt.1: Artificial Neural Networks ® All Rights ReservedJonathan Mitchell
 
Numerical analysis using Scilab: Numerical stability and conditioning
Numerical analysis using Scilab: Numerical stability and conditioningNumerical analysis using Scilab: Numerical stability and conditioning
Numerical analysis using Scilab: Numerical stability and conditioningScilab
 
Diploma ii cfpc- u-5.1 pointer, structure ,union and intro to file handling
Diploma ii  cfpc- u-5.1 pointer, structure ,union and intro to file handlingDiploma ii  cfpc- u-5.1 pointer, structure ,union and intro to file handling
Diploma ii cfpc- u-5.1 pointer, structure ,union and intro to file handlingRai University
 

La actualidad más candente (20)

09. session 9 operators and statements
09. session 9   operators and statements09. session 9   operators and statements
09. session 9 operators and statements
 
03 expressions.ppt
03 expressions.ppt03 expressions.ppt
03 expressions.ppt
 
Lecture21 categoriesof userdefinedfunctions.ppt
Lecture21 categoriesof userdefinedfunctions.pptLecture21 categoriesof userdefinedfunctions.ppt
Lecture21 categoriesof userdefinedfunctions.ppt
 
FASTEST: Test Case Generation from Z Specifications
FASTEST: Test Case Generation from Z SpecificationsFASTEST: Test Case Generation from Z Specifications
FASTEST: Test Case Generation from Z Specifications
 
Tutorial on Markov Random Fields (MRFs) for Computer Vision Applications
Tutorial on Markov Random Fields (MRFs) for Computer Vision ApplicationsTutorial on Markov Random Fields (MRFs) for Computer Vision Applications
Tutorial on Markov Random Fields (MRFs) for Computer Vision Applications
 
Inference & Learning in Linear Chain Conditional Random Fields (CRFs)
Inference & Learning in Linear Chain Conditional Random Fields (CRFs)Inference & Learning in Linear Chain Conditional Random Fields (CRFs)
Inference & Learning in Linear Chain Conditional Random Fields (CRFs)
 
Thai
ThaiThai
Thai
 
C sharp chap3
C sharp chap3C sharp chap3
C sharp chap3
 
Aaa ped-22-Artificial Neural Network: Introduction to ANN
Aaa ped-22-Artificial Neural Network: Introduction to ANNAaa ped-22-Artificial Neural Network: Introduction to ANN
Aaa ped-22-Artificial Neural Network: Introduction to ANN
 
Aaa ped-23-Artificial Neural Network: Keras and Tensorfow
Aaa ped-23-Artificial Neural Network: Keras and TensorfowAaa ped-23-Artificial Neural Network: Keras and Tensorfow
Aaa ped-23-Artificial Neural Network: Keras and Tensorfow
 
Hg2412901297
Hg2412901297Hg2412901297
Hg2412901297
 
Chapter 07
Chapter 07 Chapter 07
Chapter 07
 
Lecture03(c expressions & operators)
Lecture03(c expressions & operators)Lecture03(c expressions & operators)
Lecture03(c expressions & operators)
 
High-order Finite Elements for Computational Physics
High-order Finite Elements for Computational PhysicsHigh-order Finite Elements for Computational Physics
High-order Finite Elements for Computational Physics
 
Machine learning pt.1: Artificial Neural Networks ® All Rights Reserved
Machine learning pt.1: Artificial Neural Networks ® All Rights ReservedMachine learning pt.1: Artificial Neural Networks ® All Rights Reserved
Machine learning pt.1: Artificial Neural Networks ® All Rights Reserved
 
Numerical analysis using Scilab: Numerical stability and conditioning
Numerical analysis using Scilab: Numerical stability and conditioningNumerical analysis using Scilab: Numerical stability and conditioning
Numerical analysis using Scilab: Numerical stability and conditioning
 
Functions
FunctionsFunctions
Functions
 
Core Java
Core JavaCore Java
Core Java
 
ALGOL ailesi programlama dilleri
ALGOL ailesi programlama dilleriALGOL ailesi programlama dilleri
ALGOL ailesi programlama dilleri
 
Diploma ii cfpc- u-5.1 pointer, structure ,union and intro to file handling
Diploma ii  cfpc- u-5.1 pointer, structure ,union and intro to file handlingDiploma ii  cfpc- u-5.1 pointer, structure ,union and intro to file handling
Diploma ii cfpc- u-5.1 pointer, structure ,union and intro to file handling
 

Destacado

02 iec t1_s1_plt_session_02
02 iec t1_s1_plt_session_0202 iec t1_s1_plt_session_02
02 iec t1_s1_plt_session_02Niit Care
 
02 t1 s2_linux_lesson2
02 t1 s2_linux_lesson202 t1 s2_linux_lesson2
02 t1 s2_linux_lesson2Niit Care
 
Comp tia n+_session_08
Comp tia n+_session_08Comp tia n+_session_08
Comp tia n+_session_08Niit Care
 
01 iec t1_s1_plt_session_01
01 iec t1_s1_plt_session_0101 iec t1_s1_plt_session_01
01 iec t1_s1_plt_session_01Niit Care
 
Ms sql server architecture
Ms sql server architectureMs sql server architecture
Ms sql server architectureAjeet Singh
 

Destacado (13)

02 iec t1_s1_plt_session_02
02 iec t1_s1_plt_session_0202 iec t1_s1_plt_session_02
02 iec t1_s1_plt_session_02
 
Sql xp 11
Sql xp 11Sql xp 11
Sql xp 11
 
Sql xp 10
Sql xp 10Sql xp 10
Sql xp 10
 
02 t1 s2_linux_lesson2
02 t1 s2_linux_lesson202 t1 s2_linux_lesson2
02 t1 s2_linux_lesson2
 
Sql xp 09
Sql xp 09Sql xp 09
Sql xp 09
 
Sql xp 01
Sql xp 01Sql xp 01
Sql xp 01
 
Comp tia n+_session_08
Comp tia n+_session_08Comp tia n+_session_08
Comp tia n+_session_08
 
01 iec t1_s1_plt_session_01
01 iec t1_s1_plt_session_0101 iec t1_s1_plt_session_01
01 iec t1_s1_plt_session_01
 
SQL | Computer Science
SQL | Computer ScienceSQL | Computer Science
SQL | Computer Science
 
MS-SQL SERVER ARCHITECTURE
MS-SQL SERVER ARCHITECTUREMS-SQL SERVER ARCHITECTURE
MS-SQL SERVER ARCHITECTURE
 
Sql server basics
Sql server basicsSql server basics
Sql server basics
 
Ajs 1 b
Ajs 1 bAjs 1 b
Ajs 1 b
 
Ms sql server architecture
Ms sql server architectureMs sql server architecture
Ms sql server architecture
 

Similar a Dacj 1-3 b

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
 
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
 
Shubhrat operator &amp; expression
Shubhrat operator &amp; expressionShubhrat operator &amp; expression
Shubhrat operator &amp; expressionShubhrat Mishra
 
operat in vb .pptx
operat in vb .pptxoperat in vb .pptx
operat in vb .pptxclassall
 
L3 operators
L3 operatorsL3 operators
L3 operatorsteach4uin
 
L3 operators
L3 operatorsL3 operators
L3 operatorsteach4uin
 
L3 operators
L3 operatorsL3 operators
L3 operatorsteach4uin
 
Std 12 Computer Chapter 7 Java Basics (Part 2)
Std 12 Computer Chapter 7 Java Basics (Part 2)Std 12 Computer Chapter 7 Java Basics (Part 2)
Std 12 Computer Chapter 7 Java Basics (Part 2)Nuzhat Memon
 
OCA Java SE 8 Exam Chapter 2 Operators & Statements
OCA Java SE 8 Exam Chapter 2 Operators & StatementsOCA Java SE 8 Exam Chapter 2 Operators & Statements
OCA Java SE 8 Exam Chapter 2 Operators & Statementsİbrahim Kürce
 
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
 
Operators expressions-and-statements
Operators expressions-and-statementsOperators expressions-and-statements
Operators expressions-and-statementsCtOlaf
 
C programming session 02
C programming session 02C programming session 02
C programming session 02AjayBahoriya
 

Similar a Dacj 1-3 b (20)

Report on c
Report on cReport on c
Report on c
 
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
 
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 in java By cheena
Operators in java By cheenaOperators in java By cheena
Operators in java By cheena
 
Shubhrat operator &amp; expression
Shubhrat operator &amp; expressionShubhrat operator &amp; expression
Shubhrat operator &amp; expression
 
Introduction to Java
Introduction to JavaIntroduction to Java
Introduction to Java
 
operat in vb .pptx
operat in vb .pptxoperat in vb .pptx
operat in vb .pptx
 
L3 operators
L3 operatorsL3 operators
L3 operators
 
L3 operators
L3 operatorsL3 operators
L3 operators
 
L3 operators
L3 operatorsL3 operators
L3 operators
 
Operators
OperatorsOperators
Operators
 
Std 12 Computer Chapter 7 Java Basics (Part 2)
Std 12 Computer Chapter 7 Java Basics (Part 2)Std 12 Computer Chapter 7 Java Basics (Part 2)
Std 12 Computer Chapter 7 Java Basics (Part 2)
 
OCA Java SE 8 Exam Chapter 2 Operators & Statements
OCA Java SE 8 Exam Chapter 2 Operators & StatementsOCA Java SE 8 Exam Chapter 2 Operators & Statements
OCA Java SE 8 Exam Chapter 2 Operators & Statements
 
Java unit 3
Java unit 3Java unit 3
Java unit 3
 
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
 
Types of Operators in C
Types of Operators in CTypes of Operators in C
Types of Operators in C
 
Operators in java
Operators in javaOperators in java
Operators in java
 
Operators expressions-and-statements
Operators expressions-and-statementsOperators expressions-and-statements
Operators expressions-and-statements
 
C programming session 02
C programming session 02C programming session 02
C programming session 02
 
Operators-WPS Office.pdf
Operators-WPS Office.pdfOperators-WPS Office.pdf
Operators-WPS Office.pdf
 

Más de Niit Care (20)

Ajs 4 b
Ajs 4 bAjs 4 b
Ajs 4 b
 
Ajs 4 a
Ajs 4 aAjs 4 a
Ajs 4 a
 
Ajs 4 c
Ajs 4 cAjs 4 c
Ajs 4 c
 
Ajs 3 b
Ajs 3 bAjs 3 b
Ajs 3 b
 
Ajs 3 a
Ajs 3 aAjs 3 a
Ajs 3 a
 
Ajs 3 c
Ajs 3 cAjs 3 c
Ajs 3 c
 
Ajs 2 b
Ajs 2 bAjs 2 b
Ajs 2 b
 
Ajs 2 a
Ajs 2 aAjs 2 a
Ajs 2 a
 
Ajs 2 c
Ajs 2 cAjs 2 c
Ajs 2 c
 
Ajs 1 a
Ajs 1 aAjs 1 a
Ajs 1 a
 
Ajs 1 c
Ajs 1 cAjs 1 c
Ajs 1 c
 
Dacj 4 2-c
Dacj 4 2-cDacj 4 2-c
Dacj 4 2-c
 
Dacj 4 2-b
Dacj 4 2-bDacj 4 2-b
Dacj 4 2-b
 
Dacj 4 2-a
Dacj 4 2-aDacj 4 2-a
Dacj 4 2-a
 
Dacj 4 1-c
Dacj 4 1-cDacj 4 1-c
Dacj 4 1-c
 
Dacj 4 1-b
Dacj 4 1-bDacj 4 1-b
Dacj 4 1-b
 
Dacj 4 1-a
Dacj 4 1-aDacj 4 1-a
Dacj 4 1-a
 
Dacj 1-2 b
Dacj 1-2 bDacj 1-2 b
Dacj 1-2 b
 
Dacj 1-3 c
Dacj 1-3 cDacj 1-3 c
Dacj 1-3 c
 
Dacj 1-2 c
Dacj 1-2 cDacj 1-2 c
Dacj 1-2 c
 

Último

presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusZilliz
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 

Último (20)

presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 

Dacj 1-3 b

  • 1. Operators in Java Pre-assessment Questions 1. Predict the output of the expression, 16 % 3? a. 5 b. 0 c. 1 d. 4 • What is the default value of the float data type? a. 0.0 b. 0 c. 1.0 d. 1 ©NIIT Java Fundamentals Lesson 3B / Slide 1 of 26
  • 2. Operators in Java Pre-assessment Questions (Contd.) 3. Consider the statements: Statement A: The name of a variable can begin with a digit. Statement B: The name of a variable can contain white spaces. Identify the correct option. a. Statement A is true and statement B is false b. Statement A is false and statement B is true c. Both, statements, A and B, are true d. Both, statements, A and B, are false ©NIIT Java Fundamentals Lesson 3B / Slide 2 of 26
  • 3. Operators in Java Pre-assessment Questions (Contd.) 1. _______variables are the local variables that are accessed by the function in which the variables are declared. a. Static b. Automatic c. Instance d. Class 2. _______literals are enclosed in single quotes a. String b. Character c. Boolean d. Integer ©NIIT Java Fundamentals Lesson 3B / Slide 3 of 26
  • 4. Operators in Java Solutions to Pre-assessment Questions 1. c. 2. a. 3. d. 4. a. 5. b. ©NIIT Java Fundamentals Lesson 3B / Slide 4 of 26
  • 5. Operators in Java Objectives In this lesson, you will learn to: • Use operators • Arithmetic assignment operators • bit-wise operators • shift operators • instance-of operator • Identify the operators precedence ©NIIT Java Fundamentals Lesson 3B / Slide 5 of 26
  • 6. Operators in Java Using Unary Operators • Using the Increment and Decrement Operators • The increment and decrement operators are unary operators. • The increment operator (++) increases the value of an operand by 1. • The decrement operator (--) decreases the value of an operand by 1. • Prefix Form • The operator precedes the operand. • Operator operates on the operand before the value of operand is used in the expression. • Postfix Form • In the postfix form, operator follows the operand. • Operator operates on the operand after the value of operand is used in the expression. ©NIIT Java Fundamentals Lesson 3B / Slide 6 of 26
  • 7. Operators in Java Using the Arithmetic Assignment Operators • Arithmetic Assignment Operators • Addition(+), subtraction(-), multiplication(*), division(/), and modulo(%) are the arithmetic operators supported by Java. • Various arithmetic operators, such as +, -, /, *, and % are combined with the assignment operator (=) and are called arithmetic assignment operators. ©NIIT Java Fundamentals Lesson 3B / Slide 7 of 26
  • 8. Operators in Java Using the Arithmetic Assignment Operators (Contd.) Operator Use Description += op1 += op2 Adds operand, op1 and operand, op2 and assigns the result to op1. This expression is equivalent to op1 = op1+op2. -= op1 -= op2 Subtracts operand, op2 from operand, op1 and assigns the result to op1. This expression is equivalent to op1 = op1 – op2. ©NIIT Java Fundamentals Lesson 3B / Slide 8 of 26
  • 9. Operators in Java Using the Arithmetic Assignment Operators (Contd.) Operator Use Description *= op1 *= op2 Multiplies operand, op1 and operand, op2 and assigns value of the result to op1. This expression is equivalent to op1 = op1*op2. /= op1 /= op2 Divides operand, op1 by operand, op2, and assign the value of the result to op1. This expression is equivalent to op1 = op1/op2. ©NIIT Java Fundamentals Lesson 3B / Slide 9 of 26
  • 10. Operators in Java Using the Arithmetic Assignment Operators (Contd.) Operator Use Description %= op1 %= op2 Assigns the remainder of division of operand, op1 and operand, op2 to op1. This expression is equivalent to op1 = op1% op2. ©NIIT Java Fundamentals Lesson 3B / Slide 10 of 26
  • 11. Operators in Java Using Bit-wise Operators • Bit-wise operators • Operate on the individual bits of their operand. • Operands can be various data types like int, short, long, char, and byte. • Operands are converted into their binary equivalents before operation. • The result in the binary form after the operation is converted back into its decimal equivalent. ©NIIT Java Fundamentals Lesson 3B / Slide 11 of 26
  • 12. Operators in Java Using Bit-wise Operators(Contd.) • The following table lists the various bit-wise operators in Java: Operator Use Operation &(AND) x&y Performs bit-wise AND operation. It evaluates to 1 if both bits, x and y are 1. If either or both bits are 0, the result is 0. |(OR) x|y Performs bit-wise OR operation. It evaluates to 0 if both bits, x and y are 0. If either or both bits are 1, the result is 1. ©NIIT Java Fundamentals Lesson 3B / Slide 12 of 26
  • 13. Operators in Java Using Bit-wise Operators(Contd.) Operator Use Operation ~(inversion) ~x Performs unary NOT operation. Converts all the 1s into 0s and all the 0s into 1s. ^(XOR) x^y Performs bit-wise XOR operation. It evaluates to 1 if bits have different values and 0 if both the bits have the same value. ©NIIT Java Fundamentals Lesson 3B / Slide 13 of 26
  • 14. Operators in Java Using Bit-wise Operators (Contd.) • Using the Bit-wise AND Operator • The Bit-wise AND operator (&) performs AND operation on two operands. • Displays 1 if both bits are 1 else 0 in all other cases. Operation Result 0&0 0 0&1 0 1&1 1 1&0 0 ©NIIT Java Fundamentals Lesson 3B / Slide 14 of 26
  • 15. Operators in Java Using Bit-wise Operators (Contd.) • Using the Bit-wise OR Operator • The Bit-wise OR operator (|) performs OR operation on two operands. • Displays 0 if both bits are 0 else 1 in all other cases. Operation Result 0|0 0 0|1 1 1|1 1 1|0 1 ©NIIT Java Fundamentals Lesson 3B / Slide 15 of 26
  • 16. Operators in Java Using Bit-wise Operators (Contd.) • Using the Bit-wise NOT Operator • Bit-wise NOT operator (~) is a unary operator and performs NOT operation on each bit of binary number. • The NOT operator inverts or complements each of the bits of a binary number. Operation Result ~0 1 ~1 0 ©NIIT Java Fundamentals Lesson 3B / Slide 16 of 26
  • 17. Operators in Java Using Bit-wise Operators (Contd.) • Using the Bit-wise XOR Operator • The Bit-wise XOR (^) operator performs XOR operation on two operands. • The XOR operator applied on two bits results in 1 if exactly one bit is 1 else 0 in all other cases . Operation Result 0^0 0 0 ^1 1 1^1 0 1^0 1 ©NIIT Java Fundamentals Lesson 3B / Slide 17 of 26
  • 18. Operators in Java Using Shift Operators • Works on the bits of data. • Shifts the bits of it’s operand either to left or right. Operator Use Operation >> val1 >> val2 Shifts the bits of the val1 operand to the right by the number of (Right Shift) positions specified by val2. << val1<< val2 Shifts the bits of the val1 operand to the left by the number of (Left Shift) positions specified by val2. ©NIIT Java Fundamentals Lesson 3B / Slide 18 of 26
  • 19. Operators in Java Using Shift Operators (Contd.) Operator Use Operation >>> val1 >>> val2 Shifts the bits of the val1 operand to the right by the number of (Unsigned Shift positions specified by val2. A zero Operator) value is input in the high-order bit irrespective of the value of the high-order bit of val1. The high- order bit is the leftmost bit of the binary number. ©NIIT Java Fundamentals Lesson 3B / Slide 19 of 26
  • 20. Operators in Java Using Shift Operators (Contd.) • Using the Right Shift and Left Shift Operators • The right shift and the left shift operators are binary operators. • The right shift operator shifts all the bits of a binary number in the right direction. operand >> num • The left shift operator, <<, shifts all the bits of a binary number in the left direction. operand << num • Using the Unsigned Shift Operator • Unsigned shift operator (>>>) is used to shift the bits of a binary number to the right. • The operator fills the leftmost bits of a binary value with 0 irrespective of whether the number has 0 or 1 at the leftmost bit. ©NIIT Java Fundamentals Lesson 3B / Slide 20 of 26
  • 21. Operators in Java Using instance of Operator • Used to test whether an object is an instance of a specific class. • Used at the run time. • The syntax of the instanceof operator is: op1 instanceof op2 • op1 is the name of an object and op2 is the name of a class. • Returns a true value if the op1 object is an instance of the op2 class. ©NIIT Java Fundamentals Lesson 3B / Slide 21 of 26
  • 22. Operators in Java Operators Precedence • Each operator in an expression is evaluated in a predetermined order called operator precedence. • Operators on the same line have equal precedence. Operators Category [], (), . , expr++, expr-- Array index, method call, member access, and postfix operators ++expr, --expr, +, -, !, ~ Unary postfix operators *, /, % Multiplicative Arithmetic operators +, - Additive Arithmetic operators ©NIIT Java Fundamentals Lesson 3B / Slide 22 of 26
  • 23. Operators in Java Operators Precedence(Contd.) Operators Category <<, >>, >>> Shift operators >, <, <=, >=, instanceof Relational operators ==, != Equality operator & Bit-wise AND operator ^ Bit-wise XOR operator | Bit-wise OR operator && Conditional AND operator || Conditional OR operator =, +=, -=, *=, /=, %= Assignment operators ©NIIT Java Fundamentals Lesson 3B / Slide 23 of 26
  • 24. Operators in Java Demonstration-Precedence of Operators in Java • Problem Statement • Create a Java application to understand the order of precedence of various operators in Java. • Solution • The Java application is created using the various operators in Java. • To solve the above problem, perform the following tasks: 3. Code an application with an expression having multiple operators of different precedence 4. Compile and execute the code. ©NIIT Java Fundamentals Lesson 3B / Slide 24 of 26
  • 25. Operators in Java Summary • In this lesson, you learned: • Operators are used to calculate, compare and compute values. The operators are classified as: • Unary operators • Binary operators • Unary operators operate on one operand, such as increment and decrement operators. • Binary operators operate on two operands, such as arithmetic operators +,-,/,*. • Arithmetic operators, such as, +, _, combined with assignment operator(=) are arithmetic assignment operators. • Bit-wise operators operate on one bit at a time. • The bit-wise operators operate on data types such as, int, short, long, char and byte. • The various bit-wise operators are bit-wise AND (&), bit-wise OR (|), bit- wise NOT (~), and bit-wise XOR (^). ©NIIT Java Fundamentals Lesson 3B / Slide 25 of 26
  • 26. Operators in Java Summary (Contd.) • Shift operators are used to shift the bits of the number to the left or right. The various shift operators are right shift (>>), left shift (<<), and unsigned shift operator (>>>). • The instanceof operator is used to test that whether an object is an instance of a particular class. • An expression can have several operators and each operator is evaluated in order of their precedence. ©NIIT Java Fundamentals Lesson 3B / Slide 26 of 26