SlideShare a Scribd company logo
1 of 46
Data Structures Using Java 1
Chapter 1
Software Engineering Principles and
Java Classes
Data Structures Using Java 2
Chapter Objectives
• Learn about software engineering principles
• Discover what an algorithm is and explore
problem-solving techniques
• Become aware of structured design and object-
oriented design programming methodologies
• Learn about user-defined classes
• Learn about private, protected, and public
members of a class
Data Structures Using Java 3
Chapter Objectives
• Explore how classes are implemented
• Become aware of Unified Modeling Language
(UML) notation
• Examine constructors and destructors
• Learn about the abstract data type (ADT)
• Explore how classes are used to implement ADT
Data Structures Using Java 4
Software Life Cycle
• Life cycle: the many phases a program goes
through from the time it is conceived until
the time it is retired
• Three fundamental stages of a program
– Development
– Use
– Maintenance
Data Structures Using Java 5
Software Development Phase
• Analysis
– Understand problem
– Requirements analysis
– Data analysis
– Divide problem into subproblems and perform
analysis
Data Structures Using Java 6
Software Development Phase
• Design
– Algorithm
– Structured design
• Divide problem into subproblems and analyze each
subproblem
– Object-oriented design
• Identify components (objects) which form the basis
of solution
• Determine how these objects interact with one
another
Data Structures Using Java 7
Software Development Phase
• Three basic principles of object-oriented
design (OOD)
– Encapsulation: ability to combine data and
operations in a single unit
– Inheritance: ability to create new data types
from existing data types
– Polymorphism: ability to use the same
expression to denote different operations
Data Structures Using Java 8
Software Development Phase
• Implementation
– Write and compile programming code to
implement classes and functions discovered in
design phase
Data Structures Using Java 9
Software Development Phase
• Testing and Debugging
– Test the correctness of the program to make
sure it does what it is supposed to do
– Find and fix errors
– Run program through series of specific tests,
test cases
Data Structures Using Java 10
Software Development Phase
• Testing and Debugging
– Black-box testing: test based on inputs and
outputs not the internal working of the
algorithm or function
– White-box testing: relies on the internal
structure and implementation of a function or
algorithm; ensures that every part of the
function or algorithm executes at least once
Data Structures Using Java 11
Algorithm Analysis:
The Big-O Notation
Data Structures Using Java 12
Algorithm Analysis:
The Big-O Notation
Data Structures Using Java 13
Algorithm Analysis:
The Big-O Notation
Data Structures Using Java 14
Algorithm Analysis:
The Big-O Notation
Data Structures Using Java 15
Algorithm Analysis:
The Big-O Notation
• Definition: Let f be a function of n.The term
“asymptotic” means the study of the function f as
n becomes larger and larger without bound.
Data Structures Using Java 16
Algorithm Analysis:
The Big-O Notation
Data Structures Using Java 17
Classes
• class: reserved word; collection of a fixed
number of components
• Components: member of a class
• Members accessed by name
• Class categories/modifiers
– Private
– Protected
– public
Data Structures Using Java 18
Classes
• private: members of class not accessible
outside class
• public: members of class accessible outside
class
• Class members: can be methods or variables
• Variable members declared like any other
variables
Data Structures Using Java 19
Syntax
• General syntax for defining a class:
modifier(s) class ClassIdentifier modifier(s)
{
classMembers
}
• General syntax for using the operator new:
new className()
or
new className(argument1, argument2, ..., argumentN)
Data Structures Using Java 20
Classes
• Syntax to access data member of class object or
method:
referenceVariableName.memberName
• Shallow copying: two or more reference variables
of the same type point to the same object
• Deep copying: each reference variable refers to its
own object
Data Structures Using Java 21
Constructors
• Guarantee that data members are initialized when
object is declared
• Automatically execute when class object created
• Name of constructor is name of class
• More than one constructor can be present in one
class
• Default constructor: constructor without
parameters
Data Structures Using Java 22
The Copy Constructor
• Executes when an object is instantiated
• Initialized using an existing object
• Syntax
public ClassName(ClassName otherObject)
Data Structures Using Java 23
UML Diagram
Data Structures Using Java 24
UML Diagram
• Top box: Name of class
• Middle box: data members and their data
types
• Bottom box: member methods’ names,
parameter list, return type of method
• + means public method
• - means private method
• # means protected method
Data Structures Using Java 25
Example: class Clock
myClock = new Clock();
yourClock = new Clock(9,35,15);
Data Structures Using Java 26
Example: class Clock
Data Structures Using Java 27
Example: class Clock
Data Structures Using Java 28
The Method toString
• Public value-returning method
• Takes no parameters
• Returns address of String object
• Output using print and println methods
• Default definition creates String with name
of object’s class name followed by hash
code of object
Data Structures Using Java 29
The Modifier Static
• In method heading, specifies that method
can be invoked by using name of class
• If used to declare data member, data
member invoked by using class name
• Static data members of class exist even
when no object of class type instantiated
• Static variables are initialized to their
default values
Data Structures Using Java 30
static Data Members of a Class
Illustrate illusObject1 = new Illustrate(3);
Illustrate illusObject2 = new Illustrate(5);
Data Structures Using Java 31
Finalizers
• Automatically execute when class object
goes out of scope
• Have no parameters
• Only one finalizer per class
• Name of finalizer: finalize
Data Structures Using Java 32
Creating Packages
• Can create packages using reserved word
package
– Define the class to be public (If class not public
it can only be used within package)
– Choose name for package. Organize package
(create subdirectories)
Data Structures Using Java 33
The Reference this
• Refers to instance variables and methods of
a class
• Used to implement cascaded method calls
Data Structures Using Java 34
Inner Classes
• Defined within other classes
• Can be either a complete class definition or
anonymous inner class definition
• Used to handle events
Data Structures Using Java 35
Abstract Data Types
• Definition:
A data type that specifies the logical properties
without the implementation details
Data Structures Using Java 36
Programming Example:
Candy Machine
(Problem Statement)
• A common place to buy candy is from a candy machine. A new candy
machine is bought for the gym, but it is not working properly. The
machine sells candies, chips, gum, and cookies. You have been asked
to write a program for this candy machine so that it can be put into
operation.
• The program should do the following:
1. Show the customer the different products sold by the candy
machine.
2. Let the customer make the selection.
3. Show the customer the cost of the item selected.
4. Accept money from the customer.
5. Release the item.
Data Structures Using Java 37
Programming Example:
Candy Machine
(Input and Output)
• Input
– Item Selection
– Cost of Item
• Output
– The selected item
Data Structures Using Java 38
Programming Example:
Candy Machine
• Components
– Cash Register
– Several Dispensers
Data Structures Using Java 39
Programming Example:
Candy Machine
Data Structures Using Java 40
Programming Example:
Candy Machine
Data Structures Using Java 41
Programming Example:
Candy Machine
Object chips
Data Structures Using Java 42
Programming Example:
Candy Machine
Sample Run: In this sample run, the user input is shaded.
*** Welcome to Shelly's Candy Shop ***
To select an item, enter
1 for Candy
2 for Chips
3 for Gum
4 for Cookies
9 to exit
1
Please deposit 50 cents
50
Collect your item at the bottom and enjoy.
Data Structures Using Java 43
Object-Oriented Design
• Simplified methodology
1. Write down detailed description of problem
2. Identify all (relevant) nouns and verbs
3. From list of nouns, select objects
4. Identify data components of each object
5. From list of verbs, select operations
Data Structures Using Java 44
Object-Oriented Design
Example
• Problem Statement
– Write a program to input the dimensions of a
cylinder and calculate and print the surface area
and volume
• Nouns
– Dimensions, surface area, volume, cylinder
Data Structures Using Java 45
Chapter Summary
• Software Life Cycle
– Development, Use, Maintenance
• Algorithm Analysis: The Big-O Notation
• Classes
• UML Diagram
• Constructors, Destructors
• Abstract Data Types
Data Structures Using Java 46
Chapter Summary
• Software Development Phase
– Analysis
– Design
• Structured design
• Object-oriented design
– Encapsulation, Inheritance, Polymorphism
– Implementation
– Testing and Debugging

