Operators in Java

Java operators are majorly of the following types:

  1. Arithmetic Operators
  2. Logical Operators
  3. Unary Operators
  4. Assignment Operators
  5. Ternary Operators
  6. Relational Operators
  7. Bitwise Operators
  8. Shift Operators
  9. instanceOf operator

1. Arithmetic Operators in Java

Java arithmetic operators are used to perform arithmetic operations in programs. There are majorly 5 arithmetic operators in Java.

a. Addition(+)

b. Multiplication(*)

c. Subtraction(-)

d. Division(/)

e. Modulo(%)

The addition operator performs an addition between two entities on either side of the operator.

The multiplication operator performs multiplication between two operands on each side of the operator.

The subtraction operator performs a subtraction between two operands on either side of the operator.

The division operator performs a division and returns the value of the division quotient.

The modulo operator returns the remainder after dividing the both two operands.

2. Logical Operators in Java

Java logical operators, as the name suggests, perform logical operations on both operands. There are two main types of logical operators

a) Logical AND in Java

Java Logical AND tests whether the two conditions on both sides of the expression are true. If both expressions are true, false is returned.

b) Logical OR in Java

This tests whether either of the two conditions of the expression is true. If either expression is true, it will evaluate as true. However, if none of the conditions are true, false is returned. Note that if the first expression is already true, it does not match the second expression and returns true.

3. Unary Operator in Java

Unary operators have only one operand. They are of the following types

a) Unary plus operator in Java

The unary plus operator converts byte and short character data type values ​​to integer values. However, it is superfluous because an explicit integer conversion can also be performed.

Characters converted to integers return their ASCII value.

b) Unary Negative Operator in Java

Consciously converts a positive value to a negative value.

c) Increment Operator in Java

The Java Increment Operator is used to increase the value of a given value by one. However, there are some concepts related to the increment operator.

  • Pre-increment- In this case, the variable’s value is increased first and then its usage / or its result is calculated. Example – ++ a;
  • Post-increment- In this case, the variable value is calculated first and then incremented. Example – a ++;

d) Decrement Operator in Java

The Java decrement operator is in contrast to the increment operator. This decreases the variable value by 1.

  • Pre-decrement- In this case, the value of the variable is first decremented and then calculated. Example- -a;
  • Post-decrement- In this case, the value of the variable is calculated first and then decremented by 1. Example- a-;

e) Logical Not Operator in Java

The Java Not logical operator inverts the value of a Boolean value. It is denoted by a !.

4. Assignment Operators in Java

Java assignment operators are used to assign values ​​to variables to the left of the equal sign. Associativity is right to left. This means that the values ​​on the right are assigned the values ​​on the left. The right side must be a constant or a defined variable.

  1. + = This returns left = left + right
  2. – = This returns left = left-right
  3. * = This returns left = left * right
  4. / = returns left = left / right
  5. % = This gives left = left% right

5. Ternary Operators in Java

The Java ternary operator consists of a condition statement followed by a question mark (?). It holds two expressions separated by a colon (:). If the condition is true, the first expression is executed; otherwise, the second expression is executed.

Syntax :

(Condition)?(expression 1):(expression 2);

6. Relational Operators in Java

Java relational operators are used to check the relationship between values ​​or variables. The output of comparison operators is always a Boolean value. Relational operators are used for if conditions and for loop constraints.

Some relational operators are:

A. <(Less than) – Returns true if the left entity is less than the right entity

B.> (Greater than) – returns true if the left entity is greater than the right entity.

vs. <= (less than or equal to) – returns true if the left entity is less than or equal to the right entity.

D.> = (greater than or equal to) – returns true if the variable on the left is greater than or equal to the entity on the right

and. == (equal to) – returns true if left and right entities are equal

F.! = (not equals to) – returns true if the left and right entities are not equal.

7. Bitwise Operators in Java

Bitwise Java operators are commonly used to perform operations on bits of data. The calculation counts the individual bits of a number, not the whole number itself. To learn Java visit Java Classes in Pune

a. AND(&)

b. OR(|)

c. XOR(^)


8. Shift Operators in Java

Java shift operators are also part of the bitwise operators.

  1. Left Shift- shifts the number two places to the left and fills the gaps with 0s.
  • Right Shift- shifts the number bits two places to the right and fills the gaps with 0. The sign of the number determines the value of the left bit.
  • Unsigned RIght Shift- This is also the same as Right Shift, but changes the value of the leftmost digit to 0.

9. instance Of Operator in Java

This is a type control operator. It checks whether a given object is an instance of a given class or not. Returns true if the object is a member of the class and false otherwise.

You may interested in “Analysis of Variance – A Statistical Method

Leave a Reply

Your email address will not be published.

twelve + 20 =