SlideShare a Scribd company logo
1 of 26
Download to read offline
Objects First With Java
A Practical Introduction Using BlueJ
Object interaction
Creating cooperating objects
2.0
Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Kölling;
extensions by HJB&TN for TUM-CSE, winter 2010/2011
2
The next step
• so far:
– what objects are
– how they are implemented
• now:
– combine classes and objects
– let objects cooperate
– how methods call other methods
Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Kölling;
extensions by HJB&TN for TUM-CSE, winter 2010/2011
3
Project: a digital clock
hours (European style: 0..23) minutes
always the same
Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Kölling;
extensions by HJB&TN for TUM-CSE, winter 2010/2011
4
Abstraction
• Why not define the digital clock as one
single class?
– complexity substructuring (divide and
conquer)!
– effect: “abstract” from a component’s details
(not everyone needs to know everything …)
• Abstraction is the ability to ignore details
of parts to focus attention on a higher level
of a problem.
Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Kölling;
extensions by HJB&TN for TUM-CSE, winter 2010/2011
5
Modularization
• Modularization: process of dividing a
whole into well-defined parts, which can be
built and examined separately, and which
interact in well-defined ways.
• Modularization and abstraction
complement each other.
• Both concepts are crucial for object-
oriented software (components and
subcomponents being objects here).
Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Kölling;
extensions by HJB&TN for TUM-CSE, winter 2010/2011
6
Modularizing the clock
display
One four-digit display?
Or two two-digit
displays?
One or two classes?
Differences?
Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Kölling;
extensions by HJB&TN for TUM-CSE, winter 2010/2011
7
Implementation -
NumberDisplay
public class NumberDisplay
{
private int limit;
private int value;
public NumberDisplay(int rollOverLimit)
{
limit = rollOverLimit;
value = 0;
}
methods omitted.
}
when to roll back to 0?
current value?
fields:
Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Kölling;
extensions by HJB&TN for TUM-CSE, winter 2010/2011
8
Implementation -
ClockDisplay
public class ClockDisplay
{
private NumberDisplay hours;
private NumberDisplay minutes;
Constructor and
methods omitted.
}
Class names can be used as
types!
Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Kölling;
extensions by HJB&TN for TUM-CSE, winter 2010/2011
9
Class diagrams
• class diagrams show classes and their
relationships – hence, a static view of a program
“depends on, needs”
Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Kölling;
extensions by HJB&TN for TUM-CSE, winter 2010/2011
10
Object diagrams
• object diagrams show objects and their
relationships at one moment in time – hence, a
dynamic view of a program
not really “included”,
but references only!
Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Kölling;
extensions by HJB&TN for TUM-CSE, winter 2010/2011
11
Starting the program
• Start program by creating an object of
type/class ClockDisplay.
(bluej)
• Then: automatic creation of two
NumberDisplay objects for own
purposes
Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Kölling;
extensions by HJB&TN for TUM-CSE, winter 2010/2011
12
Primitive types vs. object
types
32
object type
(by classes, given by
Java system or
by programmer)
primitive type
(predefined in Java)
Note different way of storing!
(direct value vs. reference)
SomeObject obj;
int i;
Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Kölling;
extensions by HJB&TN for TUM-CSE, winter 2010/2011
13
Primitive types vs. object
types
32
SomeObject a;
int a;
SomeObject b;
32
int b;
b = a;
two references of
the same type!
Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Kölling;
extensions by HJB&TN for TUM-CSE, winter 2010/2011
14
Source code: NumberDisplay
public NumberDisplay(int rollOverLimit)
{
limit = rollOverLimit; constructor!
value = 0;
}
4 methods: getValue, setValue, getDisplayValue,
increment
public void increment()
{
value = (value + 1) % limit;
}
Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Kölling;
extensions by HJB&TN for TUM-CSE, winter 2010/2011
15
Source code: NumberDisplay
public String getDisplayValue()
{
if(value < 10)
return "0" + value;
else
return "" + value;
} why not directly return value?
public void setValue(int replacementValue)
{
if((replacementValue >= 0) &&
(replacementValue < limit))
value = replacementValue;
} what happens if replacement value is illegal? OK?
Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Kölling;
extensions by HJB&TN for TUM-CSE, winter 2010/2011
16
Logical operators
• operate on boolean values
• produce a new boolean value as
result
• available in Java:
– && (and)
– || (or)
– ! (not)
Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Kölling;
extensions by HJB&TN for TUM-CSE, winter 2010/2011
17
Further operators
• String concatenation
– with “+” operator
– spaces/blanks must be added explicitly
– If one operand is a string, both the
others and the result are converted to
string.
– the “+=” operator acts as for int or
double data types
• modulo: %
Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Kölling;
extensions by HJB&TN for TUM-CSE, winter 2010/2011
18
ClockDisplay object diagram
where do the three objects come from?
Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Kölling;
extensions by HJB&TN for TUM-CSE, winter 2010/2011
19
Objects creating objects
public class ClockDisplay
{
private NumberDisplay hours;
private NumberDisplay minutes;
private String displayString;
public ClockDisplay()
{
hours = new NumberDisplay(24);
minutes = new NumberDisplay(60);
updateDisplay();
}
}
Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Kölling;
extensions by HJB&TN for TUM-CSE, winter 2010/2011
20
Alternative
public class ClockDisplay
{
private NumberDisplay hours;
private NumberDisplay minutes;
private String displayString;
public ClockDisplay(int hour, int minute)
{
hours = new NumberDisplay(24);
minutes = new NumberDisplay(60);
setTime(hour, minute);
}
}
multiple constructors in one class possible!
Overloading
Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Kölling;
extensions by HJB&TN for TUM-CSE, winter 2010/2011
21
Automatic creation
• how and where?
– in ClockDisplay’s constructor
– automatically executed whenever a
ClockDisplay object is created
– explicitly done with new command
– new creates an object of the specified
class and executes the respective
constructor
Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Kölling;
extensions by HJB&TN for TUM-CSE, winter 2010/2011
22
Objects creating objects
hours = new NumberDisplay(24);
public NumberDisplay(int rollOverLimit);
in class NumberDisplay:
in class ClockDisplay:
formal parameter
actual parameter
Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Kölling;
extensions by HJB&TN for TUM-CSE, winter 2010/2011
23
Method calling
public void timeTick()
{
minutes.increment(); external!
if(minutes.getValue() == 0) {
// it just rolled over!
hours.increment();
}
updateDisplay(); internal!
}
Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Kölling;
extensions by HJB&TN for TUM-CSE, winter 2010/2011
24
Internal vs. external
• internal method calls
– internal means: called method belongs to calling class
(here: ClockDisplay)
updateDisplay();
private void updateDisplay()
• external method calls
– external means: called method belongs to other class
(here: NumberDisplay)
minutes.increment();
Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Kölling;
extensions by HJB&TN for TUM-CSE, winter 2010/2011
25
Calling external methods
object . methodName ( parameter-list )
Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Kölling;
extensions by HJB&TN for TUM-CSE, winter 2010/2011
26
Review: concepts
• abstraction
• modularization
• classes define
types
• class diagram
• object diagram
• object references
• primitive types
• object types
• object creation
• overloading
• internal/external
method call

