Top Banner
Introduction to Object Oriented Programming 7/23/2019 1 P.Poovizhi/CS8392/Overview of Java & Abstraction
35

Introduction to Object Oriented Programming · Java is a high level, robust, secured and object-oriented programming language. Platform Any hardware or software environment in which

Sep 24, 2019

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Introduction to Object Oriented Programming · Java is a high level, robust, secured and object-oriented programming language. Platform Any hardware or software environment in which

Introduction to Object Oriented Programming

7/23/2019

1P.Poovizhi/CS8392/Overview of Java & Abstraction

Page 2: Introduction to Object Oriented Programming · Java is a high level, robust, secured and object-oriented programming language. Platform Any hardware or software environment in which

Introduction – Programming Language

7/23/2019P.Poovizhi/CS8392/Overview of Java & Abstraction

2

Programming language

Imperative

Procedural

Object Oriented

Declarative

Functional

Logic

Query

Programming - Process of writing instructions in a languagethat can be understood by the computer so that a desired taskcan be performed by it

Three major families• Machine languages• Assembly languages• High-Level languages

Page 3: Introduction to Object Oriented Programming · Java is a high level, robust, secured and object-oriented programming language. Platform Any hardware or software environment in which

Imperative & Declarative programming

Imperative programming

List<int> newList = new List<int>();foreach (var item in lists){foreach (var number in items){

newList.Add(number);}}

Declarative programming

List<int> list01 = new List<int>{1,2,3};List<int> list02 = new List<int>{4,5,6};List<int> list03 = new List<int>{7,8,9};List<List<int>> lists = new

List<List<int>>{list01,list02,list03};

7/23/2019

3

P.Poovizhi/CS8392/Overview of Java & Abstraction

Page 4: Introduction to Object Oriented Programming · Java is a high level, robust, secured and object-oriented programming language. Platform Any hardware or software environment in which

Procedural and Object oriented Programming

Procedural COBOL, FORTRAN and C accomplish the tasks

such as reading,calculating andprinting.

Object oriented Programming C++ , Java , Visual

Basic.NET allows a mode of

modularizingprograms by formingseparate memoryarea for data as wellas functions that isused as object formaking copies

7/23/2019

4

P.Poovizhi/CS8392/Overview of Java & Abstraction

Page 5: Introduction to Object Oriented Programming · Java is a high level, robust, secured and object-oriented programming language. Platform Any hardware or software environment in which

7/23/2019P.Poovizhi/CS8392/Overview of Java & Abstraction

5

Page 6: Introduction to Object Oriented Programming · Java is a high level, robust, secured and object-oriented programming language. Platform Any hardware or software environment in which

Overview of JAVA

7/23/2019

6P.Poovizhi/CS8392/Overview of Java & Abstraction

Page 7: Introduction to Object Oriented Programming · Java is a high level, robust, secured and object-oriented programming language. Platform Any hardware or software environment in which

What is Java?

James Gosling and Sun Microsystems

Oak

Java, May 20, 1995, Sun World

HotJavaThe first Java-enabled Web browser

JDK Evolutions

J2SE, J2ME, and J2EE (not mentioned in the book,but could discuss here optionally)

7/23/2019P.Poovizhi/CS8392/Overview of Java & Abstraction

7

Page 8: Introduction to Object Oriented Programming · Java is a high level, robust, secured and object-oriented programming language. Platform Any hardware or software environment in which

What is Java?

James Gosling, Mike Sheridan, and PatrickNaughton - June 1991. The small team of sunengineers called Green Team.

Designed - small, embedded systems in electronicappliances like set-top boxes.

Called as "Greentalk“ & file extension - .gt. After that, it was called Oak - Developed by Green

project

7/23/2019P.Poovizhi/CS8392/Overview of Java & Abstraction

8

Page 9: Introduction to Object Oriented Programming · Java is a high level, robust, secured and object-oriented programming language. Platform Any hardware or software environment in which

What is Java?

Why Oak? Oak is a symbol of strength and choosen as a national

tree of many countries like U.S.A., France, Germany,Romania etc.

In 1995, Oak was renamed as "Java”. Why had they choosen java name for java

language? "dynamic", "revolutionary", "Silk", "jolt", "DNA" etc. Unique – suggested by Gosling

7/23/2019P.Poovizhi/CS8392/Overview of Java & Abstraction

9

Page 10: Introduction to Object Oriented Programming · Java is a high level, robust, secured and object-oriented programming language. Platform Any hardware or software environment in which

What is Java?

Java is an island of Indonesia where first coffee wasproduced (called java coffee).

Java is just a name not an acronym. Originally developed by James Gosling at Sun

Microsystems and released in 1995. Time magazine called Java one of the Ten Best

Products of 1995. JDK 1.0 released in(January 23, 1996).

7/23/2019P.Poovizhi/CS8392/Overview of Java & Abstraction

10

Page 11: Introduction to Object Oriented Programming · Java is a high level, robust, secured and object-oriented programming language. Platform Any hardware or software environment in which

