Object oriented concepts with java

Post on 02-Jun-2015

318 views 7 download

Tags:

description

Object oriented concepts with java

Transcript of Object oriented concepts with java

Object Oriented Concepts With JAVA

Mehta Ishani2nd M.E.(C.S.E)

Why OOP?

• Traditional Procedural-Oriented languages– difficult to copy a function from one program and

reuse in another program because the the function is reference the headers, global variables and other functions.(i.e. not well-encapsulated as a self-contained reusable unit.)

– not suitable of high-level abstraction for solving real life problems.

Why OOP?

• Object-oriented programming (OOP) languages– class, which encapsulates both the static

attributes and dynamic behaviors (i.e. well-encapsulated, easier to reuse)

– permit higher level of abstraction for solving real-life problems

Benefits of OOP

• Ease in software design

• Ease in software maintenance

• Reusable software

What is JAVA?

• programming language expressly designed for use in the distributed environment of the Internet

• Simple, Secure, Robust, Complete Object Oriented and Platform Independent High level Language.

• It is portable and Multi-thread technology gives High performance.

JAVA

Hardware Platform

Java Platform

Software (OS) Platform

Operates and Controls H/W

Environment for Java

Development

JVM API

JAVA

How it Works:

JAVA

Java Program

Virtual Machine

Source code Bytecode

Java Compiler

Process of Compilation:

Java Interpreter

Virtual Machine

Real Machine

Bytecode

Object

• real word entity that has state and behavior• contains data (instance variables)

representing its state, and instance methods, which are the things it can do.

• instance of a class

Class

• Collection of objects• template, blueprint or contract that defines

what an object’s data fields and methods will be.

Abstraction

• Hiding internal details and showing functionality

• In java, we use abstract class and interface to achieve abstraction.

Encapsulation

• Binding (or wrapping) code and data together into a single unit

• A java class • Java bean

Inheritance

• When one object acquires all the properties and behaviors of parent object

• provides code reusability. • Used to achieve runtime polymorphism.

Inheritance

A

B

C

A B

CA-1

A-2

B-1

B-2

AB

Multi-level Inheritance Multiple Inheritance

Multiple Multi-level Inheritance

Types of Inheritance:

Ploymorphism

• "Poly" means "many" and "morph" means "form".

• When one task is performed by different ways

Polymorphism

• same word or symbol to be interpreted correctly in different situations based on the context

• There are two types of polymorphism :1.Compile-time polymorphism (Method Overloading/Static)2.Runtime Polymorphism (Method Overriding/Dynamic)

Ploymorphism

Method Overloading:having multiple methods with same name but

with different signature (number, type and order of parameters).

Method Overriding:When a subclass contains a method with the same

name and signature as in the super class then it is called as method overriding.

Summery

• An object is an instance of a class.• Using abstraction one can simulate real world objects.• Abstraction provides advantage of code reuse• Abstraction enables program open for extension• Encapsulation provides the security that keeps data and

methods safe from inadvertent changes.• Inheritance is parent-child relationship of class which is

mainly used for code reusability.• Polymorphism definition is that Poly means many and

morphos means forms.

Questions??????