 # Arithmetic, Assignment and Unary Operator in Java

####  In this chapter you will learn:

1. What is assignment operator and their symbol?
2. What is arithmetic operator and their symbol?
3. What is unary operator and their symbol?
4. Programming example

What is assignment operator in Java?

Assignment(=) operator is most common operator in Java. It is used for assigning value to variable. For example
int num = 5;

What is arithmetic operator in java?

Arithmetic operator is an operator which provides addition, subtraction, multiplication, division and reminder. It performs mathematical operation on operands.

 Operator Description Example + It is called as Plus operator which adds integral value. num1 + num2 – It is called Minus operator which subtracts integral value. num1 – num2 * It is called Multiply operator which multiply integral value. num1 * num2 / It is called Divide operator which divide integral value. num1 / num2 % It is called Reminder operator which tells reminder of two integral values. num1 % num2
Programming Example:

Output

D:\JavaProgram>javac ArithmeticOperators.java

D:\JavaProgram>java ArithmeticOperators
Subtraction : 10
Multiplication : 200
Division : 2
Reminder : 2

D:\JavaProgram> __

#### What is unary operator?

Unary operator is such kind of operator which requires only one operand to perform task. This type of operator is used for increasing or decreasing value, negating the expression or inverting the Boolean value.

 Operator Description Example + Unary Plus Operator: It indicates positive value. (However numbers are positive by default) 35 or +35 – Unary Minus Operator: It indicates negative value -35 ++ Increment Operator: It increment value by 1 num1++ — Decrement Operator: It decrements value by 1 num1– ! Logical Complement Operator: (also known as Not Operator) – It inverts the Boolean expression. (true to false or false to true) if(!(true))

#### Programming Example

Output

D:\JavaProgram>Javac UnaryOperator.java

D:\JavaProgram>java UnaryOperator
11
9
-10
false

D:\JavaProgram> __

#### Summary

In this chapter you have learned about assignment, arithmetic and unary operator in java. The next chapter you will learn about Relational Operator in Java.