Java Version

JDK Alpha and Beta (1995)

JDK 1.0 (23rd Jan, 1996) JDK 1.1 (19th Feb, 1997) J2SE 1.2 (8th Dec, 1998) J2SE 1.3 (8th May, 2000) J2SE 1.4 (6th Feb, 2002) J2SE 5.0 (30th Sep, 2004)

Java SE 6 (11th Dec, 2006)

Java SE 7 (28th July, 2011)

Java SE 8 (18th March, 2014)

Java SE 9 (21st Sep, 2017) Java SE 10 (20th March,

2018)

7/23/2019

11

P.Poovizhi/CS8392/Overview of Java & Abstraction

Page 12: Introduction to Object Oriented Programming · Java is a high level, robust, secured and object-oriented programming language. Platform Any hardware or software environment in which

JDK Edition

Java Standard Edition (J2SE) J2SE can be used to develop client-side standalone

applications or applets. Java Enterprise Edition (J2EE)

J2EE can be used to develop server-side applicationssuch as Java servlets and Java ServerPages.

Java Micro Edition (J2ME). J2ME can be used to develop applications for mobile

devices such as cell phones.

7/23/2019P.Poovizhi/CS8392/Overview of Java & Abstraction

12

Page 13: Introduction to Object Oriented Programming · Java is a high level, robust, secured and object-oriented programming language. Platform Any hardware or software environment in which

What is Java?

Java is a programming language and a platform.

Java is a high level, robust, secured and object-

oriented programming language.

Platform

Any hardware or software environment in which a

program runs

Java has its own runtime environment (JRE) and API

7/23/2019P.Poovizhi/CS8392/Overview of Java & Abstraction

13

Page 14: Introduction to Object Oriented Programming · Java is a high level, robust, secured and object-oriented programming language. Platform Any hardware or software environment in which

Where it is used?

According to Sun, 3 billion devices run java. Desktop Applications such as acrobat reader, media

player, antivirus etc. Web Applications such as irctc.co.in, javatpoint.com etc. Enterprise Applications such as banking applications. Mobile Embedded System Smart Card Robotics Games etc.

7/23/2019P.Poovizhi/CS8392/Overview of Java & Abstraction

14

Page 15: Introduction to Object Oriented Programming · Java is a high level, robust, secured and object-oriented programming language. Platform Any hardware or software environment in which

Types of Java Applications

Standalone Application install on every machine. Example of standalone applications are: Media player,

antivirus etc. AWT and Swing are used in java for creating standalone

applications. Web Application

runs on the server side and creates dynamic page creating web applications in java.

7/23/2019P.Poovizhi/CS8392/Overview of Java & Abstraction

15

Page 16: Introduction to Object Oriented Programming · Java is a high level, robust, secured and object-oriented programming language. Platform Any hardware or software environment in which

Types of Java Applications

Enterprise Application distributed in nature, such as banking applications etc.

is called enterprise application. Mobile Application

An application that is created for mobile devices. Android and Java ME are used for creating mobile

applications.

7/23/2019P.Poovizhi/CS8392/Overview of Java & Abstraction

16

Page 17: Introduction to Object Oriented Programming · Java is a high level, robust, secured and object-oriented programming language. Platform Any hardware or software environment in which

Object Oriented ProgrammingAbstraction

17P.Poovizhi/CS8392/Overview of Java & Abstraction

7/23/2019

Page 18: Introduction to Object Oriented Programming · Java is a high level, robust, secured and object-oriented programming language. Platform Any hardware or software environment in which

Object Oriented Programming

Allows a mode of modularizing programs by forming

separate memory area for data as well as functions

that is used as object for making copies of modules as

per requirement

P.Poovizhi/CS8392/Overview of Java & Abstraction

18

7/23/2019

Page 19: Introduction to Object Oriented Programming · Java is a high level, robust, secured and object-oriented programming language. Platform Any hardware or software environment in which

Two Paradigms

programs consist of two elements: code and data program is constructed in two ways

Process Oriented Model program as a series of linear steps Code acting as a Data

Object Oriented Programming Model program around its data – objects set of well-defined interfaces to that data. data controlling access to code.

P.Poovizhi/CS8392/Overview of Java & Abstraction

19

7/23/2019

Page 20: Introduction to Object Oriented Programming · Java is a high level, robust, secured and object-oriented programming language. Platform Any hardware or software environment in which

Basic OOPs Concepts

Abstraction Objects and Classes Encapsulation Inheritance Polymorphism

P.Poovizhi/CS8392/Overview of Java & Abstraction

20

7/23/2019

Page 21: Introduction to Object Oriented Programming · Java is a high level, robust, secured and object-oriented programming language. Platform Any hardware or software environment in which

Abstraction

P.Poovizhi/CS8392/Overview of Java & Abstraction

21

7/23/2019

Page 22: Introduction to Object Oriented Programming · Java is a high level, robust, secured and object-oriented programming language. Platform Any hardware or software environment in which

