Wednesday 12 September 2018

Operators In JAVA ( Part 1 )




Definition


Operators are the symbols which perform some operation on operands. "



" Expression is any valid combination of operators, constants and variables. "





Before, Start Lets understand two small concept - 
  1. Precedence Level
  2. Associativity Rule
(For more Information - Click Here (Redirect to some other Page) )

# Precedence and Associativity

When expressions contain more than one operator, the order in which the operators are evaluated depends on their precedence levels. A higher precedence operator is evaluated before a lower precedence operator. If the precedence levels of operators are the same, then the order of evaluation depends on their associativity (or, grouping). 


Types of operators

There are two types of operators

     a) On the basis of type of operands 
              1- Unary operator
              2- Binary operator
              3- Ternary operator
     b) On the basis of type, operation performed 
              1- Arithmetic operator
              2- Logical operator
              3- Relational operator
              4- Bitwise operator
              5- Assignment operator
              6- Increment and Decrements operator
              7- Shorthand operator
              8- Conditional operator



A)  On The Basis Of Type Of Number Operands


1- Unary Operator -
These are the operator which operates upon a single operand.
Eg-  +5, +7, -6, -54.7, x++; y--   etc

2-Binary Operator -
These are the operator which operates upon two operands.
Eg-  5+7, 10-8, 15%3, x&&y, a||b   etc.

3- Ternary Operator -
It is the operator which operates upon three operands. It is also called Conditional Operator.
Eg- ?:  (Question mark and colon)



B)  On The Basis Of  Type Of Number Operands

1- Arithmetic Operator- 
This operator is used for the performing arithmetic operation in the Expression.



2- Logical Operator- 
This operator is used to combine logical expiration. It works on Control Statement.



3- Relational Operator-
This operator is used to determine the relationships among different operand.


4- Bitwise Operator- 
This operator is used as like gates. It works on mathematical Expression

 


5- Assignment Operator-
It is used to assign a value to a variable.
Eg-  x=5;

6- Increment and Decrement Operator- 

 


7- Shorthand Operator-
Is used to minimize code length.


8- Conditional Operator-
This operator is used like to select one thing from two things based on the situation.
It is also called Ternary Operator.





No comments:

Post a Comment