More Related Content

What's hot

Data abstraction and object orientation
Data abstraction and object orientationData abstraction and object orientation
Data abstraction and object orientationHoang Nguyen
 
Groovy DSLs (JavaOne Presentation)
Groovy DSLs (JavaOne Presentation)Groovy DSLs (JavaOne Presentation)
Groovy DSLs (JavaOne Presentation)Jim Driscoll
 
Map-Reduce and Apache Hadoop
Map-Reduce and Apache HadoopMap-Reduce and Apache Hadoop
Map-Reduce and Apache HadoopSvetlin Nakov
 
Introduction to class in java
Introduction to class in javaIntroduction to class in java
Introduction to class in javakamal kotecha
 
Java Garbage Collection, Monitoring, and Tuning
Java Garbage Collection, Monitoring, and TuningJava Garbage Collection, Monitoring, and Tuning
Java Garbage Collection, Monitoring, and TuningCarol McDonald
 
Java basic part 2 : Datatypes Keywords Features Components Security Exceptions
Java basic part 2 : Datatypes Keywords Features Components Security Exceptions Java basic part 2 : Datatypes Keywords Features Components Security Exceptions
Java basic part 2 : Datatypes Keywords Features Components Security Exceptions Soumen Santra
 
Classes and data abstraction
Classes and data abstractionClasses and data abstraction
Classes and data abstractionHoang Nguyen
 
