Java Basics: Operators
Programming Fundamentals in Java
ARITHMETIC OPERATORS
OPERAT DESCRIPTION
OR
+ Addition
- Subtraction
* Multiplication
/ Division
% Modulus
++ Increment (x = x+1)
-- Decrement (x = x-1)
RELATIONAL OPERATORS
OPERAT DESCRIPTION
OR
== equal to
!= not equal to
> greater than
< less than
>= greater than or equal to
<= less than or equal to
BITWISE OPERATORS
OPERAT DESCRIPTION
OR
& bitwise AND
| bitwise OR
^ bitwise XOR
~ 1’s Complement
<< Binary shift left
>> Binary shift right
>>> zero fill right shift
LOGICAL OPERATORS
OPERAT DESCRIPTION
OR
&& logical and
|| logical or
! logical not
ASSIGNMENT OPERATORS
OPERAT DESCRIPTION
OR
= simply assign
+= add then assign
-= subtract then assign
*= multiply then assign
/= divide then assign
%= get the modulo then assign
<<= binary shift left then assign
>>= binary shift right then
assign
ASSIGNMENT OPERATORS
OPERAT DESCRIPTION
OR
&= do bitwise AND then assign
|= do bitwise OR then assign
^= do bitwise XOR then
assign
CONDITIONAL/TERNARY OPERATOR
This is used to evaluate Boolean expressions. The goal of
the operator is to decide which value to assign in the
variable.
syntax:
(<condition>) ? <value if true> : <value if false>;
INSTANCEOF OPERATOR
This is used only for variable having reference data type
(object reference variable). The operator checks whether the
variable is of a particular type of class or interface.
syntax:
<object_reference_variable> instanceof
<classname/interfacename>