Operators and Expressions in Java

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Mercy Memorial School, Kanpur

Operators and Expressions in Java


1) What do you mean by operators? Name its types.
Ans. Answer is given on page 89 Q.1.
2) What is a unary operator? Give two examples.
Ans. The operator that work with single operand is known as unary operator. E.g. ++x , x++
3) Write about binary arithmetic operators with one example.
Ans. The binary arithmetic operator work on two operands. E.g. +, *, / etc.
4) What do you mean by logical operators? Name all the logical operators.
Ans. Answer is given on page 89 Q.5.
5) Write in brief about Java shorthand operators? Give two examples.
Ans. Answer is given on page 90 Q.8.
6) What do you mean by ternary operators and conditional expression?
Ans. Ternary Operator – Those operators that works upon three expressions using symbols ? and :
are known as conditional or ternary operators.
Conditional Expression – The expression which consists of conditional or ternary operators (? and :)
to execute one from the two statements depending on the result of the test condition is known as
conditional expression.
7) What do you mean by ASCII codes?
Ans. Answer is given on page 89 Q.3.
8) Differentiate between a relational expression and logical expression.
Ans. Relational Expression – A valid combination of operands and only relational operators (>, <, ==
etc.) and returns boolean result in the form of false and true is known as a relational expression.
Logical Expression – The expression which consists of two or more relational expressions along with
only logical operators (&&, || or !) and returns boolean result in the form of false and true is known
as a Logical expression.
9) State the purpose of new operator with one example.
Ans. The new operator dynamically allocates the memory for an object and returns a reference to it.
E.g. Scanner sc = new Scanner (System.in);
10) What do you mean by precedence of operators? Make the complete table of it.
Ans. The precedence of an operator determines which operator (in an expression) is to be used first
for the evaluation. Execution of operators of equal precedence is left associative.
PRECENDENCE OF OPERATOR TABLE

Rank Operators
1(Highest) ()[]
2 ! ++ - -
3 */%
4 + -
5 < <= > >=
6 == !=
7 &&
8 ||
9 !
10(Lowest) = += *= -= /=

11) What do you mean by compound statement?


Ans. A block or compound statement is a group of zero or more statements grouped together
between opening and closing braces.
12) What do you mean by expression?
Ans. A valid combination of operands and operators is known as expression. It may be pure or
mixed.
13) What is a statement in Java?
Ans. A Java statement is a valid expression that terminates with a semicolon (;). It is also known as
expression.
14) Define the purpose of dot ( . ) operator.
Ans. The dot operator or member reference operator is used to access the member of an object or
to access the member of a class.
15) Differentiate between operator and expression.
Ans. Operator: The specific symbols that carries out some operations using operands is called
operators.
Expression: A valid combination of operands and operators is known as expression.
16) Differentiate between Prefix and Postfix.
Ans. Prefix: If increment (++) or decrement (- -) used before its operand, it is known as prefix.
E.g.: ++x, --x
Postfix: If increment (++) or decrement (- -) used after its operand, it is known as postfix.
E.g.: x++, x--

You might also like