objected oriented programming & design java shishir gupta [email protected] (704) 947 2181...

23
Objected Oriented Objected Oriented Programming & Design Programming & Design JAVA JAVA Shishir Gupta Shishir Gupta [email protected] [email protected] t t http://www.shishir http://www.shishir .net .net (704) 947 2181 (704) 947 2181

Upload: lynette-marsha-barnett

Post on 01-Jan-2016

230 views

Category:

Documents


1 download

TRANSCRIPT

Objected Oriented Objected Oriented Programming & Design Programming & Design

JAVAJAVA

Shishir GuptaShishir Gupta

[email protected]@shishir.net

http://www.shishir.nethttp://www.shishir.net

(704) 947 2181(704) 947 2181

(704) 944 8864(704) 944 8864

AGENDAAGENDA TextText Setup for the class.Setup for the class. Quick Introduction.Quick Introduction.

– Your NameYour Name– Your JobYour Job– Any Past Programming ExperienceAny Past Programming Experience

Information on the course.Information on the course. Course PoliciesCourse Policies Course EvaluationCourse Evaluation Calendar (Tentative)Calendar (Tentative) Introduction OOP & Java.Introduction OOP & Java.

TEXTTEXT

Thinking In JavaThinking In Java

Bruce EckelBruce Eckel

http://www.EckelObjects.comhttp://www.EckelObjects.com

http://www.BruceEckel.comhttp://www.BruceEckel.com

SetupSetup

Create “temp” directory on the D: drive.Create “temp” directory on the D: drive. Copy all the files from the CD.Copy all the files from the CD. Install JDK & Forte.Install JDK & Forte. Install JDK Documentation.Install JDK Documentation. Install Examples from the Text.Install Examples from the Text.

IntroductionIntroduction

Your NameYour Name Your JobYour Job Any Past Programming Experience.Any Past Programming Experience. Your Expectations from this course.Your Expectations from this course. Your E-Mail AddressYour E-Mail Address

Course PoliciesCourse Policies

Honor CodeHonor Code AttendanceAttendance AssignmentsAssignments ClassClass

– Interactive/Responsive.Interactive/Responsive.– Make sure that you know everything that is said in Make sure that you know everything that is said in

the class before you leave.the class before you leave.– Feel free to ask when in doubt.Feel free to ask when in doubt.– There is no limit to asking questions.There is no limit to asking questions.

Evaluation – Assignment (60%)Evaluation – Assignment (60%)

Grades will be awarded on assignments and the Final Project. Grades will be awarded on assignments and the Final Project. Assignments will be given at the beginning of the Week and will Assignments will be given at the beginning of the Week and will

be based on the course to be covered that week. be based on the course to be covered that week. The assignments will be due beginning the following week The assignments will be due beginning the following week

Late Submission will not be accepted.Late Submission will not be accepted. Assignments will be graded as follows: Assignments will be graded as follows:

– 100% : Program that compiles and runs correctly. 100% : Program that compiles and runs correctly.

–   80% : Program compiles but does not run correctly. 80% : Program compiles but does not run correctly.

–   60% : program that compiles but does not run. 60% : program that compiles but does not run.

–   40% : Programs that do not compile.40% : Programs that do not compile.

Evaluation – Project (40%)Evaluation – Project (40%) Should be a full fledged JAVA application. Should be a full fledged JAVA application. The application should use the following programming features. The application should use the following programming features.

– JDBC JDBC

– SWING SWING

– CORBA or RMICORBA or RMI Groups may choose to implement the Work they had done in Software Groups may choose to implement the Work they had done in Software

Engineering Class last Semester (Fall). Engineering Class last Semester (Fall). Maximum of 3 people per group. Maximum of 3 people per group. The final presentation of the project should consist of the following: The final presentation of the project should consist of the following:

– 10 minutes PowerPoint Presentation & demo of the application developed. 10 minutes PowerPoint Presentation & demo of the application developed.

– 3 Minutes for answering questions after the presentation. 3 Minutes for answering questions after the presentation.

– All members of the team must participate in the presentation and demonstration All members of the team must participate in the presentation and demonstration of the application. of the application.

– The final submission of the project document should consist of a copy of your The final submission of the project document should consist of a copy of your presentation and your application on a floppy diskette.presentation and your application on a floppy diskette.

Extra credit will be given to groups who choose to implement their Extra credit will be given to groups who choose to implement their software using Rational Rose.software using Rational Rose.

Calendar (Tentative)Calendar (Tentative)

Calendar (Tentative)Calendar (Tentative)

Introduction to OOPIntroduction to OOP

AbstractionAbstraction– Describe the solution in terms of the problem rather than the Describe the solution in terms of the problem rather than the

Computer on which where the solution runs.Computer on which where the solution runs.– Allows user to define his/her own data type and use them as Allows user to define his/her own data type and use them as

they were a basic language type. This user defined type can they were a basic language type. This user defined type can be anything e.g. TABLE, CHAIRS etc.be anything e.g. TABLE, CHAIRS etc.

– Programmers define their own type and provide a full set of Programmers define their own type and provide a full set of operation with each type. operation with each type.

– Thinking in terms of types one wants, an object is just not Thinking in terms of types one wants, an object is just not data & functionality bundled together in any fashion, but it is data & functionality bundled together in any fashion, but it is tightly related to the idea of ADT: a user defined type.tightly related to the idea of ADT: a user defined type.

– Abstract data type work's the same way like built in types Abstract data type work's the same way like built in types (CLASS). You can create a variable of this type and mani(CLASS). You can create a variable of this type and mani

Introduction to OOPIntroduction to OOP

Characteristics :Characteristics : – Everything is an Object.Everything is an Object.– A program is a bunch of objects telling each other A program is a bunch of objects telling each other

what to do by sending messages.what to do by sending messages.– Each object has its own memory made up of other Each object has its own memory made up of other

objects.objects.– Every Object has a Type.Every Object has a Type.– All Objects of a particular type can receive the All Objects of a particular type can receive the

same messages.same messages.

Introduction to OOPIntroduction to OOP

ClassClass– Definition of the object.Definition of the object.

– Class describes a set of Class describes a set of objects that have objects that have identical characteristics identical characteristics

and behavior.and behavior.

ObjectObject– Instantiation of the class.Instantiation of the class.

Introduction to OOPIntroduction to OOP

InterfaceInterface– Request you can Request you can

make to a specific make to a specific object.object.

– There must be code There must be code to satisfy the to satisfy the request.request.

ImplementationImplementation– Interface with Hidden Interface with Hidden

DataData

Introduction to OOPIntroduction to OOP

The hidden ImplementationThe hidden Implementation The access specifiers The access specifiers

determine who can use the determine who can use the definition that follows.definition that follows.– PUBLICPUBLIC– PRIVATE PRIVATE – PROTECTEDPROTECTED

If not specified “If not specified “FRIENDLYFRIENDLY” ” (default) access is used.(default) access is used.

Introduction to OOPIntroduction to OOP

Reusing the ImplementationReusing the Implementation– Reuse a class as an object of another class.Reuse a class as an object of another class.– Also called Aggregation or Composition.Also called Aggregation or Composition.– Composition is also referred to as “HAS-A” relationship.Composition is also referred to as “HAS-A” relationship.– The member object of the new class is usually “private” which The member object of the new class is usually “private” which

make them unavailable to outside classes.make them unavailable to outside classes.– Is generally a preferred choice over “Inheritance”Is generally a preferred choice over “Inheritance”

Introduction to OOPIntroduction to OOP

InheritanceInheritance– Cloning an existing Class Cloning an existing Class

and making modifications to and making modifications to the Clone.the Clone.

– Inheriting class inherits the Inheriting class inherits the functionality of the Parent.functionality of the Parent.

– The Inheriting class is of The Inheriting class is of “Parent” Type.“Parent” Type.

– Can take all the message the Can take all the message the parent can take plus more.parent can take plus more.

BASEBASE

DERIVEDDERIVED

Introduction to OOPIntroduction to OOP

InheritanceInheritance– When inherit from an When inherit from an

existing type, you create a existing type, you create a new type.new type.

– Duplicates the interface of Duplicates the interface of the base class.the base class.

– Messages that can be sent Messages that can be sent to the base class can also to the base class can also be sent to the derived be sent to the derived class.class.

– Derived Class is the same Derived Class is the same type as the base class type as the base class (Circle is a Shape).(Circle is a Shape).

Introduction to OOPIntroduction to OOP

Inheritance Inheritance (what to do with the derived class)(what to do with the derived class)

– Add a brand new function Add a brand new function to the derived class.to the derived class.

– Change the existing Change the existing behavior also known as behavior also known as overriding that function.overriding that function.

– ““Extends” keyword is used Extends” keyword is used in Java to inherit from a in Java to inherit from a existing base class.existing base class.

Introduction to OOPIntroduction to OOP

Inheritance Inheritance (IS-A vs LIKE-A Relationship)(IS-A vs LIKE-A Relationship)

– If the Derived Class only If the Derived Class only overrides function of the base overrides function of the base class. The derived class is class. The derived class is exactly like the Base Class. Any exactly like the Base Class. Any message that can be sent to the message that can be sent to the derived class can also be sent to derived class can also be sent to the Base class.the Base class.

– Adding new Interface elements Adding new Interface elements to the derive class extends the to the derive class extends the interface and creates a new interface and creates a new type. The new type can still type. The new type can still substitute the base type, but the substitute the base type, but the new functions are not accessible new functions are not accessible from the base type. from the base type.

Introduction to OOPIntroduction to OOP

Polymorphism Polymorphism – Treat a Derived Type as a Base Treat a Derived Type as a Base

type.type.– Late Binding. There is no way to Late Binding. There is no way to

determine the address of the determine the address of the code until runtime.code until runtime.

– The ability to extend a program The ability to extend a program easily by deriving new subtypes easily by deriving new subtypes is important because it greatly is important because it greatly improves design while reducing improves design while reducing the cost of S/W Maintenance.the cost of S/W Maintenance.

– Upcasting.Upcasting.

Introduction to OOP (Concepts)Introduction to OOP (Concepts)

Abstract Class and InterfaceAbstract Class and Interface

Provide only an interface for the derived class.Provide only an interface for the derived class. We do not want to create an object of the base class; We do not want to create an object of the base class;

only to upcast it so that the interface can be used.only to upcast it so that the interface can be used. Derived classes must implement methods that are Derived classes must implement methods that are

abstract or they become abstract class themselves.abstract or they become abstract class themselves. Interface does not provide any method definition at Interface does not provide any method definition at

all.all. Many Interface can be inherited together in Java.Many Interface can be inherited together in Java.

Object Landscapes & LifetimeObject Landscapes & Lifetime

Object Creation and Destruction.Object Creation and Destruction. Objects stored in Heap rather than on Objects stored in Heap rather than on

Stack.Stack. Objects are created with “new” Objects are created with “new”

keyword.keyword. Objects are destroyed using Garbage Objects are destroyed using Garbage

Collector.Collector.