More Related Content

What's hot

Statics in java | Constructors | Exceptions in Java | String in java| class 3
Statics in java | Constructors | Exceptions in Java | String in java| class 3Statics in java | Constructors | Exceptions in Java | String in java| class 3
Statics in java | Constructors | Exceptions in Java | String in java| class 3Sagar Verma
 
Collection Framework in Java | Generics | Input-Output in Java | Serializatio...
Collection Framework in Java | Generics | Input-Output in Java | Serializatio...Collection Framework in Java | Generics | Input-Output in Java | Serializatio...
Collection Framework in Java | Generics | Input-Output in Java | Serializatio...Sagar Verma
 
Logic and Coding of Java Interfaces & Swing Applications
Logic and Coding of Java Interfaces & Swing ApplicationsLogic and Coding of Java Interfaces & Swing Applications
Logic and Coding of Java Interfaces & Swing Applicationskjkleindorfer
 
Week9 Intro to classes and objects in Java
Week9 Intro to classes and objects in JavaWeek9 Intro to classes and objects in Java
Week9 Intro to classes and objects in Javakjkleindorfer
 
Inner Classes & Multi Threading in JAVA
Inner Classes & Multi Threading in JAVAInner Classes & Multi Threading in JAVA
Inner Classes & Multi Threading in JAVATech_MX
 