01 Java Language And OOP Part I LAB
01 Java Language And OOP Part I LAB01 Java Language And OOP Part I LAB
01 Java Language And OOP Part I LABHari Christian
 
Java 5 6 Generics, Concurrency, Garbage Collection, Tuning
Java 5 6 Generics, Concurrency, Garbage Collection, TuningJava 5 6 Generics, Concurrency, Garbage Collection, Tuning
Java 5 6 Generics, Concurrency, Garbage Collection, TuningCarol McDonald
 
Java oops PPT
Java oops PPTJava oops PPT
Java oops PPTkishu0005
 
Core Java- An advanced review of features
Core Java- An advanced review of featuresCore Java- An advanced review of features
Core Java- An advanced review of featuresvidyamittal
 
Java OOP Programming language (Part 8) - Java Database JDBC
Java OOP Programming language (Part 8) - Java Database JDBCJava OOP Programming language (Part 8) - Java Database JDBC
Java OOP Programming language (Part 8) - Java Database JDBCOUM SAOKOSAL
 

What's hot (20)

Chapter08
Chapter08Chapter08
Chapter08
 
Data abstraction and object orientation
Data abstraction and object orientationData abstraction and object orientation
Data abstraction and object orientation
 
gdfgdfg
gdfgdfggdfgdfg
gdfgdfg
 
java review
java reviewjava review
java review
 
Java Day-3
Java Day-3Java Day-3
Java Day-3
 
Groovy DSLs (JavaOne Presentation)
Groovy DSLs (JavaOne Presentation)Groovy DSLs (JavaOne Presentation)
Groovy DSLs (JavaOne Presentation)
 
Class introduction in java
Class introduction in javaClass introduction in java
Class introduction in java
 
Map-Reduce and Apache Hadoop
Map-Reduce and Apache HadoopMap-Reduce and Apache Hadoop
Map-Reduce and Apache Hadoop
 
Introduction to class in java
Introduction to class in javaIntroduction to class in java
Introduction to class in java
 
Java Garbage Collection, Monitoring, and Tuning
Java Garbage Collection, Monitoring, and TuningJava Garbage Collection, Monitoring, and Tuning
Java Garbage Collection, Monitoring, and Tuning
 
Java basic part 2 : Datatypes Keywords Features Components Security Exceptions
Java basic part 2 : Datatypes Keywords Features Components Security Exceptions Java basic part 2 : Datatypes Keywords Features Components Security Exceptions
Java basic part 2 : Datatypes Keywords Features Components Security Exceptions
 
04 sorting
04 sorting04 sorting
04 sorting
 
Classes and data abstraction
Classes and data abstractionClasses and data abstraction
Classes and data abstraction
 
01 Java Language And OOP Part I LAB
01 Java Language And OOP Part I LAB01 Java Language And OOP Part I LAB
01 Java Language And OOP Part I LAB
 
Java 103
Java 103Java 103
Java 103
 
Java 5 6 Generics, Concurrency, Garbage Collection, Tuning
Java 5 6 Generics, Concurrency, Garbage Collection, TuningJava 5 6 Generics, Concurrency, Garbage Collection, Tuning
Java 5 6 Generics, Concurrency, Garbage Collection, Tuning
 
Java oops PPT
Java oops PPTJava oops PPT
Java oops PPT
 
Oop
OopOop
Oop
 
Core Java- An advanced review of features
Core Java- An advanced review of featuresCore Java- An advanced review of features
Core Java- An advanced review of features
 
Java OOP Programming language (Part 8) - Java Database JDBC
Java OOP Programming language (Part 8) - Java Database JDBCJava OOP Programming language (Part 8) - Java Database JDBC
Java OOP Programming language (Part 8) - Java Database JDBC
 

Similar to Obj 3

Towards Object-centric Time-traveling Debuggers
 Towards Object-centric Time-traveling Debuggers Towards Object-centric Time-traveling Debuggers
Towards Object-centric Time-traveling DebuggersESUG
 
Dependency Injection Why is it awesome and Why should I care?
Dependency Injection Why is it awesome and Why should I care?Dependency Injection Why is it awesome and Why should I care?
Dependency Injection Why is it awesome and Why should I care?ColdFusionConference
 
