Operators in java

Operators are special symbol which are used to perform some operation on two or three or more operands or expression manipulation. There are following types of operators available in java.

  • Arithmetic Operators
  • Assignment Operator
  • Unary Operators
  • Equality and relational operators
  • Conditional Operators
  • Bitwise Operators

Arithmetic Operators: These are the operators which perform addition, subtraction, multiplication, and division.

Operator Description
+ Additive operator (also used for String concatenation)
- Subtraction operator
* Multiplication operator
/ Division operator
% Remainder operator

Assignment Operator: This operator  assign the value from right hand side to left side operand.It is denoted by “=”.

e.g. int x =3;

Unary Operators: These perform various operations such as incrementing/decrementing a value by one, negating an expression, or inverting the value of a boolean. It requires only one operand.

Operator Description
+ Unary plus operator; indicates positive value (numbers are positive without this, however)
Unary minus operator; negates an expression
++ Increment operator; increments a value by 1
Decrement operator; decrements a value by 1
! Logical complement operator; inverts the value of a boolean
Equality and relational operators: These operators are used to compare one operand to another like if one operand is greater than another, less than,equal to or not equal to etc.

Operators Description
== equal to
!= not equal to
> greater than
< less than
>= greater than or equal to
<= less than or equal to

Conditional Operators: These operator perform AND and OR operation on 2 boolean expressions.

Operator Description
&& Conditional-AND
|| Conditional-OR
Bitwise Operators: These operators perform bitwise and bit shift operations on integral types. These are not used much in practical scenario.

E.g. Let’s consider a = 60; and b = 13. Now, if performed binary operation how it will be?

a = 0011 1100

b = 0000 1101

Perform several operation as given below:

a&b = 0000 1100

a|b = 0011 1101

a^b = 0011 0001

~a  = 1100 0011

 

Ask Question
If you have any question, you can go to menu ‘Features -> Q&A forum-> Ask Question’.Select the desired category and post your question.
Print Friendly, PDF & Email
Data types in Java
OOPs concepts in java
Shekhar Sharma

Shekhar Sharma

Shekhar Sharma is founder of testingpool.com. He is an automation engineer having more than 8 years of experience who loves troubleshooting in automation and finding innovative ways to solve the problems. His other leisurely activities includes playing harmonica, paintings, sketching portrait, watching movies and travelling etc.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *