- Get link
- X
- Other Apps
Operators
In Java, we can perform various operations on data.For example, addition,subtraction and many more calculation. There are a lot of operations that we want to perform on our data.
Lets understand it with simple example, "We will apply multiplication operation on a and b.For implementing multiplication,we must have a symbol that denotes multiplication, that symbol is know as multiplication operator.An operator can be prefixed, suffixed or can occur in the middle of expression."
A symbol that denotes the occurrence of some operation is know as "Operator".It tells compiler to perform a specific mathematical or logical operation on one or more operands. To apply multiplication we will use asterisk(*) symbol as operator.So, basically anything that is used to define an operation is an operator.
for example, a + b, In here, "+" is the operator that causes the addition of numbers a and b."a+b" is a mathematical expression.
Operands
Anything on which we are performing an operation by using the operators is known as "Operand".Operand can by a variable, constant, or an expression. In above example, "a" and "b" are two operands, on which we were performing an action.
Major Categories of Operators
Operators are categorized in three types:
- Unary Operator: Unary operators are the operators that are used with only one operand.For example: ++a , here "++" is an increment operator which increases the value of a by 1 . It is used with only one operand "a".
- Binary Operator: These operators are used with two operands.For example: a - b, here "-" is a subtraction operator which subtracts value of "b" from the value of "a".
- Ternary Operator: These operators performs action on three operands.For example: a>b?a:b is a condition operator(exp1?exp2:exp3) which takes three operands,as I told operands can be expressions, here "a>b" is an expression which tells if a is greater than b, "a:b" will return "a" if the exp1 is true else it will return "b".
Types of Operators used in Java
In Java, We have many types of operators that perform different action or operation on data.Lets see them below:
- Arithmetic Operators
- Relational Operators
- Logical Operators
- Bitwise Operators
- Assignment Operators
- Unary Operators
- Conditional Operator
- String Concatenation Operator
- Dot Operator
- instanceof Operator
Comments
Post a Comment
If you have any doubt, ask here