Online Training [Topic->Operators In Java] www.wayofcoding.
com [Page-1]
Operators In Java
An operator is a symbol by which certain operation can be performed.
Types of Operators – Based on the nature, the operators are classified into various
types which are-
Unary Operator – Unary means one, i.e An unary operator can be applied on single
operand only.
Pre Increment Operator – Increment it by one then returns the value.
for e.g-
int i = 0;
System.out.println(++i); // this line will print 1
System.out.println(i); // this line will print 1
Online Training [Topic->Operators In Java] www.wayofcoding.com [Page-2]
Post Increment Operator – It returns the value first then increment it by one.
for e.g-
int j = 0;
System.out.println(j++); // this line will print 0
System.out.println(j); // this line will print 1
Pre Decrement Operator – Decrement it by one then returns the value.
Post Decrement Operator – It returns the value first then decrement it by one.
Lets see in the below example to understand how post increment and pre increment expression
gets evaluated.
Online Training [Topic->Operators In Java] www.wayofcoding.com [Page-3]
Negation Operator – It negates the value of boolean type.
for e.g-
boolean isPrime = true;
System.out.println(!isPrime); // this line will print false
System.out.println(isPrime); // this line will print true
Bitwise Complement Operator – It flips all bits in binary and hence positive number becomes
negative and vice versa.
for e.g-
int k = 5;
int z = -10;
System.out.println(~k); // this line will print -6
System.out.println(~z); // this line will print 9
Online Training [Topic->Operators In Java] www.wayofcoding.com [Page-4]
Arithmetic Operator – It is used to perform basic mathematical operation like addition,
subtraction, mulitplication, division, finding reminder.
Online Training [Topic->Operators In Java] www.wayofcoding.com [Page-5]
Assignment Operator – It is used to assign the value to variable.
Relational Operator – It compares two values and returns boolean(true/false).
Online Training [Topic->Operators In Java] www.wayofcoding.com [Page-6]
Logical AND && Operator – It returns true only if both condition are true otherwise it
returns false. Note that if first condition is false then second condition does not get evaluated.
Logical OR || Operator – It returns true if any condition is true otherwise it returns false.
Note that if first condition is true then second condition does not get evaluated.
Online Training [Topic->Operators In Java] www.wayofcoding.com [Page-7]
Ternary Operator – It has three parts- condition, statement-1, statement-2. If condition is
true then first statement is returned, otherwise second statement is returned.
Bitwise Operator – Bitwise AND(&), Bitwise OR(|), Bitwise XOR(^)
Refer Binary Number System Notes for bitwise operator working details. And do the java program
practice as an assignment.
Shift Operator – Right Shift(>>), Left Shift(<<), unsigned right shift(>>>)
Refer Binary Number System Notes for shift operator working details. And do the java program
practice as an assignment.