2 lesson 2 object oriented programming in c++
2 lesson 2 object oriented programming in c++2 lesson 2 object oriented programming in c++
2 lesson 2 object oriented programming in c++Jeff TUYISHIME
 
Android App code starter
Android App code starterAndroid App code starter
Android App code starterFatimaYousif11
 
Class and object in c++
Class and object in c++Class and object in c++
Class and object in c++NainaKhan28
 
Class and Objects in Java
Class and Objects in JavaClass and Objects in Java
Class and Objects in JavaSpotle.ai
 
Object and Classes in Java
Object and Classes in JavaObject and Classes in Java
Object and Classes in Javabackdoor
 
03 object-classes-pbl-4-slots
03 object-classes-pbl-4-slots03 object-classes-pbl-4-slots
03 object-classes-pbl-4-slotsmha4
 
How to write you first class in c++ object oriented programming
How to write you first class in c++ object oriented programmingHow to write you first class in c++ object oriented programming
How to write you first class in c++ object oriented programmingSyed Faizan Hassan
 

What's hot (18)

Statics in java | Constructors | Exceptions in Java | String in java| class 3
Statics in java | Constructors | Exceptions in Java | String in java| class 3Statics in java | Constructors | Exceptions in Java | String in java| class 3
Statics in java | Constructors | Exceptions in Java | String in java| class 3
 
Java
Java Java
Java
 
Java chapter 5
Java chapter 5Java chapter 5
Java chapter 5
 
Collection Framework in Java | Generics | Input-Output in Java | Serializatio...
Collection Framework in Java | Generics | Input-Output in Java | Serializatio...Collection Framework in Java | Generics | Input-Output in Java | Serializatio...
Collection Framework in Java | Generics | Input-Output in Java | Serializatio...
 
Logic and Coding of Java Interfaces & Swing Applications
Logic and Coding of Java Interfaces & Swing ApplicationsLogic and Coding of Java Interfaces & Swing Applications
Logic and Coding of Java Interfaces & Swing Applications
 
Week9 Intro to classes and objects in Java
Week9 Intro to classes and objects in JavaWeek9 Intro to classes and objects in Java
Week9 Intro to classes and objects in Java
 
Inner Classes & Multi Threading in JAVA
Inner Classes & Multi Threading in JAVAInner Classes & Multi Threading in JAVA
Inner Classes & Multi Threading in JAVA
 
2 lesson 2 object oriented programming in c++
2 lesson 2 object oriented programming in c++2 lesson 2 object oriented programming in c++
2 lesson 2 object oriented programming in c++
 
Android App code starter
Android App code starterAndroid App code starter
Android App code starter
 
Java static keyword
Java static keywordJava static keyword
Java static keyword
 