Define Abstraction

Process of hiding the implementation details and showing

only functionality to the user.

Ex: A car is viewed as a car rather than its individual

components.

In java, abstraction is achieved by interfaces and abstract

classes. We can achieve 100% abstraction using interfaces.7/23/2019P.Poovizhi/CS8392/Overview of Java & Abstraction

22

Page 23: Introduction to Object Oriented Programming · Java is a high level, robust, secured and object-oriented programming language. Platform Any hardware or software environment in which

Objects and Classes

P.Poovizhi/CS8392/Overview of Java & Abstraction

23

7/23/2019

Page 24: Introduction to Object Oriented Programming · Java is a high level, robust, secured and object-oriented programming language. Platform Any hardware or software environment in which

Define Object

An entity that has state and behavior is known asan object

e.g., chair, bike, marker, pen, table, car, etc. It can be physical or logical (tangible and

intangible). The example of an intangible object is the banking

system.

7/23/2019P.Poovizhi/CS8392/Overview of Java & Abstraction

24

Page 25: Introduction to Object Oriented Programming · Java is a high level, robust, secured and object-oriented programming language. Platform Any hardware or software environment in which

An object consists of :

State : It is represented by attributes of an object.

It also reflects the properties of an object.

Behavior : It is represented by methods of an

object. It also reflects the response of an object

with other objects.

Identity : It gives a unique name to an object and

enables one object to interact with other objects.7/23/2019P.Poovizhi/CS8392/Overview of Java & Abstraction

25

Page 26: Introduction to Object Oriented Programming · Java is a high level, robust, secured and object-oriented programming language. Platform Any hardware or software environment in which

Example of an object : dog

7/23/2019P.Poovizhi/CS8392/Overview of Java & Abstraction

26

Page 27: Introduction to Object Oriented Programming · Java is a high level, robust, secured and object-oriented programming language. Platform Any hardware or software environment in which

Define Class

A class is a group of objects which have commonproperties.

It is a template or blueprint from which objectsare created.

7/23/2019P.Poovizhi/CS8392/Overview of Java & Abstraction

27

Page 28: Introduction to Object Oriented Programming · Java is a high level, robust, secured and object-oriented programming language. Platform Any hardware or software environment in which

Components of class declarations

Modifiers : A class can be public or has default access.

Class name: The name should begin with a initial letter.

Superclass(if any): The name of the class’s parent (superclass), if any,

preceded by the keyword extends. A class can only extend (subclass)

one parent.

Interfaces(if any): A comma-separated list of interfaces implemented

by the class, if any, preceded by the keyword implements. A class can

implement more than one interface.

Body: The class body surrounded by braces, { }.

7/23/2019P.Poovizhi/CS8392/Overview of Java & Abstraction

28

Page 29: Introduction to Object Oriented Programming · Java is a high level, robust, secured and object-oriented programming language. Platform Any hardware or software environment in which

Simple class

class Box {double width;double height;double depth;}

P.Poovizhi/CS8392/Overview of Java & Abstraction

29

7/23/2019

Page 30: Introduction to Object Oriented Programming · Java is a high level, robust, secured and object-oriented programming language. Platform Any hardware or software environment in which

Declaring Objects

// create a Box object called myboxBox mybox = new Box();

OrBox mybox; // declare reference to objectmybox = new Box(); // allocate a Box object

P.Poovizhi/CS8392/Overview of Java & Abstraction

30

7/23/2019

Page 31: Introduction to Object Oriented Programming · Java is a high level, robust, secured and object-oriented programming language. Platform Any hardware or software environment in which

Assigning Object Reference Variables

Box b1 = new Box();Box b2 = b1;

P.Poovizhi/CS8392/Overview of Java & Abstraction

31

7/23/2019

Page 32: Introduction to Object Oriented Programming · Java is a high level, robust, secured and object-oriented programming language. Platform Any hardware or software environment in which

Introducing Methods

General form of a method:type name(parameter-list) {// body of method}

P.Poovizhi/CS8392/Overview of Java & Abstraction

32

7/23/2019

Page 33: Introduction to Object Oriented Programming · Java is a high level, robust, secured and object-oriented programming language. Platform Any hardware or software environment in which

Adding a Method to the Box Class

class Box {double width;double height;double depth;// display volume of a box

void volume() {System.out.print("Volume is ");System.out.println(width * height * depth);} }

P.Poovizhi/CS8392/Overview of Java & Abstraction

33

7/23/2019

Page 34: Introduction to Object Oriented Programming · Java is a high level, robust, secured and object-oriented programming language. Platform Any hardware or software environment in which

Guess the concept explained in the picture

7/23/2019P.Poovizhi/CS8392/Overview of Java & Abstraction

34

Page 35: Introduction to Object Oriented Programming · Java is a high level, robust, secured and object-oriented programming language. Platform Any hardware or software environment in which

7/23/2019P.Poovizhi/CS8392/Overview of Java & Abstraction

35