Operator In Java

Card image cap

Definition of an Operators ?

Operators are symbols that indicate an ioperation to be performed. Operators are used to manipulate data in program.

Arithmetic operators are classified as unary, binary and ternary operators based on the number of operands used. The unary operators requires only one operand (+,-,++,--); Binary operators requires two operands(+,-,*,^,/,% and the ternary operator requires three operands(?).


All arithmetic operators compute the result of specific arithmetic operation and returns its result. The arguments are not modified.

Arithmetic operators "+" and "-" are used to manipulate pointers by adding or subtracting the numeric value to or from the pointers without generating any exception during overflow of the of the pointer's domain.

Arithmetic operators can be overloaded when used with user-defined types to extend the nature of normal operators, thus providing additional functionalities.


Card image cap

Arithmetic Operators

Operator Description Example
+ Addition a+b
- Subtraction a-b
* Multiplication a*b
/ Division a/b
% Modulus a%b
Card image cap

Increment and Decrement Operators

Operator Description Example
++ Post Increment a++
-- Post Decrement a--
++a Pre Increment ++a
--a Pre Decrement --b
Card image cap

Relational Operators

Operator Description Example
== Is equal to a==b
!= Is not equal to a!=b
> Greater than a>b
< Less than a<b
>= Greater than or equal to a>=b
<= Less than or equal to a<=b
Card image cap

Logical Operators

Operator Description
&& And operator. if both expressions evaluate to True, result is True. If either expression evaluates to False, result is False
|| Or operator. if either or both expressions evaluate to True, result is True
! Not operator. Performs logical negation on an expression.
Card image cap

Bitwise Operators

Operator Description
<< Binary left Shift Operator
>> Binary Right Shift Operator
~ Binary One's Complement Operator
& Binary AND Operator
^ Binary XOR Operator
| Binary OR Operator
Card image cap

Assignment Operators

Operator Description
= Assign
+= Increments, then assigns
-= Decrements, then assigns
*= Multiplies, then assigns
/= Divides, then assigns
%= Modulus, then assigns
<<= Left shift and assigns
>>= Right shift and assigns
&= Bitwise AND assigns
^= Bitwise exclusive OR and assigns
|= Bitwise inclusive OR and assigns
Card image cap

Example :



Output :

Simple Arithmetic Operators Example

 a - b = 8
 b * c = 24
 a / c = 2
 a + b * c = 36
 a * b + c * d = 96
Card image cap

Card image cap