Write First C++ class
Write First C++ classWrite First C++ class
Write First C++ class
 
Class and object in c++
Class and object in c++Class and object in c++
Class and object in c++
 
Class and Objects in Java
Class and Objects in JavaClass and Objects in Java
Class and Objects in Java
 
Chap02
Chap02Chap02
Chap02
 
[OOP - Lec 06] Classes and Objects
[OOP - Lec 06] Classes and Objects[OOP - Lec 06] Classes and Objects
[OOP - Lec 06] Classes and Objects
 
Object and Classes in Java
Object and Classes in JavaObject and Classes in Java
Object and Classes in Java
 
03 object-classes-pbl-4-slots
03 object-classes-pbl-4-slots03 object-classes-pbl-4-slots
03 object-classes-pbl-4-slots
 
How to write you first class in c++ object oriented programming
How to write you first class in c++ object oriented programmingHow to write you first class in c++ object oriented programming
How to write you first class in c++ object oriented programming
 

Viewers also liked

Database using oracle 10g
Database using oracle 10gDatabase using oracle 10g
Database using oracle 10gJotham Gadot
 
Fundamentals of Database ppt ch04
Fundamentals of Database ppt ch04Fundamentals of Database ppt ch04
Fundamentals of Database ppt ch04Jotham Gadot
 
Opeating system programs
Opeating system programsOpeating system programs
Opeating system programsJotham Gadot
 
01 introduction-to-computers
01 introduction-to-computers01 introduction-to-computers
01 introduction-to-computersJotham Gadot
 
CCNAv5 - S4: Chapter3 Point to-point Connections
CCNAv5 - S4: Chapter3 Point to-point ConnectionsCCNAv5 - S4: Chapter3 Point to-point Connections
CCNAv5 - S4: Chapter3 Point to-point ConnectionsVuz Dở Hơi
 
ENGLAND PRESENTATION
ENGLAND PRESENTATIONENGLAND PRESENTATION
ENGLAND PRESENTATIONadamson1218
 
Fundamentals of Database ppt ch01
Fundamentals of Database ppt ch01Fundamentals of Database ppt ch01
Fundamentals of Database ppt ch01Jotham Gadot
 

Viewers also liked (9)

Database using oracle 10g
Database using oracle 10gDatabase using oracle 10g
Database using oracle 10g
 
Fundamentals of Database ppt ch04
Fundamentals of Database ppt ch04Fundamentals of Database ppt ch04
Fundamentals of Database ppt ch04
 
Opeating system programs
Opeating system programsOpeating system programs
Opeating system programs
 
01 introduction-to-computers
01 introduction-to-computers01 introduction-to-computers
01 introduction-to-computers
 
Research gadot
Research gadotResearch gadot
Research gadot
 
Auto cad manual
Auto cad manualAuto cad manual
Auto cad manual
 
CCNAv5 - S4: Chapter3 Point to-point Connections
CCNAv5 - S4: Chapter3 Point to-point ConnectionsCCNAv5 - S4: Chapter3 Point to-point Connections
CCNAv5 - S4: Chapter3 Point to-point Connections
 
ENGLAND PRESENTATION
ENGLAND PRESENTATIONENGLAND PRESENTATION
ENGLAND PRESENTATION
 
Fundamentals of Database ppt ch01
Fundamentals of Database ppt ch01Fundamentals of Database ppt ch01
Fundamentals of Database ppt ch01
 

Similar to Chap01

UNIT - IIInew.pptx
UNIT - IIInew.pptxUNIT - IIInew.pptx
UNIT - IIInew.pptxakila m
 
Introduction to OOP with java
Introduction to OOP with javaIntroduction to OOP with java
Introduction to OOP with javaSujit Kumar
 
02._Object-Oriented_Programming_Concepts.ppt
02._Object-Oriented_Programming_Concepts.ppt02._Object-Oriented_Programming_Concepts.ppt
02._Object-Oriented_Programming_Concepts.pptYonas D. Ebren
 
Java 102 intro to object-oriented programming in java
Java 102   intro to object-oriented programming in javaJava 102   intro to object-oriented programming in java
Java 102 intro to object-oriented programming in javaagorolabs
 
