You are on page 1of 10

Assignment of

programming language
JAVA

Submitted to
submitted by
Mr. Mohit Angurala
Girish Puri

2014CSA1715

B.tech CSE
Java has a rich set of operators with which we can manipulate
variables. Java operators can be divided into the following
groups :

1.ARITHMETIC
2.RELATIONAL
3.BITWISE

1. ARITHMETIC OPERATORS :
In mathematical expressions, the usage of Arithmetic operators
are in same way that they are used in algebra. The following
table lists the arithmetic operators:

Assume integer variable A holds 40 and variable B holds 55,


then:

Sr.No.
Operators and examples
( + ) Addition
1 It Adds values on either side of the operator
Example: A + B will give 95.

( - ) Subtraction
2 It Subtracts right-hand operand from left-hand
operand
Example: A - B will give -15.

( * ) Multiplication
3 It Multiplies values on Left and right side of the
operator
Example: A * B will give 2200.

( / ) Division
4 It Divides left-hand operand by right-hand
operand
Example: B / A will give 1.375.
( % ) Modulus
5 It returns remainder after dividing left-hand
operand by right-hand operand
Example: B % A will give 15.
( ++ ) Increment
6 Increases the value of operand by 1
Example: B++ gives 56.

( -- ) Decrement
7 Decreases the value of operand by 1
Example: B-- gives 54 .
2. RELATIONAL OPERATORS
It is a programming language constructor or operator that test
or define some kind of relations between two entities. These
include numerical equality and inequalities. Relational
operators are binary operators. It returns boolean value I.e.it
will return true or false. Most of the relational operators are
used in if statement and inside looping statement in order to
check truthness or falseness of condition.

It has six operators are following :---

== (equal to)

It Checks if the values of two operands are equal or not, if yes


then condition will be evaluated true.

Example: (A == B) is false.

!= (not equal to)


It Checks whether the values of two operands are equal or not,
if values are unequal then condition will be evaluated true.

Example: (A != B) is true.

> (greater than)

It Checks whether the value of left side operand is greater than


the value of right side operand, if yes then condition will be
evaluated true.

Example: (A > B) is false.

< (less than)

It Checks whether the value of left side operand is less than the
value of right side operand, if yes then condition will be
evaluated true.

Example: (A < B) is true.

>= (greater than or equal to)


It Checks whether the value of left side operand is greater than
or equal to the value of right side operand, if yes then condition
will be evaluated true.

Example: (A >= B) is false.

<= (less than or equal to)

It Checks whether the value of left side operand is less than or


equal to the value of right side operand, if yes then condition
will be evaluated true.

Example: (A <= B) is true.


3. BITWISE OPERATOR
These operator operates on one or more bit patterns or binary
numerals at the bit level. It is a fast and simple action directly
supported by the processor, and it is used to change values for
calculations and for comparisons,

Java has several bitwise operators, which can be applied to


different types like integer, long, short, char, and byte.

Bitwise operator performs bit-by-bit operation by working on


bits.

For Example if a = 60 , b = 13; if we convert these in binary


format, they will be as follows:

a = 0011 1100

b = 0000 1101

-----------------

a&b = 0000 1100

a|b = 0011 1101

a^b = 0011 0001

~a = 1100 0011
Type of Bitwise operators are following :-

( & ) bitwise and

Binary AND Operator copies a bit to result if it exists in both the


operands. i.e. the bits which are common in both will be 1 and
else will be 0.

Example: (A & B) will give 12 which is 0000 1100

( | ) bitwise or

Binary OR Operator copies a bit if it exists in either of the


operands. i.e. the bits which are 1 in any of a or b will be 1 else
will be 0.

Example: (A | B) will give 61 which is 0011 1101

( ^ ) bitwise XOR

Binary XOR Operator copies the bit if it is set in only one


operand but not set in both. i.e. the bits which are 1 in only one
operand will be one else will be 0.

Example: (A ^ B) will give 49 which is 0011 0001

4
( ~ ) bitwise compliment

This Operator flips bits and it is a unary operator.

Example: ( ~A ) will output -61. Due to a signed binary number,


in 2's complement form is 1100 0011.

5
( << ) left shift

In Binary Left Shift Operator, value of left operand is moved left


by that number of bits which are specified by the right
operand.

Example: A << 2 will output 240 which is 1111 0000

( >> ) right shift

In Binary Right Shift Operator, value of the left operand is


moved right by that number of bits which are specified by the
right operand.

Example: A >> 2 will output 15 which is 1111

( >>> ) zero fill right shift

In Shift right zero fill operator, the value of left operand is


moved right by that number of bits which are specified by the
right operand and those values are filled up with zeros which
are shifted.
Example: A >>>2 will give 15 which is 0000 1111