Operators in Java


Computer operators are special symbols that perform specific operations on operands to return a result. Most computer programming languages support pre-defined set of operators, similar in function to mathematical operators.

Many a times, these operators are built-into a programming language, while at other times these may be defined in the program itself.  Therefore, languages such as C support built-in operators, while C++ and Java contain program-defined operators.

Operator precedence and associativity are defined in computer programming language specifications. Similarly, the position of the computer operator with respect to the computer operands can be prefix, postfix, or infix.

In the Java programming language, the operators act according to their precedence. Therefore, it is important that we know in advance about the operators with highest precedence, as these operators are evaluated before the operators with lower precedence. On the other hand, all the operators appearing on the same line have equal precedence. The Java compiler evaluates all operators, except the binary operators from left to right. Only the assignment operators are evaluated from right to left.

The following table lists the operators according to their precedence.

Operator Precedence

Name of Operator Order of Precedence
Postfix expr–,  expr++
Unary ++expr, –expr, +expr, -expr, ~ !
Multiplicative * / %
Additive +, -
Shift <<, >>, >>>
Relational <, >, <=, >=, instanceof
Equality ==, !=
Bitwise AND &
Bitwise exclusive OR ^
Bitwise inclusive OR |
Logical AND &&
Logical OR ||
Ternary ?, :
Assignment = ,+=, -=, *=, /= ,%=, &=, ^=, |=, <<=, >>= >>>=

Programmers tend to use some operators mot than the others. For example, they tend to us the assignment operator “=”much more than the unsigned left shift operator “>>>=”

Leave a Reply

  

  

  

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>