SystemVerilog_Classes.pdf
SystemVerilog_Classes.pdfSystemVerilog_Classes.pdf
SystemVerilog_Classes.pdfssusere9cd04
 
CIS110 Computer Programming Design Chapter (10)
CIS110 Computer Programming Design Chapter  (10)CIS110 Computer Programming Design Chapter  (10)
CIS110 Computer Programming Design Chapter (10)Dr. Ahmed Al Zaidy
 
Kelis king - introduction to software design
Kelis king -  introduction to software designKelis king -  introduction to software design
Kelis king - introduction to software designKelisKing
 
Object-oriented Analysis, Design & Programming
Object-oriented Analysis, Design & ProgrammingObject-oriented Analysis, Design & Programming
Object-oriented Analysis, Design & ProgrammingAllan Mangune
 
C++ training
C++ training C++ training
C++ training PL Sharma
 
Java lec class, objects and constructors
Java lec class, objects and constructorsJava lec class, objects and constructors
Java lec class, objects and constructorsJan Niño Acierto
 
Unit No 2 Objects and Classes.pptx
Unit No 2 Objects and Classes.pptxUnit No 2 Objects and Classes.pptx
Unit No 2 Objects and Classes.pptxDrYogeshDeshmukh1
 

Similar to Chap01 (20)

UNIT - IIInew.pptx
UNIT - IIInew.pptxUNIT - IIInew.pptx
UNIT - IIInew.pptx
 
Introduction to OOP with java
Introduction to OOP with javaIntroduction to OOP with java
Introduction to OOP with java
 
02._Object-Oriented_Programming_Concepts.ppt
02._Object-Oriented_Programming_Concepts.ppt02._Object-Oriented_Programming_Concepts.ppt
02._Object-Oriented_Programming_Concepts.ppt
 
Java 102 intro to object-oriented programming in java
Java 102   intro to object-oriented programming in javaJava 102   intro to object-oriented programming in java
Java 102 intro to object-oriented programming in java
 
VB.net&OOP.pptx
VB.net&OOP.pptxVB.net&OOP.pptx
VB.net&OOP.pptx
 
SystemVerilog_Classes.pdf
SystemVerilog_Classes.pdfSystemVerilog_Classes.pdf
SystemVerilog_Classes.pdf
 
BCA Class and Object (3).pptx
BCA Class and Object (3).pptxBCA Class and Object (3).pptx
BCA Class and Object (3).pptx
 
CIS110 Computer Programming Design Chapter (10)
CIS110 Computer Programming Design Chapter  (10)CIS110 Computer Programming Design Chapter  (10)
CIS110 Computer Programming Design Chapter (10)
 
Kelis king - introduction to software design
Kelis king -  introduction to software designKelis king -  introduction to software design
Kelis king - introduction to software design
 
Object-oriented Analysis, Design & Programming
Object-oriented Analysis, Design & ProgrammingObject-oriented Analysis, Design & Programming
Object-oriented Analysis, Design & Programming
 
C# classes objects
C#  classes objectsC#  classes objects
C# classes objects
 
Java2
Java2Java2
Java2
 
Java
JavaJava
Java
 
C++ training
C++ training C++ training
C++ training
 
Java lec class, objects and constructors
Java lec class, objects and constructorsJava lec class, objects and constructors
Java lec class, objects and constructors
 
Object oriented programming
Object oriented programmingObject oriented programming
Object oriented programming
 
Ppt chapter05
Ppt chapter05Ppt chapter05
Ppt chapter05
 
Unit No 2 Objects and Classes.pptx
Unit No 2 Objects and Classes.pptxUnit No 2 Objects and Classes.pptx
Unit No 2 Objects and Classes.pptx
 
Java
JavaJava
Java
 
Constructors and Method Overloading
Constructors and Method OverloadingConstructors and Method Overloading
Constructors and Method Overloading
 

Recently uploaded

Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterMydbops
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...AliaaTarek5
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 

Recently uploaded (20)

Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 

