You are on page 1of 10

Java Operators

Jayson Angelo E. Vale Cruz


Operators
• Are symbols that perform logical or mathematical
functions on operands such as variable or
constants, and objects
Operators
• Unary Operators – requires only one operand
• In Java there at least four unary operators:
• Negation (-)
• Bitwise Complement (~)
• Increment (++)
• Decrement (--)
• Binary Operators – requires two operands
• Example:
• + - for addition or concatenation
• * - for multiplication
• / - for division
Arithmetic Operators
• An operator that perform mathematical operations

Operator Description

+ Addition – adds two operands

Subtraction – subtracts second


-
operand from the first
Multiplication – multiplies two
*
operands
Division – divides numerator by
/
denominator

% Modulo – remainder of the division


Increment and Decrement
• These are operators that only increment or
decrement a value of an operand

Operator Description
It increases the value of an operand
++
by 1
It decreases the value of an operand
--
by 1
Relational Operators
• These are operators that perform a comparison
between operands
Operator Description
It checks whether the left operand is
==
equal to the right operand
It checks whether if the left operand
>
is greater than the right operand
It checks whether if the left operand
<
is less than the right operand
It checks whether if the left operand
>= is greater than or equal the right
operand
It checks whether if the left operand
<= is less than or equal the right
operand
It checks whether the left operand is
!=
“not” equal to the right operand
Logical Operators
• These operators further expand the relational
operator since they add more control to it

Operator Description
An operator that returns true only
&&
when both operands are true
An operator that returns true when
||
at least 1 value is true

! It negates the value of an operand


Assignment Operator
• These are operators that assigns a value from the
right operand to the left operand

Operator Description

+= Assignment with Addition

-= Assignment with Subtraction

*- Assignment with Multiplication

/= Assignment with Division

%= Assignment with Modulo


Operator Precedence
• Is a hierarchy by which you can evaluate a given
expression

You might also like