From Java to Kotlin - The first month in practice
From Java to Kotlin - The first month in practiceFrom Java to Kotlin - The first month in practice
From Java to Kotlin - The first month in practiceStefanTomm
 
Java™ (OOP) - Chapter 10: "Thinking in Objects"
Java™ (OOP) - Chapter 10: "Thinking in Objects"Java™ (OOP) - Chapter 10: "Thinking in Objects"
Java™ (OOP) - Chapter 10: "Thinking in Objects"Gouda Mando
 
From Java to Kotlin - The first month in practice v2
From Java to Kotlin - The first month in practice v2From Java to Kotlin - The first month in practice v2
From Java to Kotlin - The first month in practice v2StefanTomm
 
Sample UML Diagram – Employee ClassEmployee- count int- .docx
Sample UML Diagram – Employee ClassEmployee- count  int- .docxSample UML Diagram – Employee ClassEmployee- count  int- .docx
Sample UML Diagram – Employee ClassEmployee- count int- .docxjeffsrosalyn
 
Dependency Injection: Why is awesome and why should I care?
Dependency Injection: Why is awesome and why should I care?Dependency Injection: Why is awesome and why should I care?
Dependency Injection: Why is awesome and why should I care?devObjective
 
Chapter 1- Introduction.ppt
Chapter 1- Introduction.pptChapter 1- Introduction.ppt
Chapter 1- Introduction.pptTigistTilahun1
 
04. constructor & destructor
04. constructor & destructor04. constructor & destructor
04. constructor & destructorHaresh Jaiswal
 
Exciting JavaScript - Part I
Exciting JavaScript - Part IExciting JavaScript - Part I
Exciting JavaScript - Part IEugene Lazutkin
 
New c sharp3_features_(linq)_part_i
New c sharp3_features_(linq)_part_iNew c sharp3_features_(linq)_part_i
New c sharp3_features_(linq)_part_iNico Ludwig
 
MVC and Entity Framework
MVC and Entity FrameworkMVC and Entity Framework
MVC and Entity FrameworkJames Johnson
 

Similar to Obj 3 (20)

3 class definition
3 class definition3 class definition
3 class definition
 
02 objective-c session 2
02  objective-c session 202  objective-c session 2
02 objective-c session 2
 
Towards Object-centric Time-traveling Debuggers
 Towards Object-centric Time-traveling Debuggers Towards Object-centric Time-traveling Debuggers
Towards Object-centric Time-traveling Debuggers
 
Dependency Injection Why is it awesome and Why should I care?
Dependency Injection Why is it awesome and Why should I care?Dependency Injection Why is it awesome and Why should I care?
Dependency Injection Why is it awesome and Why should I care?
 
From Java to Kotlin - The first month in practice
From Java to Kotlin - The first month in practiceFrom Java to Kotlin - The first month in practice
From Java to Kotlin - The first month in practice
 
Java™ (OOP) - Chapter 10: "Thinking in Objects"
Java™ (OOP) - Chapter 10: "Thinking in Objects"Java™ (OOP) - Chapter 10: "Thinking in Objects"
Java™ (OOP) - Chapter 10: "Thinking in Objects"
 
From Java to Kotlin - The first month in practice v2
From Java to Kotlin - The first month in practice v2From Java to Kotlin - The first month in practice v2
From Java to Kotlin - The first month in practice v2
 
Sample UML Diagram – Employee ClassEmployee- count int- .docx
Sample UML Diagram – Employee ClassEmployee- count  int- .docxSample UML Diagram – Employee ClassEmployee- count  int- .docx
Sample UML Diagram – Employee ClassEmployee- count int- .docx
 
00-review.ppt
00-review.ppt00-review.ppt
00-review.ppt
 
Ch09lect1 ud
Ch09lect1 udCh09lect1 ud
Ch09lect1 ud
 
Dependency Injection: Why is awesome and why should I care?
Dependency Injection: Why is awesome and why should I care?Dependency Injection: Why is awesome and why should I care?
Dependency Injection: Why is awesome and why should I care?
 
Dependency Injection
Dependency InjectionDependency Injection
Dependency Injection
 
Ch05lect2 ud
Ch05lect2 udCh05lect2 ud
Ch05lect2 ud
 
Dependency injectionpreso
Dependency injectionpresoDependency injectionpreso
Dependency injectionpreso
 
Chapter 1- Introduction.ppt
Chapter 1- Introduction.pptChapter 1- Introduction.ppt
Chapter 1- Introduction.ppt
 
Objective c
Objective cObjective c
Objective c
 
04. constructor & destructor
04. constructor & destructor04. constructor & destructor
04. constructor & destructor
 
Exciting JavaScript - Part I
Exciting JavaScript - Part IExciting JavaScript - Part I
Exciting JavaScript - Part I
 
New c sharp3_features_(linq)_part_i
New c sharp3_features_(linq)_part_iNew c sharp3_features_(linq)_part_i
New c sharp3_features_(linq)_part_i
 
MVC and Entity Framework
MVC and Entity FrameworkMVC and Entity Framework
MVC and Entity Framework
 

More from Fajar Baskoro

Generasi Terampil Digital Skill-2023.pptx
Generasi Terampil Digital Skill-2023.pptxGenerasi Terampil Digital Skill-2023.pptx
Generasi Terampil Digital Skill-2023.pptxFajar Baskoro
 
Cara Membuat Kursus Online Wordpress-tutorstarter
Cara Membuat Kursus Online Wordpress-tutorstarterCara Membuat Kursus Online Wordpress-tutorstarter
Cara Membuat Kursus Online Wordpress-tutorstarterFajar Baskoro
 
PPT-Kick Off Double Track 2024 melaksanakan Festival Ramadhan
PPT-Kick Off Double Track 2024 melaksanakan Festival RamadhanPPT-Kick Off Double Track 2024 melaksanakan Festival Ramadhan
PPT-Kick Off Double Track 2024 melaksanakan Festival RamadhanFajar Baskoro
 
Buku Inovasi 2023 - 2024 konsep capaian KUS
Buku Inovasi 2023 - 2024 konsep capaian  KUSBuku Inovasi 2023 - 2024 konsep capaian  KUS
Buku Inovasi 2023 - 2024 konsep capaian KUSFajar Baskoro
 
Pemaparan Sosialisasi Program Dual Track 2024.pptx
Pemaparan Sosialisasi Program Dual Track 2024.pptxPemaparan Sosialisasi Program Dual Track 2024.pptx
Pemaparan Sosialisasi Program Dual Track 2024.pptxFajar Baskoro
 
Executive Millennial Entrepreneur Award 2023-1a-1.pdf
Executive Millennial Entrepreneur Award  2023-1a-1.pdfExecutive Millennial Entrepreneur Award  2023-1a-1.pdf
Executive Millennial Entrepreneur Award 2023-1a-1.pdfFajar Baskoro
 
1-Executive Millennial Entrepreneur Award 2023-1-cetak.pptx
1-Executive Millennial Entrepreneur Award  2023-1-cetak.pptx1-Executive Millennial Entrepreneur Award  2023-1-cetak.pptx
1-Executive Millennial Entrepreneur Award 2023-1-cetak.pptxFajar Baskoro
 
Executive Millennial Entrepreneur Award 2023-1.pptx
Executive Millennial Entrepreneur Award  2023-1.pptxExecutive Millennial Entrepreneur Award  2023-1.pptx
Executive Millennial Entrepreneur Award 2023-1.pptxFajar Baskoro
 
Pemrograman Mobile - JetPack Compose1.pptx
Pemrograman Mobile - JetPack Compose1.pptxPemrograman Mobile - JetPack Compose1.pptx
Pemrograman Mobile - JetPack Compose1.pptxFajar Baskoro
 
Evaluasi KPP Program Dual Track Provinsi Kaltim
Evaluasi KPP Program Dual Track Provinsi KaltimEvaluasi KPP Program Dual Track Provinsi Kaltim
Evaluasi KPP Program Dual Track Provinsi KaltimFajar Baskoro
 
foto tenda digital skill program dari sekolah
foto tenda digital skill program dari sekolahfoto tenda digital skill program dari sekolah
foto tenda digital skill program dari sekolahFajar Baskoro
 
Meraih Peluang di Gig Economy yang cocok bagi remaja
Meraih Peluang di Gig Economy yang cocok bagi remajaMeraih Peluang di Gig Economy yang cocok bagi remaja
Meraih Peluang di Gig Economy yang cocok bagi remajaFajar Baskoro
 
