# [Tutorial 3] :Operators in Java – Their use and Syntax

**So, you are now familiar with writing the very basic programs in Java such as – “Printing your name and other such stuff.” Now, let us proceed a bit further. So, In this tutorial , I will tell you about various Operators in Java and how to make use of them.**

##
**What are Operators in Java ?**

**Operators in Java**are some symbols in Java that are used to perform some particular tasks such as making calculations or comparing two quantities or to perform some other function.

**For example :–**

- ‘+’ is an operator used in Java to add two quantities.
- ‘<’ is used to test whether a quantity is “lesser than” another quantity or not.

##
**What are the different types of Operators?**

Java offers various types of Operators to perform different tasks. The main operators in Java can be broadly classified into the following categories :-

**Arithmetic Operators –**The operators used in Java to perform the basic addition , subtraction , multiplication , division and remainder operations are known as**Arithmetic operators.****The arithmetic operators of Java**can be used to perform various Mathematical calculations or Arithmetic calculations such as addition, subtraction, multiplication , division , remainder etc. Examples of Arithmetic operators are ‘+’ , ‘-’ , ‘*’ , ‘/’**Relational Operators**–

The relational operators in Java are used to compare two quantities. They always give the result as “True” or “False.” Examples of Relational Operators used in Java are ‘<’ , ‘>’ , ‘<=’ , ‘>=’ , ‘==’**Increment-Decrement Operators –**

The increment operators in Java are used to ‘1’ to a number. For example :-

**a++ (It means a = a+1)****a– (It means a = a-1)****Logical Operators –**The logical operators that are used in Java are the following :-

#### Logical “AND” Operator (&&)

#### Logical “OR” Operator (||)

#### Logical “NOT” Operator (!)

**Conditional Operators –**These operators are also known as ternary operators which mean that these operators act on three operands. The generic syntax of these operators is as follows :-

**Expression1 ? Expression2 : Expression3**

Its working is explained as :-

If the expression1 results to true , expression 2 will be executed otherwise expression3 will be executed.

Its symbol is “

If the expression1 results to true , expression 2 will be executed otherwise expression3 will be executed.

Its symbol is “

**?:**”**Assignment Operator –**The assignment operator if Java is used to assign a value to a variable. The main assignment operator is ‘=’ Other than this “equal to” operator , there are also other operators that come under the category of assignment operators , there are known as Java ShortHand Operators. These operators are used to simplify the coding of a particular assignment statement. The different types of shorthand operators are as follows :-

####
‘+=’ Its use is as :- a+=10 means a=a+10;

‘-=’ Its use is as :- a-=10 means a=a-10;

‘*=’ Its use is as :- a*=10 means a=a*10;

‘/=’ Its use is as :- a/=10 means a=a/10;

## Don’t miss – Introduction to BlueJ – Writing and Compiling your Java programs

**Miscellaneous operators –**The other Miscellaneous operators used are- The dot Operator as in “System.out.println();”
- The () Operator – It is also known as parenthesis and is also used in the System.out.printing command.

##
**What is Operator Precedence ?**

Well , In Mathematics we have seen that the basic operations are performed in a sequence which is termed as BOD MAS. Similarly , In Java also , the sequence of the operators has been defined and this is known as “

**Operator Precedence**” The following is the**Operator Precedence table.**Category | Operator | Associativity |

Postfix | () [] . (dot operator) | Left to right |

Unary | ++ – – ! ~ | Right to left |

Multiplicative | * / % | Left to right |

Additive | + – | Left to right |

Shift | >> >>> << | Left to right |

Relational | > >= < <= | Left to right |

Equality | == != | Left to right |

Bitwise AND | & | Left to right |

Bitwise XOR | ^ | Left to right |

Bitwise OR | | | Left to right |

Logical AND | && | Left to right |

Logical OR | || | Left to right |

Conditional | ?: | Right to left |

Assignment | = += -= *= /= %= >>= <<= &= ^= |= | Right to left |

Hello Every One thanks For Visit My site You Can Suggest any Idea About site And Related Education Information Provide me Its Best Content For you am Include in this Site And feel free contact And email now I hope This site very help full you