Page 70 - CA_Blue( J )_Class10
P. 70
dot(.) Operator
The dot(.) operator is used to invoke the members of a class or a package. It is also known as a member operator. Let
us see the following syntax:
System.out.println("We are students of class 10");
Here, the dot operator is used to access members of an object. The print method of PrintStream object uses the dot
operator to invoke the method on the object reference to the left. To access the members of a package we use:
import java.util.*;
The new Operator
The new operator is used to create the object of a class. Let us see the following syntax:
<class_name> <object> = new <constructor>;
Example:
Sum ob = new Sum();
Here, Sum is the class name, ob is the object created and Sum() is the constructor of the class Sum. The new operator
is used here to initialize the object ob of the class Sum. Thus, the new operator is used to assign space in the dynamic
memory (RAM) to store the data members and methods that are parts of an object. This operator is also used to create
an array:
int array[]=new int[10];
Therefore, using the new operator we can initialize all non-primitive data types in Java.
4.4 HIERARCHY OF OPERATORS
The word hierarchy means an arrangement of things according to relative significance. Java also uses this concept to
calculate the result of an expression according to the relative importance of the operators.
The hierarchy of operators in Java is also known as precedence of operators. Precedence of operators means the way
in which expressions will be calculated to obtain the correct result. Java uses this precedence when an expression
contains two or more operators. Java compiler decides which operator should be executed first on the basis of
precedence associated with the operator. To solve mathematical expressions, Java follows the BEDMAS rule:
Note: The meaning of letters used in the word BEDMAS is:
B-Bracket E-Exponents D-Division M-Multiplication A-Addition S-Subtraction
Let us take an example to understand the concept:
int a=5, b=10, c=2, d;
d = a + ((b - c) % a) * c;
= 5 + ((10-2) % 5) * 2; [solve inner most bracket]
= 5 + (8 % 5) * 2; [solve outer bracket]
= 5 + 3 * 2; [multiply]
= 5 + 6; [addition]
= 11;
Hence, d = 11.
Java follows the below hierarchy of operators:
Hierarchy Order Operators Precedence
1 postfix unary operator ++, --
2 unary operator (prefix) ++, --, +, -
3 multiplication, division and modulus *, /, %
4 addition and subtraction +, -
5 relational operator <, >, <=, >=
6868 Touchpad Computer Applications-X