Membangun aplikasi mobile dengan Appsheet
Membangun aplikasi mobile dengan AppsheetMembangun aplikasi mobile dengan Appsheet
Membangun aplikasi mobile dengan AppsheetFajar Baskoro
 
Transition education to employment.pdf
Transition education to employment.pdfTransition education to employment.pdf
Transition education to employment.pdfFajar Baskoro
 

More from Fajar Baskoro (20)

Generasi Terampil Digital Skill-2023.pptx
Generasi Terampil Digital Skill-2023.pptxGenerasi Terampil Digital Skill-2023.pptx
Generasi Terampil Digital Skill-2023.pptx
 
Cara Membuat Kursus Online Wordpress-tutorstarter
Cara Membuat Kursus Online Wordpress-tutorstarterCara Membuat Kursus Online Wordpress-tutorstarter
Cara Membuat Kursus Online Wordpress-tutorstarter
 
PPT-Kick Off Double Track 2024 melaksanakan Festival Ramadhan
PPT-Kick Off Double Track 2024 melaksanakan Festival RamadhanPPT-Kick Off Double Track 2024 melaksanakan Festival Ramadhan
PPT-Kick Off Double Track 2024 melaksanakan Festival Ramadhan
 
Buku Inovasi 2023 - 2024 konsep capaian KUS
Buku Inovasi 2023 - 2024 konsep capaian  KUSBuku Inovasi 2023 - 2024 konsep capaian  KUS
Buku Inovasi 2023 - 2024 konsep capaian KUS
 
Pemaparan Sosialisasi Program Dual Track 2024.pptx
Pemaparan Sosialisasi Program Dual Track 2024.pptxPemaparan Sosialisasi Program Dual Track 2024.pptx
Pemaparan Sosialisasi Program Dual Track 2024.pptx
 
Executive Millennial Entrepreneur Award 2023-1a-1.pdf
Executive Millennial Entrepreneur Award  2023-1a-1.pdfExecutive Millennial Entrepreneur Award  2023-1a-1.pdf
Executive Millennial Entrepreneur Award 2023-1a-1.pdf
 
1-Executive Millennial Entrepreneur Award 2023-1-cetak.pptx
1-Executive Millennial Entrepreneur Award  2023-1-cetak.pptx1-Executive Millennial Entrepreneur Award  2023-1-cetak.pptx
1-Executive Millennial Entrepreneur Award 2023-1-cetak.pptx
 
Executive Millennial Entrepreneur Award 2023-1.pptx
Executive Millennial Entrepreneur Award  2023-1.pptxExecutive Millennial Entrepreneur Award  2023-1.pptx
Executive Millennial Entrepreneur Award 2023-1.pptx
 
Pemrograman Mobile - JetPack Compose1.pptx
Pemrograman Mobile - JetPack Compose1.pptxPemrograman Mobile - JetPack Compose1.pptx
Pemrograman Mobile - JetPack Compose1.pptx
 
Evaluasi KPP Program Dual Track Provinsi Kaltim
Evaluasi KPP Program Dual Track Provinsi KaltimEvaluasi KPP Program Dual Track Provinsi Kaltim
Evaluasi KPP Program Dual Track Provinsi Kaltim
 
foto tenda digital skill program dari sekolah
foto tenda digital skill program dari sekolahfoto tenda digital skill program dari sekolah
foto tenda digital skill program dari sekolah
 
Meraih Peluang di Gig Economy yang cocok bagi remaja
Meraih Peluang di Gig Economy yang cocok bagi remajaMeraih Peluang di Gig Economy yang cocok bagi remaja
Meraih Peluang di Gig Economy yang cocok bagi remaja
 
Membangun aplikasi mobile dengan Appsheet
Membangun aplikasi mobile dengan AppsheetMembangun aplikasi mobile dengan Appsheet
Membangun aplikasi mobile dengan Appsheet
 
epl1.pdf
epl1.pdfepl1.pdf
epl1.pdf
 
user.docx
user.docxuser.docx
user.docx
 
Dtmart.pptx
Dtmart.pptxDtmart.pptx
Dtmart.pptx
 
