Java Operators

Operators are used in java along with the variables to achieve arithmetic, logical, conditional & relational functionalities. There are different types of operators available as below.


Types of Operators:

  1. Assignment Operator
  2. Arithmetic Operators
  3. Relational Operators
  4. Conditional Operators
  5. Unary Operators
  6. Type Comparison Operator
  7. Bitwise Operators
  8. Equality Operator

 

Assignment Operator:

(=) It is used to assign any value to a variable.
Eg:

int a = 2;

Arithmetic Operators:

+ Addition operator
Subtraction operator
* Multiplication operator
/ Division operator
% Remainder operator

Relational Operators:

!= Not equal to
> Greater than
>= Greater than or equal to
< Less than
<= Less than or equal to

Conditional Operators:

&& Conditional-AND
|| Conditional-OR
?: Ternary (shorthand for if-then-else statement)

Unary Operators:

+ 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

Bitwise Operators:

~ Unary bitwise complement
<< Signed left shift
>> Signed right shift
>>> Unsigned right shift
& Bitwise AND
^ Bitwise exclusive OR
| Bitwise inclusive OR

Type Comparison Operator:

instanceof – Checks whether the object is of specific type and returns a boolean.

 

Equality Operator:

== Checks whether the value of two variables are equal.

Posted on July 1, 2014 in Java for Beginners

Share the Story

Leave a reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Back to Top