Java Operators
Java Operators
OPERATORS
Operators
are symbols that carry out mathematical or logical functions
on an operand or operands such as literals, constants,
variables and objects.
Unary Operators
bitwise complement (~), negation (-), increment (++) and
decrement (- -) have only one operand. They can change
their operand's value without the use of an assignment
operator (=).
Binary Operators
have exactly two operands and uses the assignment
operator for the result.
Ternary Operators
has at most three operands. In Java, the only ternary
operator is the conditional operator (? :).
Arithmetic Operators
Operators Description
+ Addition
- Subtraction
* Multiplication
/ Division
% Modulo
++ Increment
-- Decrement
Relational Operators
are considered as binary operators since they
show the relationship between two operands. It
yield a true or false value.
Operators Description
< Less than
<= Less than or equal to
> Greater than
>= Greater than or equal to
== Equal to
!= Not Equal to
Logical Operators
as logical operators are governed by logical rules,
truth tables are necessary to evaluate logical
operations. It is strongly suggested that the
programmer keeps the ff. truth tables in mind
when evaluating logical operations.
Operators Description
! NOT
& AND
| OR
&& short-circuit AND
|| short-circuit OR
AND
The binary operator AND operator returns false
except when both operands have a true value.
Operand2 Result
! false true
! true false
Coding Time:
1. Length and breadth of a rectangle are
15 and 27 respectively. Create a
program that will calculate the area
and perimeter of the rectangle.
2. Create a program to check if the two
numbers 35 and 75 are equal.