DualTrack-2023.pptx
DualTrack-2023.pptxDualTrack-2023.pptx
DualTrack-2023.pptx
 
BADGE.pptx
BADGE.pptxBADGE.pptx
BADGE.pptx
 
womenatwork.pdf
womenatwork.pdfwomenatwork.pdf
womenatwork.pdf
 
Transition education to employment.pdf
Transition education to employment.pdfTransition education to employment.pdf
Transition education to employment.pdf
 

Recently uploaded

Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
XpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsXpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsMehedi Hasan Shohan
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number SystemsJheuzeDellosa
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfkalichargn70th171
 
buds n tech IT solutions
buds n  tech IT                solutionsbuds n  tech IT                solutions
buds n tech IT solutionsmonugehlot87
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyFrank van der Linden
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfPower Karaoke
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 
cybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningcybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningVitsRangannavar
 
What are the features of Vehicle Tracking System?
What are the features of Vehicle Tracking System?What are the features of Vehicle Tracking System?
What are the features of Vehicle Tracking System?Watsoo Telematics
 

Recently uploaded (20)

Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
 
XpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsXpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software Solutions
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number Systems
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
 
buds n tech IT solutions
buds n  tech IT                solutionsbuds n  tech IT                solutions
buds n tech IT solutions
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The Ugly
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdf
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 
cybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningcybersecurity notes for mca students for learning
cybersecurity notes for mca students for learning
 
What are the features of Vehicle Tracking System?
What are the features of Vehicle Tracking System?What are the features of Vehicle Tracking System?
What are the features of Vehicle Tracking System?
 

Obj 3

  • 1. Objects First With Java A Practical Introduction Using BlueJ Object interaction Creating cooperating objects 2.0
  • 2. Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Kölling; extensions by HJB&TN for TUM-CSE, winter 2010/2011 2 The next step • so far: – what objects are – how they are implemented • now: – combine classes and objects – let objects cooperate – how methods call other methods
  • 3. Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Kölling; extensions by HJB&TN for TUM-CSE, winter 2010/2011 3 Project: a digital clock hours (European style: 0..23) minutes always the same
  • 4. Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Kölling; extensions by HJB&TN for TUM-CSE, winter 2010/2011 4 Abstraction • Why not define the digital clock as one single class? – complexity substructuring (divide and conquer)! – effect: “abstract” from a component’s details (not everyone needs to know everything …) • Abstraction is the ability to ignore details of parts to focus attention on a higher level of a problem.
  • 5. Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Kölling; extensions by HJB&TN for TUM-CSE, winter 2010/2011 5 Modularization • Modularization: process of dividing a whole into well-defined parts, which can be built and examined separately, and which interact in well-defined ways. • Modularization and abstraction complement each other. • Both concepts are crucial for object- oriented software (components and subcomponents being objects here).
  • 6. Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Kölling; extensions by HJB&TN for TUM-CSE, winter 2010/2011 6 Modularizing the clock display One four-digit display? Or two two-digit displays? One or two classes? Differences?
  • 7. Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Kölling; extensions by HJB&TN for TUM-CSE, winter 2010/2011 7 Implementation - NumberDisplay public class NumberDisplay { private int limit; private int value; public NumberDisplay(int rollOverLimit) { limit = rollOverLimit; value = 0; } methods omitted. } when to roll back to 0? current value? fields:
  • 8. Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Kölling; extensions by HJB&TN for TUM-CSE, winter 2010/2011 8 Implementation - ClockDisplay public class ClockDisplay { private NumberDisplay hours; private NumberDisplay minutes; Constructor and methods omitted. } Class names can be used as types!
  • 9. Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Kölling; extensions by HJB&TN for TUM-CSE, winter 2010/2011 9 Class diagrams • class diagrams show classes and their relationships – hence, a static view of a program “depends on, needs”
  • 10. Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Kölling; extensions by HJB&TN for TUM-CSE, winter 2010/2011 10 Object diagrams • object diagrams show objects and their relationships at one moment in time – hence, a dynamic view of a program not really “included”, but references only!
  • 11. Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Kölling; extensions by HJB&TN for TUM-CSE, winter 2010/2011 11 Starting the program • Start program by creating an object of type/class ClockDisplay. (bluej) • Then: automatic creation of two NumberDisplay objects for own purposes
  • 12. Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Kölling; extensions by HJB&TN for TUM-CSE, winter 2010/2011 12 Primitive types vs. object types 32 object type (by classes, given by Java system or by programmer) primitive type (predefined in Java) Note different way of storing! (direct value vs. reference) SomeObject obj; int i;
  • 13. Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Kölling; extensions by HJB&TN for TUM-CSE, winter 2010/2011 13 Primitive types vs. object types 32 SomeObject a; int a; SomeObject b; 32 int b; b = a; two references of the same type!
  • 14. Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Kölling; extensions by HJB&TN for TUM-CSE, winter 2010/2011 14 Source code: NumberDisplay public NumberDisplay(int rollOverLimit) { limit = rollOverLimit; constructor! value = 0; } 4 methods: getValue, setValue, getDisplayValue, increment public void increment() { value = (value + 1) % limit; }
  • 15. Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Kölling; extensions by HJB&TN for TUM-CSE, winter 2010/2011 15 Source code: NumberDisplay public String getDisplayValue() { if(value < 10) return "0" + value; else return "" + value; } why not directly return value? public void setValue(int replacementValue) { if((replacementValue >= 0) && (replacementValue < limit)) value = replacementValue; } what happens if replacement value is illegal? OK?
  • 16. Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Kölling; extensions by HJB&TN for TUM-CSE, winter 2010/2011 16 Logical operators • operate on boolean values • produce a new boolean value as result • available in Java: – && (and) – || (or) – ! (not)
  • 17. Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Kölling; extensions by HJB&TN for TUM-CSE, winter 2010/2011 17 Further operators • String concatenation – with “+” operator – spaces/blanks must be added explicitly – If one operand is a string, both the others and the result are converted to string. – the “+=” operator acts as for int or double data types • modulo: %
  • 18. Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Kölling; extensions by HJB&TN for TUM-CSE, winter 2010/2011 18 ClockDisplay object diagram where do the three objects come from?
  • 19. Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Kölling; extensions by HJB&TN for TUM-CSE, winter 2010/2011 19 Objects creating objects public class ClockDisplay { private NumberDisplay hours; private NumberDisplay minutes; private String displayString; public ClockDisplay() { hours = new NumberDisplay(24); minutes = new NumberDisplay(60); updateDisplay(); } }
  • 20. Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Kölling; extensions by HJB&TN for TUM-CSE, winter 2010/2011 20 Alternative public class ClockDisplay { private NumberDisplay hours; private NumberDisplay minutes; private String displayString; public ClockDisplay(int hour, int minute) { hours = new NumberDisplay(24); minutes = new NumberDisplay(60); setTime(hour, minute); } } multiple constructors in one class possible! Overloading
  • 21. Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Kölling; extensions by HJB&TN for TUM-CSE, winter 2010/2011 21 Automatic creation • how and where? – in ClockDisplay’s constructor – automatically executed whenever a ClockDisplay object is created – explicitly done with new command – new creates an object of the specified class and executes the respective constructor
  • 22. Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Kölling; extensions by HJB&TN for TUM-CSE, winter 2010/2011 22 Objects creating objects hours = new NumberDisplay(24); public NumberDisplay(int rollOverLimit); in class NumberDisplay: in class ClockDisplay: formal parameter actual parameter
  • 23. Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Kölling; extensions by HJB&TN for TUM-CSE, winter 2010/2011 23 Method calling public void timeTick() { minutes.increment(); external! if(minutes.getValue() == 0) { // it just rolled over! hours.increment(); } updateDisplay(); internal! }
  • 24. Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Kölling; extensions by HJB&TN for TUM-CSE, winter 2010/2011 24 Internal vs. external • internal method calls – internal means: called method belongs to calling class (here: ClockDisplay) updateDisplay(); private void updateDisplay() • external method calls – external means: called method belongs to other class (here: NumberDisplay) minutes.increment();
  • 25. Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Kölling; extensions by HJB&TN for TUM-CSE, winter 2010/2011 25 Calling external methods object . methodName ( parameter-list )
  • 26. Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Kölling; extensions by HJB&TN for TUM-CSE, winter 2010/2011 26 Review: concepts • abstraction • modularization • classes define types • class diagram • object diagram • object references • primitive types • object types • object creation • overloading • internal/external method call