The document discusses the different types of operators in Java. It defines operators as symbols that operate on arguments to produce a result. It describes the different types of operands that operators can act on, such as numeric variables, primitive types, reference variables, and array elements. The document then lists and provides examples of the main types of operators in Java, including assignment, increment/decrement, arithmetic, bitwise, relational, logical, ternary, comma, and instanceof operators. It explains how each operator is used and provides simple code examples to illustrate their functionality.
OPERATOR
An operatoris a symbol that operates on one or
more arguments to produce a result.
Java provides a rich set of operators to
manipulate variables
3.
OPERANDS
An operandsare the values on which the operators act upon.
An operand can be:
-> A numeric variable - integer, floating point or character
-> Any primitive type variable - numeric and boolean
-> Reference variable to an object
-> A literal - numeric value, boolean value, or string.
-> An array element, "a[2]“
-> char primitive, which in numeric operations is treated
as an unsigned two byte integer
ASSIGNMENT OPERATORS
Theassignment statements has the following syntax :
<variable>=<expression>
Assigning primitive value
int a, b;
a = 2; // 2 is assigned to variable a
b = 5; // 5 is assigned to variable b
Assigning references
Home home1 = new Home(); //new object created
Home home2 = home1; //assigning the reference of home1 in home2
ASSIGNING VALUES EXAMPLE
6.
INCREMENT AND DECREMENTOPERATORS
++ AND --
The increment and decrement operators add an integer
variable by one.
increment operator:
two successive plus signs, ++
decrement operator: --
Common Shorthand
a = a + 1; a++; or ++a;
a = a - 1; a--; or --a
BITWISE OPERATORS
Java'sbitwise operators operate on individual bits
of integer (int and long) values.
If an operand is shorter than an int, it is
promoted to int before doing the operations.
RELATIONAL OPERATORS
Arelational operator compares two values and
determines the relationship between them.
For example, != returns true if its two operands are
unequal.
Relational operators are used to test whether two values
are equal, whether one value is greater than another, and
so forth
TERNARY OPERATORS
Javahas a short hand way by using ?: the ternary aka conditional operator
for doing ifs that compute a value.
Unlike the if statement, the conditional operator is an expression which can
be used for
20.
COMMA OPERATORS
Javahas an often look past feature within it’s for loop
and this is the comma operator.
Usually when people think about commas in the java
language they think of a way to split up arguments within
a functions parameters
INSTANCEOF OPERATORS
Thisoperator is used only for object reference variables. The
operator checks whether the object is of a particular type(class type
or interface type).
InstanceOf operator is wrriten as: