|
An Operator is a symbol that tells to computer to perform certain action mathematical or logical manipulation. Operator are used in programs to manipulate data and variable. Operator in java eight types
- Arithmetic Operators
- Relational Operators
- Logical Operators
- Assignment Operator
- Increment and decrement Operators
- Bitwise Operators
- Special Operators
1. Arithmetic Operator Arithmetic Operators are used in Mathematical expressions in a same way that they are used in algebra.
Operator Result
+ Addition
- Subtraction
* Multiplication
/ Division
% Modulus
2. Relational Operator Relational Operator determine the relationship that operand has to other. when arithmetic expression are used on either side of a relational operator , the arithmetic expression will be evaluated first and then result compared. arithmetic operators have a higher priority over relational operator.
Operator Result
< Less than
<= Less than or equal to
> Greater than
>= Greater than or equal to
== Equal to
!= Not equal to
3. Logical Operator
Operator Result
& Logical AND
&& Short_ circuit AND
| Logical OR
|| Short_ circuit OR
?: Ternary if-then-else
! Logical unary NOT
4. Assignment Operator Assignment Operators are used to assign to the value of an expression to a variable.
syntax:- int aa = 100;
5. Increment and decrement Operator .
Operator Result
++ Increment
-- Decrement
Note - Increment Operator also divided into two type.
Pre Increment // ++aa;
Post Increment // aa++;
Decrement Operator also divided into two type.
pre Decrement Operator // --aa;
Post Decrement Operator // aa--;
6. Bitwise Operator These Operator used for testing the bit or shifting to right or left.
Operator Result
~ Bitwise unary NOT
& Bitwise AND
- Bitwise NOT
^ Bitwise exclusive OR
<< Shift left
>> Shift Right
>>>
7. Special Operator Java support two special operator.
instanceof Operator.
Dot Operator (.).
1. Instanceof Operator Instance Operator allow us to determine whether the object belong to a particular class or not. syntax
person instanceof Student ;
Note-( person instanceof Student ) is true if object person belong to the class Student otherwise it is false.
2. Dot Operator. Dot Operator (.) is used to access the instance variables and methods of the class object. Example
Student person1= new Student() ; // person1 is object of class Student
person1.age; // reference to the variable age
person1.salary() ; // reference to the method salary()
|