3.12 Operators
Operators are special symbols that perform specific operations on one, two, or three operands, and then return a result.
The following 37 tokens are the operators, formed from ASCII characters:
Operator: one of
= > < ! ~ ?: == <= >= != && || ++ -- + - * / & |^ % <<>>>>>
+= -= *= /= &= |= ^= %= <<= >>= >>>=
Operators in java fall into 8different categories
Assignment
Arithmetic
Relational operators
Logical
Bitwise
Compound assignment
Conditional
Type
OPERATERS PRESEDENCE
The order which operator evaluated first is called as precedence
The operators in the following table are listed according to precedence order. The closer to the top of the table an operator appears, the higher its precedence. Operators with higher precedence are evaluated before operators with relatively lower precedence. Operators on the same line have equal precedence. When operators of equal precedence appear in the same expression, a rule must govern which is evaluated first. All binary operators except for the assignment operators are evaluated from left to right; assignment operators are evaluated right to left.
Operator Precedence | |
Operators | Precedence |
parenthesis | [];(), |
Postfix | expr++ expr-- |
Unary | ++expr --expr +expr -expr ~ ! |
Creation/cast | new,(type)expr |
Multiplicative | * / % |
Additive | + - |
Shift | << >> >>> |
Relational | < > <= >= instanceof |
Equality | == != |
bitwise AND | & |
bitwise exclusive OR | ^ |
bitwise inclusive OR | | |
logical AND | && |
logical OR | || |
Ternary | ? : |
Assignment | = += -= *= /= %= &= ^= |= <<= >>= >>>= |
The Simple Assignment Operator
Arithmetic operators are used to perform calculations using number types, these operators can only be applied between numeric data types including character.
If we apply assignment operator between boolean types, it leads to compile time error.
+ additive operator(also used for String concatenation)
- subtraction operator
* multiplication operator
/ division operator
% remainder operator
The “+” operator can also be applied between String and any other operand.
It is only the overloaded operator to add two numbers and also used as concatenate two strings and string and any data type.
No comments:
Post a Comment