28
Object oriented programming Presented by Uday Sharma Presenting Object oriented Programming (Java) and aspects of management of project. 1

Java tutor oo ps introduction-version 1

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: Java tutor  oo ps introduction-version 1

Object oriented programming

Presented byUday Sharma

Presenting Object oriented Programming (Java) and aspects of management of project.

1

Page 2: Java tutor  oo ps introduction-version 1

2

Why this tutorial?

To gain knowledge of Object Oriented ProgrammingWhy this tutorial for java why not for C++?• Aim to do practice on Object Oriented programming and

understanding of basic needs to be a programmer• Knowing C++ or Java will not make us a programmer but

understanding of project, project requirement , project management are really important • Company demand force you to work on different technology• Right platform to learn something new what we do not know

Page 3: Java tutor  oo ps introduction-version 1

3

Java developers and general software developers in permanent roles get an average salary of between €42,000 and €60,000 per year in 2012. This compares to an average salary of €40,000 to €55,000 in 2011.However, in London, Java developers managed to get an average salary of between €66,000 and €107,000, while in Sydney, they could get salaries of between €73,000 and €105,000.

Why java ?• Open source package•Wastly useful in Web technology• Java Embedded technology • Client / Server application • Graphical user interface• Design patterns • Test-driven development APIs

Why this tutorial?

Page 4: Java tutor  oo ps introduction-version 1

4

After Student life

CVObjectiv: bla bla –Study : bla bla– Programming language : C, C++Project work :

Java

Interview

Page 5: Java tutor  oo ps introduction-version 1

5

What is object – oriented?

State(Variable)

Entity (Methods)

Name BarkingColor PlayBreed SlobberHungry Biting

Asian countryNo money

GermanyMoneyrains

Barking

Biting

Object Properties

Page 6: Java tutor  oo ps introduction-version 1

6

Why object oriented necessary ?

Ballpen

Parts/Objects/Member of ballpen

12 3

4

5

6 7

Page 7: Java tutor  oo ps introduction-version 1

7

Properties of Parts/Objects/Member

Part 1 Part 2 Part 3 Part 4 Part 5 Part 6Name Name Name Name Name NameColor Color Color Upper-

Color Ink- Color

Size Size Size Size Size SizeGrip Grip Grip Grip Grip GripNotch Notch

SizeNotch Notch

Shape Shape Round Shape

Shape Shape

Why object oriented necessary ?

1

2

3

4 6

7

5

Page 8: Java tutor  oo ps introduction-version 1

8

Object oriented programming types

• Java• C#• .Net• PHP• Python• C++• Lisp• Ruby on Rain• Objective- C• Matlab• Lisp

Page 9: Java tutor  oo ps introduction-version 1

9

Real time example of OOPsConcept

Name, Shape,

grip,Diameter

2 3

5

6

7

1

Class Ballpen

Sub Class of class Ballpen

Name, Shape, color, grip, Diameter..

Name, Shape,

grip, Diameter

Nam

e,

Shap

eDi

ame

ter.

Sub Class of class Ballpen

Sub Class of class Ballpen

Class of class 2

Sub class of class 1

Member of Class 6, Class 7, Class 1, Class 2

Ballpen

S.Class 1

S.Class 3

S.Class 2

S.Class 5

S.Class 6

Class 7.

Inheritance

Name, shape,color and grip, Diameter

Encapsulation

Sun Rise Ltd

Sun Rise Ltd

Sun Rise Ltd.

Name,

Sh

ape,

co

lor,

gr

ip,

Diam

eter

..

Page 10: Java tutor  oo ps introduction-version 1

10

Interview question

• What is an Object in OOPS?

• What is an Attribute in OOPs?

• What is a Entity in OOPS?

• What is an Identity in OOPS?

• What is Encapsulation in OOPS?

• What is Inheritance in OOPS?

• What is Polymorphism in OOPS?

• What is Compile Time Polymorphism in OOPS?

• What is Run Time Polymorphism in OOPS?

• What is Access Modifier in OOPS?

Page 11: Java tutor  oo ps introduction-version 1

11

• Project have a purpose• Project are realistic• Project have duration• Project are complex• Project are collective• Project are unique• Project are adventure• Project can be assessed• Project are made up of stages

Characteristic of project?

Page 12: Java tutor  oo ps introduction-version 1

12

OOP: model, map, reusability, extention

DataMethodMethod

DataMethodMethod

DataMethodMethod

Object

Object Object

• Model the real worldproblem to user’sperceive

• Use similar metaphorin computational env.Construct reusablecomponents

