0% found this document useful (0 votes)
13 views5 pages

Operators

Operators are special symbols that perform operations on operands in a Java program. There are three main types of operators based on the number of operands: unary, binary, and ternary. Symbolic operators use symbols like + and -, while named operators use keywords. Common symbolic operators include arithmetic, relational, logical, assignment, increment/decrement, conditional, and bitwise operators. Operators allow programmers to manipulate variables and perform calculations in Java expressions.

Uploaded by

Japesh reddy
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
0% found this document useful (0 votes)
13 views5 pages

Operators

Operators are special symbols that perform operations on operands in a Java program. There are three main types of operators based on the number of operands: unary, binary, and ternary. Symbolic operators use symbols like + and -, while named operators use keywords. Common symbolic operators include arithmetic, relational, logical, assignment, increment/decrement, conditional, and bitwise operators. Operators allow programmers to manipulate variables and perform calculations in Java expressions.

Uploaded by

Japesh reddy
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 5

1. What is an Operator in Java?

Ans: A operator is a special symbol that tells the compiler to perform specific
mathematical or logical operations. It is generally used in a program to perform a
particular function on operands.
2. What are the types of operators based on the number of operands?
Ans: There are three types of operators in java based on the number of operands.
They are:
 Unary operator -- Operators that acts on single operand.
 Binary operator -- Operators that acts on two operands.
 Ternary operator -- Operators that acts on three operands.
3. What is Expression in Java?
Ans: An expression in java is a combination of operators and operands that is used to
perform mathematical or logical calculations. In simple words, it is a combination of
variables, constants, and operators.
4. What are the types of operators?
Ans: There are two types of operators
 Symbolic Operator
 Named Operator
Symbolic Operator:
If a symbol like +, -, * etc. is used as an operator, it is called symbolic operator.
There are mainly eight types of operators based on symbols. They are as follows:
 Arithmetic operators ⇒ +, -, *, /, etc.
 Relational operators ⇒ <, >, <=, >=, = =,!=
 Logical operators ⇒ &&, ||,!
 Assignment operators ⇒ =,
 Increment and decrement operators ⇒ + +, – –
 Conditional operators ⇒ ?:
 Bitwise operators ⇒ &,!, ^, ~, <<, >>, >>>
 Shift operators ⇒ <<, >>, >>>.
Named Operator:
If a keyword is used as an operator, it is called named operator. The named operator
is instance of.
Instance of - The instance of keyword checks whether an object is an instance of a
specific class or an interface. The instance of keyword compares the instance with
type. The return value is either true or false.

5. Explain about all Symbolic Operators?


Ans:
 Arithmetic operators: Operators that are used to performing fundamental
arithmetic operations such as addition, subtraction, multiplication, and
division on numeric data types are called arithmetic operators.
Java supports five types of arithmetic operators. They are:
 + Addition
 – Subtraction
 * Multiplication
 / Division
 % Modulo division (Remainder).
Relational Operators: Operators that are used to perform the comparison
between two numeric values or two quantities. They are generally used in
looping and branching statements to create conditions.
Java supports six types of relational operators. They are as follows:
 < Less than
 <= Less than or equal to
 > Greater than
 >= Greater than or equal to
 == Equal to
 != Not equal to
The result of all relational operators is always of a Boolean type. It always
returns true or false.
Logical Operators: Logical operators are used to check whether an expression
is true or false.
These operators are also called Boolean operators because they return a
Boolean value.
Java supports three types of logical operators. They are as follows:
 && AND operator
 || OR operator
 ! NOT operator
Unary Operator: The operator that acts on a single operand is called unary
operator in Java. A unary operator uses a single variable.
The types of unary operators in java are as follows:
 Increment operator ( ++ )
 Decrement operator ( — )
Ternary Operator: The character pair ?: is called ternary operator in Java
because it acts on three variables. This operator is also known as conditional
operator.
Bitwise Operator: An operator that acts on individual bits (0 or 1) of the
operands is called bitwise operator in java.
6. What is increment operator (++) in Java?
Ans: The operator which is used to increase the value of a variable (operand) by one
is called increment operator in java. It can have the following forms: ++x; or x++;
7. Explain Pre incrementation (Prefix) and Post incrementation (Postfix).
Ans:
Pre incrementation (Prefix): When we write ++ operator before a variable, it is called
pre incrementation or prefix. In pre incrementation, the increment is done first and
then any other operation will be performed.
Post incrementation (Postfix): When we write ++ operator after a variable, it is
called post incrementation or postfix. In post-increment, all the other operations are
performed first, and then at the end increment is done only.
8. What is a decrement operator in Java?
Ans: The operator which is used to decrement the value of a variable (operand) by
one is called decrement operator in java. It can have the following forms: –x; or x–;
9. Explain Pre decrementation (Prefix) and Post decrementation (Postfix).
Ans:
Pre decrementation (Prefix): When we write — operator before a variable, it is
called pre decrementation or prefix. In pre decrementation, the decrement is done
first and then any other operation will be performed.
Post decrementation (Postfix): When we write — operator after a variable, it is
called post decrementation or postfix. In post-decrement, all the other operations
are performed first, and then at the end increment is done only.
10. What is concatenation in Java?
Ans. Concatenation is the process of combining two or more strings to form a new
string by subsequently appending the next string to the end of the previous strings.
In Java, two strings can be concatenated by using the + or += operator, or through
the concat() method, defined in the java.
11. Can we use increment and decrement for literals?
Ans: We can use the increment decrement operator for the variables which stores
numerals and characters.
12. How does Java store negative numbers?
Ans: Negative integers are stored as the two's complement of their absolute value.
The two's complement of a positive number is when using this notation, a negative
number

You might also like