Sunday, June 7, 2020

Types of Operators in java


Definition of Java Operator: An operator performs a particular operation on the operands it is applied on.

Types of Operators in java:

  • Assignment Operators
  • Arithmetic Operators
  • Unary Operators
  • Equality Operators
  • Relational Operators
  • Conditional Operators
  • instanceof Operators
  • Bitwise Operators
  • Shift Operators

Assignment Operator:
OperatorDescriptionExample
        =Assignmentint i=10; int j=i;

Arithmetic Operators:
OperatorDescriptionExample
       +Additionint i=8+9; byte b=(byte) 7+9;
        -Substractionint i=9-3;
         *Multiplicationint i=7*9;
        /Divisionint i=12/4;
        %Reminderint i=10%4;

Unary Operators:
OperatorDescriptionExample
        +Unary Plusint i=+1;
         -Unary Minusint i=-1;
        ++Incrementint j=i++;
         --Decrementint j=i--;
         !Logical Notboolean j=!true;

Equality Operators:
OperatorDescriptionExample
        ==Equalityif(i==1)
        !=Non Equalityif(i!=1)

Relational Operators:
OperatorDescriptionExample
          >Greater thanif(x>5)
          <Less thanif(x<5)
          >=Greater than or equal toif(x>=5)
          <=Less than or equal toif(x<=5)

Conditional Operators:
OperatorDescriptionExample
       &&Conditional andif(a==4 && b==7)
       ||Conditional orif(a==4 || b==7)

instanceof Operators:
OperatorDescriptionExample
  instanceofInstance ofif(Jeep instanceof Vehicale)

Bitwise Operators:
OperatorDescriptionExample
       &Bitwise and001 & 111 =1
       |Bitwise or001 | 110 = 111
       ^Bitwise ex-or001 ^ 110 = 111
       ~Reverse~011 = -10

Shift Operators:
OperatorDescriptionExample
      >>Right shift4 >> 1 = 100 >> 1 = 010 = 2
      <<Left shift4 << 1 = 100 << 1 = 1000 = 8
      >>>Unsigned Right shift4 >>>1 = 100 >>> 1 = 010 = 2

No comments:

Post a Comment

Hello Buddy, if you have any doubts or need any clarification , feel free to comment. Thanks.