1 of 13

Object Oriented Programming

By

​

S.V.V.D.Jagadeesh

Sr. Assistant Professor

Dept of Artificial Intelligence & Data Science

​

​

LAKIREDDY BALI REDDY COLLEGE OF ENGINEERING

2 of 13

  • Tokens
  • Identifiers
  • Keywords
  • Separators
  • Data Types

​

S.V.V.D.Jagadeesh

Thursday, August 31, 2023

Previous Discussion

LBRCE

OOP

3 of 13

At the end of this session, Student will be able to:

  • CO1: Apply different sets of operators for solving problems. (Apply- L3)

S.V.V.D.Jagadeesh

Thursday, August 31, 2023

Session Outcomes

LBRCE

OOP

4 of 13

  • Definition
  • An operator performs a particular operation on the operands it is applied on.
  • Types of operators
    • Assignment Operators
    • Arithmetic Operators
    • Unary Operators
    • Equality Operators
    • Relational Operators
    • Conditional Operators
    • instanceof Operator
    • Bitwise Operators
    • Shift Operators

​

S.V.V.D.Jagadeesh

Thursday, August 31, 2023

Operators

LBRCE

OOP

5 of 13

S.V.V.D.Jagadeesh

Thursday, August 31, 2023

Arithmetic Operators

Operator

Description

Example

+

Addition

int i = 8 + 9; byte b = (byte) 5+4;

-

Subtraction

int i = 9 – 4;

*

Multiplication

int i = 8 * 6;

/

Division

int i = 10 / 2;

%

Remainder

int i = 10 % 3;

LBRCE

OOP

6 of 13

S.V.V.D.Jagadeesh

Thursday, August 31, 2023

Assignment Operators

Operator

Description

Example

=

Assignment

int i = 10;

int j = i;

​

+=,-=,&=,<<= etc

Short-Hand Assignment

int a=10;

a+=10;

LBRCE

OOP

7 of 13

S.V.V.D.Jagadeesh

Thursday, August 31, 2023

Relational/Equality Operators

Operator

Description

Example

>

Greater than

if ( x > 4)

<

Less than

if ( x < 4)

>=

Greater than or equal to

if ( x >= 4)

<=

Less than or equal to

if ( x <= 4)

Operator

Description

Example

==

Equality

If (i==1)

!=

Non equality

If (i != 4)

LBRCE

OOP

8 of 13

S.V.V.D.Jagadeesh

Thursday, August 31, 2023

Logical Operators

Operator

Description

Example

&&

Logical and

If (a == 4 && b == 5)

||

Logical or

If (a == 4 || b == 5)

!

Logical Not

If (!a)

LBRCE

OOP

9 of 13

S.V.V.D.Jagadeesh

Thursday, August 31, 2023

Bitwise and Shift Operators

Operator

Description

Example

&

Bitwise and

001 & 111 = 1

|

Bitwise or

001 | 110 = 111

^

Bitwise ex-or

001 ^ 110 = 111

~

Reverse

~011 = -10

Operator

Description

Example

>>

Right shift

4 >> 1 = 100 >> 1 = 010 = 2

<<

Left Shift

4 << 1 = 100 << 1 = 1000 = 8

>>>

Unsigned Right shift

4 >>> 1 = 100 >>> 1 = 010 = 2

LBRCE

OOP

10 of 13

S.V.V.D.Jagadeesh

Thursday, August 31, 2023

instance of operator

Operator

Description

Example

instanceof

Instamce of

If (john instance of person)

LBRCE

OOP

11 of 13

S.V.V.D.Jagadeesh

Thursday, August 31, 2023

Precedence & Associativity of Operators

Category

Operators

Associativity

Parantheses

()

Left to right

Postfix

++ - -

Left to right

Unary

+ - ! ~ ++ - -

Right to left

Multiplicative

* / %

Left to right

Additive

+ -

Left to right

Shift

<< >>

Left to right

Relational

< <= > >=

Left to right

Equality

== !=

Left to right

Bitwise AND

&

Left to right

Bitwise XOR

^

Left to right

Bitwise OR

|

Left to right

Logical AND

&&

Left to right

Logical OR

||

Left to right

Conditional

?:

Right to left

Assignment

= += -= *= /= %=>>= <<= &= ^= |=

Right to left

LBRCE

OOP

12 of 13

  • Write a java program to swap two nos without using third variable.
  • Note: your logic for swapping the numbers should be written in a single statement

​

S.V.V.D.Jagadeesh

Thursday, August 31, 2023

Assignment

LBRCE

OOP

13 of 13

  • Operator-Definition, Types of Operators
  • Arithmetic Operators
  • Assignment Operators
  • Relational/Equality Operators
  • Logical Operators
  • Bitwise and Shift Operator
  • Instance of operator
  • Precedence & Associativity of Operators

​

​

​

S.V.V.D.Jagadeesh

Thursday, August 31, 2023

Summary

LBRCE

OOP