| Home Page |
| Course Page |
The following table lists all the operators in order of precedence from highest to lowest. All the operators are binary, except those shown as unary with expr, the creation and cast operators (which are also unary), and the conditional operator (which is ternary). Operators with the same precedence appear on the same line of the table:
| postfix operators | [] . (params) expr++ expr-- |
| unary operators | ++expr --expr +expr -expr ~ ! |
| creation or cast | new (type)expr |
| multiplicative | * / % |
| additive | + - |
| shift | << >> >>> |
| relational | < > >= <= instanceof |
| equality | == != |
| bitwise AND | & |
| bitwise exclusive OR | ^ |
| bitwise OR | | |
| logical AND | && |
| logical OR | || |
| conditional | ?: |
| assignment | = += -= *= /= %= >>= <<= >>>= &= ^= |= |
All binary operators other than assignment operators are left-associative. Assignment is right-associative -- in other words, a=b=c is equivalent to a=(b=c).
Precedence can be overridden using parentheses. The expression x+y*z multiplies y by z first and then adds x, whereas (x+y)*z adds x and y first and multiplies the result by z.
The primitive data types of Java are:
| boolean | either true or false |
| char | 16-bit Unicode 1.1.5 character |
| byte | 8-bit signed two's-complement integer |
| short | 16-bit signed two's-complement integer |
| int | 32-bit signed two's-complement integer |
| long | 64-bit signed two's-complement integer |
| float | 32-bit IEEE 754-1985 floating-point number |
| double | 64-bit IEEE 754-1985 floating-point number |
| Course Page |
| Home Page |