28 Jan 2020

Mathematical operations are used everywhere whether to calculate a company's payroll or the employees' number. The structure of an operation is composed of operands and operators and usually The result is assigned to variables. the statement below is an example of an operation.

** int a=1 + 2; **

**1**and**2**are the**operands****The sign +**is the**Addition operator**.**The sign=**is the**Assignment operator**

Java supports other operators for different purposes :

**Relational and equality operators****Logical operators****Ternary operators****Unary operators****Binary operators**

We'll see each one in the next sections .

Java supports using the following classical arithmetic operators

- Multiplication *
- Division /
- Modulus %
**Addition +****Subtraction -**

These operators are usually used to assign Mathematical operations results to variables .The most-used assignment operator is the equal operator "=", which simply assigns operations' result to variables.

Sometimes, You'll encounter Compound Assignment operators which always have the equal sign on the right side beside other operators +=, -=, *=, /=, %=, &=, ^=, !=, <<=,>>=, >>>=

This way of writing operators behaves as a shortcut that uses the previous value of the statement's variable as an operand in the whole operation.

Relational operators are used to evaluate a test case before entering a protected block of code

- less than <
- greater than >
- less than or equal to<=
- greater than or equal to>=
- instanceof
- equal to ==
- not equal to !=

These operators are used to verify a set of tests either

- Collectively using the Conditional-And,
**(****in code we write &&)** - Or individually with the Conditional-or,
**(****in code we write ||)**

Ternary operators are used to compact conditional blocks of code into one line. These conditional blocks must treat only two cases, for instance, this example

**if(test){First case;}else{Second case;}**

becomes :

- Test ? First case :
**Second case**

If the Test evaluates to true, the first case block is entered, otherwise, the second.

These kind of operators are involved with just one expression, they don't need more than one operand unlike arithmetic operators.

- Post-unary operators expression++,expression--
- Pre-unary operators ++expression, --expression
- The unary plus +
- The unary minus: -
- The logical not: !

These operators are less commonly used, They perform bits' operations :

- The signed left shift <<
- The signed right shift >>
- The unsigned right shift >>>
- Bitwise AND &
- Bitwise exclusive OR ^
- Bitwise inclusive OR |
- Bitwise complement ~