Operators are special characters within the Java language to manipulate primitive data types. Java operators can be classified as :

Unary : Takes one argument. These operators appear before (prefix) its argument or after (postfix) its argument.

Binary: Takes two arguments.  These operators appear between their arguments.

Ternary: Takes three arguments. These operators appear between their arguments.

### Different types of Operators in java

Assignment Operators : ` =`
Arithmetic Operators : ``` - + * / % ++ -- ``` Relational Operators : `> < >= <= == !=`
Logical Operators : ` && || & | ! ^`
Conditional Operator `: ?`
Bitwise Operator : ` & | ^ >> >>>`
Compound Assignment Operators :  ``` += -= *= /= %= ```

## Assignment Operator

Assignment Operator is denoted by the symbol “=” and it is the most commonly used operator. it simply assigns the value on the right to the variable on the left. Syntax of the assignment operator is <variable> = <expression>.

Examples

OutPut

Value stored in the speed variable is : 80
Value stored in the distance variable is : 20
Value stored in the time variable is : 10
Value stored in the name variable is : ToolsQA
Value stored in the isGood variable is : true
Value stored in the speed variable is : 100
Value stored in the time variable is : 20
Value stored in the name variable is : ForumsQA
Value stored in the isGood variable is : false
Value stored in the speed variable is : 0

## Arithmetic Operators

Arithmetic operators perform the same basic operations you would expect if you used them in mathematics. They take two operands and return the result of the mathematical calculation. There are seven important arithmetic operators available in Java:

Subtraction ‘-‘ : This subtracts right-side operand from the left side operand
Multiplication ‘*’ : This multiplies two numbers
Division ‘/’ : This divides left side operand by the right side operand
Modulo ‘%’ : This divides left side operand by the right side operand and returns the remainder
Increment ‘++’ : This increases the value by 1
Decrement ‘- -‘ : This decreases the value by 1

Examples

Output

Value of ‘a’ after ‘+’ Arithmetic operation is 15
Value of ‘a’ after ‘-‘ Arithmetic operation is 5
Value of ‘a’ after ‘*’ Arithmetic operation is 50
Value of ‘a’ after ‘/’ Arithmetic operation is 2
Value of ‘a’ after ‘%’ Arithmetic operation is 0
Value of ‘b’ after ‘++’ Arithmetic operation is 11
Value of ‘c’ after ‘–‘ Arithmetic operation is 4

## Relational Operators

Relational Operators are used to determine the comparison between two or more objects. These operators always return the boolean value either true or false when used in an expression. In java we have six different relational operators:

Greater than ‘>’ : This checks if the value of left operand is greater than value of right operand
Less than ‘<‘ : This checks if the value of left operand is less than the value of right operand
Greater than or Equal to ‘>=’ : This checks if the value of left operand is greater than or equal to the value of right operand
Less than or Equal to ‘<=’ : This checks if the value of left operand is less than or equal to the value of right operand
Equal ‘==’ : This checks if the value of both operands are equal
Not Equal ‘!=’ : This checks if the value of two operands are not equal

Example

Output:

<<<<<< GREATER THAN OPERATOR >>>>>>
Ten > Twenty ==> false
Twenty > Ten ==> true
Thirty > Twenty ==> true
<<<<<< GREATER THAN OR EQUAL TO OPERATOR >>>>>>
Ten >= Twenty ==> false
Twenty >= Ten ==> true
Thirty >= Twenty ==> true
<<<<<< LESS THAN OPERATOR >>>>>>
Ten < Twenty ==> true
Twenty < Ten ==> false
Thirty < Twenty ==> false
<<<<<< LESS THAN OR EQUAL TO OPERATOR >>>>>>
Ten <= Twenty ==> true
Twenty <= Ten ==> false
Thirty <= Twenty ==> false
<<<<<< EQUAL TO OPERATOR >>>>>>
Ten == Twenty ==> false
Thirty == Twenty + Ten ==> true
<<<<<< NOT EQUAL TO OPERATOR >>>>>>
Ten != Twenty ==> true
Thirty != Twenty + Ten ==> false

## Logical Operators

Logical operators return a true or false value based on the state of the Variables. Each argument to a logical operator must be a boolean data type, and the result is always a boolean data type. Below are the three most commonly used logical operators:

And Operator ‘&&’ : This returns true if the output of both the operands are true
OR Operator ‘||’ : This returns true if the output of either operands are true
NOT Operator ‘!’ : This inverts the state of the condition

Example

Output

Check if both the boolean variables are true : false
Check if even one of the boolean variable is true : true
Change the state of the Output_1 to false : false

## Conditional Operator

The conditional operator is the only operator that takes three arguments in Java. The conditional operator is equivalent to if-else statement. It is also known as the ternary operator. This operator consists of three operands and is used to evaluate Boolean expressions. The goal of the operator is to decide which value should be assigned to the variable. The operator is written as:

variable = (expression) ? value if true : value if false

Example

Output

The boolean value of the variable ‘bValue’ is : true
The int Value of the variable iValue is : 50
The int Value of the variable iValue is : 100