An operator takes one or more arguments and produces a new value.
Precedence
Operator precedence defines how an expression evaluates when several operators are present.
Assignment
Assignment is performed with the operator “=”, it means “Take the value of the right-hand side and copy it into the left-hand side.”
The primitive holds the actual value and not a reference to an object.
When you assign “from one object to another”, you are actually copying a reference from one place to another.
Mathematical Operator
The basic mathematical operators
addition (+)
subtraction (-)
multiplication (*)
division (/) Integer division truncates, rather than rounds.
modulus (%)
Java uses the shorthand notation from C/C++ that performs an operation and an assignment at the same time.
+=
-=
*=
/=
%=
Unary minus and plus operators
minus (-) inverts the sign on the data
plus (+)
Auto increment and decrement
increment (++) increase by one unit
decrement (--) decrease by one unit
String operator
+ if an expression begins with a String, then all operands that follow must be Strings.
+=
Relational operators
Relational operators generate a boolean result.
less than (<)
greater than (>)
less than or equal to (<=)
greater than or equal to (>=)
equivalent (==)
not equivalent (!=)
Logical operators
Logical operators produces a boolean result
AND (&&)
OR (||)
NOT (!)
Short-circuiting
The expression will be evaluated only until the truth or falsehood of the entire expression can be unambiguously determined. As a result, the latter parts of a logical expression migth not be evaluated.
A boolean value is automatically converted to an appropriate text form if it is used where a String is expected.
Bitwise operators
The bitwise operators allow you to manipulate individual bits in an integral primitive date type.
Bitwise operatos perform Boolean algebra on the corresponding bits in the two arguments to produce the result.
bitwise AND (&)
bitwise OR (|)
bitwise NOT (~)
bitwise XOR (^)
Shift operators
The shift operators also manipulate bits.
left-shift operator (<<)
signed right-shift operator (>>) if the value is positive, zeroes are inserted at the higher-order bits; if negative, ones are inserted.
unsigned right-shift operator (>>>) regardless of the sign, zeroes are inserted at the higher-order bits.
Shifts can be combined with the equal sign (shorthand notation)
<<=
>>=
>>>=
Ternary if-else operator
The ternary operator, also called the conditional operator, is unusual because it has three operands.
boolean-exp ? true-value : false-value
The ternary operator is different from if-else because it produces a value.
Literals
When you insert a literal value into a program, the complier knows exactly what type to make it.
A trailing character after a literal value establishes its type.
L (long)
F (float)
D (double)
0 (octal)
0x (hexadecimal)
Casting
Casting from float to integer value always truncates the number.
The largest data type in an expression is the one that determines the size of the result of that expression.