• Create newcomponents fromexisting ones

Page 13: Java tutor  oo ps introduction-version 1

13

Examples of objects

Page 14: Java tutor  oo ps introduction-version 1

14

Classes: Objects with the same attribute and behavior

Person Object

Abstract into

Person ClassAttributes: Name, Age, SexMethod :Speak(), Listen(), Walk()

Abstract into

Vehicle ClassAttributes: Name, Model, CarMethod :Start(), Stop(), Accelerator()

Vehicle Object

Abstract into

Polygon ClassAttributes: Vertices, border, color, FillcolorMethod :Draw(), Erase(), Move()

Polygon Object

Page 15: Java tutor  oo ps introduction-version 1

15

Object Oriented Paradigm

Encapsulation

Data Abstration

Single Inheritance

Polymorphysm

Persistance

Delegation

Genericity

Multiple Inheritance

OOP Paradigm

Page 16: Java tutor  oo ps introduction-version 1

16

Encapsulation

Encapsulation

Data Abstration

Single Inheritance

Polymorphysm

Persistance

Delegation

Genericity

Multiple Inheritance

OOP Paradigm

It associates the code and the data it manipulates into a single unit and keeps them safe from external interference and misuse

Page 17: Java tutor  oo ps introduction-version 1

17

Data Abstraction

Encapsulation

Data Abstration

Single Inheritance

Polymorphysm

Persistance

Delegation

Genericity

Multiple Inheritance

OOP Paradigm

• The technique of creating new data types that are well suited to an application• It allows the creation of user defined data types, having the properties of built data types and a set of permitted operators• In Java, partial support• In C++, fully supported (e.g., operator overloading)

Page 18: Java tutor  oo ps introduction-version 1

18

Abstract Data Type

• A structure that contains both data and the actions to be performed on that data

• Class is an implementation of an Abstract Data Type

Page 19: Java tutor  oo ps introduction-version 1

19

Class

class Account {

//Attributes of account.private String accountName;private double accountBalance;

//Entity of account.public withdraw();public deposit();public determineBalance();} / / Class Account

Class is a set of attributes and operations that are performed on the attributes.

Account

+accountName+accountBalance

+withdraw();+deposit();+determineBal();

Page 20: Java tutor  oo ps introduction-version 1

20

Access Modifier

Private :Protected:Public:

Private: Drinking beer

Protected: Drinking beer

Public: Drinking beer

Page 21: Java tutor  oo ps introduction-version 1

21

Exercise

Car --- Create class for carBird --- Create class for Bird

Page 22: Java tutor  oo ps introduction-version 1

22

Solution for car

Car- hasNumberPlate- hasNoDoors

+ setDoors()+setRoof()+setGlass()+setHeadlight()+setWheel()

BMW

- hasType- hasName- hasColor- hasEngineType- hasShape

+ setDoors(hasshape,hasNoDoors)+setRoof(hasshape)+setGlass(hasShape)+setHeadlight(hasShape)+setWheel(hasShape)+setEngine()

Page 23: Java tutor  oo ps introduction-version 1

23

Bird Example

Page 24: Java tutor  oo ps introduction-version 1

24

Bird- hasHeight- hasWidth

+ setEye()+setLeg()+setWing()+setThroat()+setNape()+setBack()+setBill()+setTail

Parrot

- hasType- hasName- hasbackColor,wingscolor....- hasHeight- hasWidth- hasShape

+ setWing(hasColor)+setLeg(hasShape)+setWing(wingcolor)+setBill(hasShape)+setTail(hasShape)

Solution for bird

Page 25: Java tutor  oo ps introduction-version 1

25

Inheritance

• New data types (classes) can be defined as extensions to previously defined types

• Parent Class (Super Class) – Child Class (Sub Class)• Subclass inherits properties from the parent class

Parent

Child

Inherited Capability

Page 26: Java tutor  oo ps introduction-version 1

26

Inheritance-Example

• Example• Define Person to be a class• A Person has attributes, such as age, height, gender• Assign values to attributes when describing object

• Define student to be a subclass of Person• A student has all attributes of Person, plus attributes of

his/her own ( student no, course_enrolled)• A student has all attributes of Person, plus attributes of

his/her own (student no, course_enrolled)

• Define lecturer to be a subclass of Person• Lecturer has all attributes of Person, plus attributes of

His/her own ( staff_id, subjectID1, subjectID2)

Page 27: Java tutor  oo ps introduction-version 1

27

Inheritance- Example

Circle Class can be a subclass (inherited from ) of a parent class - Shape