Chap01

  • 1. Data Structures Using Java 1 Chapter 1 Software Engineering Principles and Java Classes
  • 2. Data Structures Using Java 2 Chapter Objectives • Learn about software engineering principles • Discover what an algorithm is and explore problem-solving techniques • Become aware of structured design and object- oriented design programming methodologies • Learn about user-defined classes • Learn about private, protected, and public members of a class
  • 3. Data Structures Using Java 3 Chapter Objectives • Explore how classes are implemented • Become aware of Unified Modeling Language (UML) notation • Examine constructors and destructors • Learn about the abstract data type (ADT) • Explore how classes are used to implement ADT
  • 4. Data Structures Using Java 4 Software Life Cycle • Life cycle: the many phases a program goes through from the time it is conceived until the time it is retired • Three fundamental stages of a program – Development – Use – Maintenance
  • 5. Data Structures Using Java 5 Software Development Phase • Analysis – Understand problem – Requirements analysis – Data analysis – Divide problem into subproblems and perform analysis
  • 6. Data Structures Using Java 6 Software Development Phase • Design – Algorithm – Structured design • Divide problem into subproblems and analyze each subproblem – Object-oriented design • Identify components (objects) which form the basis of solution • Determine how these objects interact with one another
  • 7. Data Structures Using Java 7 Software Development Phase • Three basic principles of object-oriented design (OOD) – Encapsulation: ability to combine data and operations in a single unit – Inheritance: ability to create new data types from existing data types – Polymorphism: ability to use the same expression to denote different operations
  • 8. Data Structures Using Java 8 Software Development Phase • Implementation – Write and compile programming code to implement classes and functions discovered in design phase
  • 9. Data Structures Using Java 9 Software Development Phase • Testing and Debugging – Test the correctness of the program to make sure it does what it is supposed to do – Find and fix errors – Run program through series of specific tests, test cases
  • 10. Data Structures Using Java 10 Software Development Phase • Testing and Debugging – Black-box testing: test based on inputs and outputs not the internal working of the algorithm or function – White-box testing: relies on the internal structure and implementation of a function or algorithm; ensures that every part of the function or algorithm executes at least once
  • 11. Data Structures Using Java 11 Algorithm Analysis: The Big-O Notation
  • 12. Data Structures Using Java 12 Algorithm Analysis: The Big-O Notation
  • 13. Data Structures Using Java 13 Algorithm Analysis: The Big-O Notation
  • 14. Data Structures Using Java 14 Algorithm Analysis: The Big-O Notation
  • 15. Data Structures Using Java 15 Algorithm Analysis: The Big-O Notation • Definition: Let f be a function of n.The term “asymptotic” means the study of the function f as n becomes larger and larger without bound.
  • 16. Data Structures Using Java 16 Algorithm Analysis: The Big-O Notation
  • 17. Data Structures Using Java 17 Classes • class: reserved word; collection of a fixed number of components • Components: member of a class • Members accessed by name • Class categories/modifiers – Private – Protected – public
  • 18. Data Structures Using Java 18 Classes • private: members of class not accessible outside class • public: members of class accessible outside class • Class members: can be methods or variables • Variable members declared like any other variables
  • 19. Data Structures Using Java 19 Syntax • General syntax for defining a class: modifier(s) class ClassIdentifier modifier(s) { classMembers } • General syntax for using the operator new: new className() or new className(argument1, argument2, ..., argumentN)
  • 20. Data Structures Using Java 20 Classes • Syntax to access data member of class object or method: referenceVariableName.memberName • Shallow copying: two or more reference variables of the same type point to the same object • Deep copying: each reference variable refers to its own object
  • 21. Data Structures Using Java 21 Constructors • Guarantee that data members are initialized when object is declared • Automatically execute when class object created • Name of constructor is name of class • More than one constructor can be present in one class • Default constructor: constructor without parameters
  • 22. Data Structures Using Java 22 The Copy Constructor • Executes when an object is instantiated • Initialized using an existing object • Syntax public ClassName(ClassName otherObject)
  • 23. Data Structures Using Java 23 UML Diagram
  • 24. Data Structures Using Java 24 UML Diagram • Top box: Name of class • Middle box: data members and their data types • Bottom box: member methods’ names, parameter list, return type of method • + means public method • - means private method • # means protected method
  • 25. Data Structures Using Java 25 Example: class Clock myClock = new Clock(); yourClock = new Clock(9,35,15);
  • 26. Data Structures Using Java 26 Example: class Clock
  • 27. Data Structures Using Java 27 Example: class Clock
  • 28. Data Structures Using Java 28 The Method toString • Public value-returning method • Takes no parameters • Returns address of String object • Output using print and println methods • Default definition creates String with name of object’s class name followed by hash code of object
  • 29. Data Structures Using Java 29 The Modifier Static • In method heading, specifies that method can be invoked by using name of class • If used to declare data member, data member invoked by using class name • Static data members of class exist even when no object of class type instantiated • Static variables are initialized to their default values
  • 30. Data Structures Using Java 30 static Data Members of a Class Illustrate illusObject1 = new Illustrate(3); Illustrate illusObject2 = new Illustrate(5);
  • 31. Data Structures Using Java 31 Finalizers • Automatically execute when class object goes out of scope • Have no parameters • Only one finalizer per class • Name of finalizer: finalize
  • 32. Data Structures Using Java 32 Creating Packages • Can create packages using reserved word package – Define the class to be public (If class not public it can only be used within package) – Choose name for package. Organize package (create subdirectories)
  • 33. Data Structures Using Java 33 The Reference this • Refers to instance variables and methods of a class • Used to implement cascaded method calls
  • 34. Data Structures Using Java 34 Inner Classes • Defined within other classes • Can be either a complete class definition or anonymous inner class definition • Used to handle events
  • 35. Data Structures Using Java 35 Abstract Data Types • Definition: A data type that specifies the logical properties without the implementation details
  • 36. Data Structures Using Java 36 Programming Example: Candy Machine (Problem Statement) • A common place to buy candy is from a candy machine. A new candy machine is bought for the gym, but it is not working properly. The machine sells candies, chips, gum, and cookies. You have been asked to write a program for this candy machine so that it can be put into operation. • The program should do the following: 1. Show the customer the different products sold by the candy machine. 2. Let the customer make the selection. 3. Show the customer the cost of the item selected. 4. Accept money from the customer. 5. Release the item.
  • 37. Data Structures Using Java 37 Programming Example: Candy Machine (Input and Output) • Input – Item Selection – Cost of Item • Output – The selected item
  • 38. Data Structures Using Java 38 Programming Example: Candy Machine • Components – Cash Register – Several Dispensers
  • 39. Data Structures Using Java 39 Programming Example: Candy Machine
  • 40. Data Structures Using Java 40 Programming Example: Candy Machine
  • 41. Data Structures Using Java 41 Programming Example: Candy Machine Object chips
  • 42. Data Structures Using Java 42 Programming Example: Candy Machine Sample Run: In this sample run, the user input is shaded. *** Welcome to Shelly's Candy Shop *** To select an item, enter 1 for Candy 2 for Chips 3 for Gum 4 for Cookies 9 to exit 1 Please deposit 50 cents 50 Collect your item at the bottom and enjoy.
  • 43. Data Structures Using Java 43 Object-Oriented Design • Simplified methodology 1. Write down detailed description of problem 2. Identify all (relevant) nouns and verbs 3. From list of nouns, select objects 4. Identify data components of each object 5. From list of verbs, select operations
  • 44. Data Structures Using Java 44 Object-Oriented Design Example • Problem Statement – Write a program to input the dimensions of a cylinder and calculate and print the surface area and volume • Nouns – Dimensions, surface area, volume, cylinder
  • 45. Data Structures Using Java 45 Chapter Summary • Software Life Cycle – Development, Use, Maintenance • Algorithm Analysis: The Big-O Notation • Classes • UML Diagram • Constructors, Destructors • Abstract Data Types
  • 46. Data Structures Using Java 46 Chapter Summary • Software Development Phase – Analysis – Design • Structured design • Object-oriented design – Encapsulation, Inheritance, Polymorphism – Implementation – Testing and Debugging