Java Reference
In-Depth Information
Chapter 4
Operators
In this chapter, you will learn:
What operators are
The different types of operators available in Java
Operator precedence, which determines the order in which operators are evaluated when
multiple operators are used in the same expression
What Is an Operator?
An operator is a symbol that performs a specific kind of operation on one, two, or three operands, and produces a
result. The type of the operator and its operands determines the kind of operation performed on the operands and the
type of the result produced. Operators in Java can be categorized based on two criteria:
The number of operands they operate on
The type of operation they perform on the operands
There are three types of operators based on the number of operands. An operator is called a unary, binary, or
ternary operator based on the number of operands. If an operator takes one operand, it called a unary operator; if it
takes two operands, it called a binary operator; if it takes three operands, it called a ternary operator.
A unary operator can use postfix or prefix notation. In the postfix notation, the unary operator appears after
its operand.
operand operator // Postfix notation
For example,
num++; // num is an operand and ++ is a unary Java operator
In a prefix notation, the unary operator appears before its operand.
operator operand // Prefix notation
For example,
++num; // ++ is a Java unary operator and num is an operand
 
Search WWH ::




Custom Search