SlideShare a Scribd company logo
Object Oriented Programming
Chapter 2: Array of objects
Prepared by: Mahmoud Rafeek Alfarra
2016
Chapter2 array of objects
Outlines
◉ User defined type
◉ Array of User defined type (new class)
◉ Passing Objects to Methods
◉ Immutable Objects and Classes
◉ Full Example
Note: I have prepared this material Based on (Liang: “Introduction to Programming using Java”, 10’th edition, 2015)
Lecture
Let’s think on fieldes of class
3
o As the defined class is a new data type, we can defined any
variables or arrays of it.
User defined type
Array of User defined type
int sal;
int id;
String name;
…
Employee class
e1
e2
e3
e4
e5
e6
e7
e8
Employee [ ] x ;
Array of User defined type
o An array of objects is actually an array of reference variables.
Circle[] circleArray = new Circle[10];
Array of User defined type
Class [ ] x ;
Add objects
Delete objects
Looking for objects
Printing all data
….
Class
To management many objects
which are stored in array
o Passing by value for primitive type value (the value is passed to
the parameter)
o Passing by value for reference type value (the value is the
reference to the object)
Passing Objects to Methods
Passing Objects to Methods
o For a class to be immutable, it must mark all data fields private
and provide no mutator methods and no accessor methods that
would return a reference to a mutable data field object.
o If the contents of an object cannot be changed once the object
is created, the object is called an immutable object and its class
is called an immutable class.
Immutable Objects and Classes
Immutable ?
public class Student {
private int id;
private BirthDate birthDate;
public Student(int ssn,
int year, int month, int day) {
id = ssn;
birthDate = new BirthDate(year, month, day);
}
public int getId() {
return id;
}
public BirthDate getBirthDate() {
return birthDate;
}
}
public class BirthDate {
private int year;
private int month;
private int day;
public BirthDate(int newYear,
int newMonth, int newDay) {
year = newYear;
month = newMonth;
day = newDay;
}
public void setYear(int newYear) {
year = newYear;
}
}
Example: ContactBook
int serial;
String name;
String mobile;
String address;
…
Contact class
int count;
void search(){}
void print(){}
void insert(){}
…
ManagArray class
e1
e2
e3
e4
e5
e6
e7
e8
Contact [ ] conArray ;
Contact book
class Contact {
private String name;
//….
public Contact (String name, String mobile) { … }
}
class ManagArray {
private Contact [ ] contBook;
private int count;
// …
public ManagArray(int size){ … }
public void insert(Contact c) { …. }
public void printData() { … }
public void searchByName(String name) { … }
}
static int x;
class Test
obj1
X = 0X = 1
obj2
X = 2
obj3
X = 3
Now:
Print Obj1.X
3
Print Obj1.X
3
Print Obj1.X
3
Practices
Group 1
Give 3 examples to
array of objects.
Group 2
Diffrenciate between
Passing by value and
by reference.
Group 3
Develop Immutable
class.
THANKS!
Any questions?
You can find me at:
Fb/mahmoudRAlfarra
Staff.cst.ps/mfarra
Youtube.com/mralfarra1
@mralfarra

More Related Content

PPTX
Object Oriented Programming_Lecture 2
Mahmoud Alfarra
 
PPTX
‫Object Oriented Programming_Lecture 3
Mahmoud Alfarra
 
PPT
البرمجة الهدفية بلغة جافا - مصفوفة الكائنات
Mahmoud Alfarra
 
PPT
البرمجة الهدفية بلغة جافا - مفاهيم أساسية
Mahmoud Alfarra
 
PPT
البرمجة الهدفية بلغة جافا - تعدد الأشكال
Mahmoud Alfarra
 
PPTX
‫‫Chapter4 Polymorphism
Mahmoud Alfarra
 
PPT
Object and class
mohit tripathi
 
PPTX
‫Chapter3 inheritance
Mahmoud Alfarra
 
Object Oriented Programming_Lecture 2
Mahmoud Alfarra
 
‫Object Oriented Programming_Lecture 3
Mahmoud Alfarra
 
البرمجة الهدفية بلغة جافا - مصفوفة الكائنات
Mahmoud Alfarra
 
البرمجة الهدفية بلغة جافا - مفاهيم أساسية
Mahmoud Alfarra
 
البرمجة الهدفية بلغة جافا - تعدد الأشكال
Mahmoud Alfarra
 
‫‫Chapter4 Polymorphism
Mahmoud Alfarra
 
Object and class
mohit tripathi
 
‫Chapter3 inheritance
Mahmoud Alfarra
 

What's hot (20)

PPTX
Class or Object
Rahul Bathri
 
PPTX
Data members and member functions
Marlom46
 
PPT
البرمجة الهدفية بلغة جافا - الوراثة
Mahmoud Alfarra
 
PPT
Class and object in c++
NainaKhan28
 
PDF
ITFT-Classes and object in java
Atul Sehdev
 
PDF
Class and Objects in Java
Spotle.ai
 
PDF
CLASS & OBJECT IN JAVA
Riaj Uddin Mahi
 
PPT
Lect 1-class and object
Fajar Baskoro
 
PPT
Class and object in C++
rprajat007
 
PPT
Object and class in java
Umamaheshwariv1
 
PDF
Lect 1-java object-classes
Fajar Baskoro
 
PPT
C++ classes
imhammadali
 
PPTX
Java class,object,method introduction
Sohanur63
 
PPT
11 Using classes and objects
maznabili
 
PPTX
Pi j3.2 polymorphism
mcollison
 
PPTX
[OOP - Lec 09,10,11] Class Members & their Accessing
Muhammad Hammad Waseem
 
PPTX
Static keyword ppt
Vinod Kumar
 
PPT
Data members and member functions
Harsh Patel
 
PPT
Class & Object - Intro
PRN USM
 
PPTX
Classes and objects
rajveer_Pannu
 
Class or Object
Rahul Bathri
 
Data members and member functions
Marlom46
 
البرمجة الهدفية بلغة جافا - الوراثة
Mahmoud Alfarra
 
Class and object in c++
NainaKhan28
 
ITFT-Classes and object in java
Atul Sehdev
 
Class and Objects in Java
Spotle.ai
 
CLASS & OBJECT IN JAVA
Riaj Uddin Mahi
 
Lect 1-class and object
Fajar Baskoro
 
Class and object in C++
rprajat007
 
Object and class in java
Umamaheshwariv1
 
Lect 1-java object-classes
Fajar Baskoro
 
C++ classes
imhammadali
 
Java class,object,method introduction
Sohanur63
 
11 Using classes and objects
maznabili
 
Pi j3.2 polymorphism
mcollison
 
[OOP - Lec 09,10,11] Class Members & their Accessing
Muhammad Hammad Waseem
 
Static keyword ppt
Vinod Kumar
 
Data members and member functions
Harsh Patel
 
Class & Object - Intro
PRN USM
 
Classes and objects
rajveer_Pannu
 
Ad

Similar to Chapter2 array of objects (20)

PPT
10slide.ppt
MohammedNouh7
 
PPTX
L03 Software Design
Ólafur Andri Ragnarsson
 
PPT
OOP Principles
Upender Upr
 
PPT
Oops Concept Java
Kamlesh Singh
 
PDF
Arrays Java
Jose Sumba
 
PPT
Java™ (OOP) - Chapter 10: "Thinking in Objects"
Gouda Mando
 
PPT
Java căn bản - Chapter10
Vince Vo
 
PPTX
Presentation2.ppt java basic core ppt .
KeshavMotivation
 
PPT
10slide
Dorothea Chaffin
 
PPT
JavaYDL10
Terry Yoast
 
PPTX
OOP - Java is pass-by-value
Mudasir Qazi
 
PPTX
Object oriented programming2 Week 2.pptx
MirHazarKhan1
 
PPT
Java Tutorial
Singsys Pte Ltd
 
PPTX
chapter 5 concepts of object oriented programming
WondimuBantihun1
 
PPTX
Upstate CSCI 200 Java Chapter 8 - Arrays
DanWooster1
 
PPT
STRINGS IN JAVA
LOVELY PROFESSIONAL UNIVERSITY
 
PPTX
Arrays in programming
TaseerRao
 
PPTX
UNIT I OOP AND JAVA FUNDAMENTALS CONSTRUCTOR
mohanrajm63
 
10slide.ppt
MohammedNouh7
 
L03 Software Design
Ólafur Andri Ragnarsson
 
OOP Principles
Upender Upr
 
Oops Concept Java
Kamlesh Singh
 
Arrays Java
Jose Sumba
 
Java™ (OOP) - Chapter 10: "Thinking in Objects"
Gouda Mando
 
Java căn bản - Chapter10
Vince Vo
 
Presentation2.ppt java basic core ppt .
KeshavMotivation
 
JavaYDL10
Terry Yoast
 
OOP - Java is pass-by-value
Mudasir Qazi
 
Object oriented programming2 Week 2.pptx
MirHazarKhan1
 
Java Tutorial
Singsys Pte Ltd
 
chapter 5 concepts of object oriented programming
WondimuBantihun1
 
Upstate CSCI 200 Java Chapter 8 - Arrays
DanWooster1
 
Arrays in programming
TaseerRao
 
UNIT I OOP AND JAVA FUNDAMENTALS CONSTRUCTOR
mohanrajm63
 
Ad

More from Mahmoud Alfarra (20)

PPT
Computer Programming, Loops using Java - part 2
Mahmoud Alfarra
 
PPT
Computer Programming, Loops using Java
Mahmoud Alfarra
 
PPT
Chapter 10: hashing data structure
Mahmoud Alfarra
 
PPT
Chapter9 graph data structure
Mahmoud Alfarra
 
PPT
Chapter 8: tree data structure
Mahmoud Alfarra
 
PPT
Chapter 7: Queue data structure
Mahmoud Alfarra
 
PPT
Chapter 6: stack data structure
Mahmoud Alfarra
 
PPT
Chapter 5: linked list data structure
Mahmoud Alfarra
 
PPT
Chapter 4: basic search algorithms data structure
Mahmoud Alfarra
 
PPT
Chapter 3: basic sorting algorithms data structure
Mahmoud Alfarra
 
PPT
Chapter 2: array and array list data structure
Mahmoud Alfarra
 
PPT
Chapter1 intro toprincipleofc#_datastructure_b_cs
Mahmoud Alfarra
 
PPT
Chapter 0: introduction to data structure
Mahmoud Alfarra
 
PPTX
3 classification
Mahmoud Alfarra
 
PPT
8 programming-using-java decision-making practices 20102011
Mahmoud Alfarra
 
PPT
7 programming-using-java decision-making220102011
Mahmoud Alfarra
 
PPT
6 programming-using-java decision-making20102011-
Mahmoud Alfarra
 
PPT
5 programming-using-java intro-tooop20102011
Mahmoud Alfarra
 
PPT
4 programming-using-java intro-tojava20102011
Mahmoud Alfarra
 
PPT
3 programming-using-java introduction-to computer
Mahmoud Alfarra
 
Computer Programming, Loops using Java - part 2
Mahmoud Alfarra
 
Computer Programming, Loops using Java
Mahmoud Alfarra
 
Chapter 10: hashing data structure
Mahmoud Alfarra
 
Chapter9 graph data structure
Mahmoud Alfarra
 
Chapter 8: tree data structure
Mahmoud Alfarra
 
Chapter 7: Queue data structure
Mahmoud Alfarra
 
Chapter 6: stack data structure
Mahmoud Alfarra
 
Chapter 5: linked list data structure
Mahmoud Alfarra
 
Chapter 4: basic search algorithms data structure
Mahmoud Alfarra
 
Chapter 3: basic sorting algorithms data structure
Mahmoud Alfarra
 
Chapter 2: array and array list data structure
Mahmoud Alfarra
 
Chapter1 intro toprincipleofc#_datastructure_b_cs
Mahmoud Alfarra
 
Chapter 0: introduction to data structure
Mahmoud Alfarra
 
3 classification
Mahmoud Alfarra
 
8 programming-using-java decision-making practices 20102011
Mahmoud Alfarra
 
7 programming-using-java decision-making220102011
Mahmoud Alfarra
 
6 programming-using-java decision-making20102011-
Mahmoud Alfarra
 
5 programming-using-java intro-tooop20102011
Mahmoud Alfarra
 
4 programming-using-java intro-tojava20102011
Mahmoud Alfarra
 
3 programming-using-java introduction-to computer
Mahmoud Alfarra
 

Recently uploaded (20)

PDF
What is CFA?? Complete Guide to the Chartered Financial Analyst Program
sp4989653
 
PPTX
Kanban Cards _ Mass Action in Odoo 18.2 - Odoo Slides
Celine George
 
PPTX
How to Close Subscription in Odoo 18 - Odoo Slides
Celine George
 
PDF
The Minister of Tourism, Culture and Creative Arts, Abla Dzifa Gomashie has e...
nservice241
 
PDF
2.Reshaping-Indias-Political-Map.ppt/pdf/8th class social science Exploring S...
Sandeep Swamy
 
PDF
Phylum Arthropoda: Characteristics and Classification, Entomology Lecture
Miraj Khan
 
PDF
The Picture of Dorian Gray summary and depiction
opaliyahemel
 
PPTX
PREVENTIVE PEDIATRIC. pptx
AneetaSharma15
 
PPTX
Dakar Framework Education For All- 2000(Act)
santoshmohalik1
 
PPTX
Measures_of_location_-_Averages_and__percentiles_by_DR SURYA K.pptx
Surya Ganesh
 
PDF
The-Invisible-Living-World-Beyond-Our-Naked-Eye chapter 2.pdf/8th science cur...
Sandeep Swamy
 
PPTX
CARE OF UNCONSCIOUS PATIENTS .pptx
AneetaSharma15
 
PDF
Study Material and notes for Women Empowerment
ComputerScienceSACWC
 
DOCX
SAROCES Action-Plan FOR ARAL PROGRAM IN DEPED
Levenmartlacuna1
 
PPTX
family health care settings home visit - unit 6 - chn 1 - gnm 1st year.pptx
Priyanshu Anand
 
DOCX
Unit 5: Speech-language and swallowing disorders
JELLA VISHNU DURGA PRASAD
 
PDF
Sunset Boulevard Student Revision Booklet
jpinnuck
 
PDF
Virat Kohli- the Pride of Indian cricket
kushpar147
 
PDF
Health-The-Ultimate-Treasure (1).pdf/8th class science curiosity /samyans edu...
Sandeep Swamy
 
PPTX
HISTORY COLLECTION FOR PSYCHIATRIC PATIENTS.pptx
PoojaSen20
 
What is CFA?? Complete Guide to the Chartered Financial Analyst Program
sp4989653
 
Kanban Cards _ Mass Action in Odoo 18.2 - Odoo Slides
Celine George
 
How to Close Subscription in Odoo 18 - Odoo Slides
Celine George
 
The Minister of Tourism, Culture and Creative Arts, Abla Dzifa Gomashie has e...
nservice241
 
2.Reshaping-Indias-Political-Map.ppt/pdf/8th class social science Exploring S...
Sandeep Swamy
 
Phylum Arthropoda: Characteristics and Classification, Entomology Lecture
Miraj Khan
 
The Picture of Dorian Gray summary and depiction
opaliyahemel
 
PREVENTIVE PEDIATRIC. pptx
AneetaSharma15
 
Dakar Framework Education For All- 2000(Act)
santoshmohalik1
 
Measures_of_location_-_Averages_and__percentiles_by_DR SURYA K.pptx
Surya Ganesh
 
The-Invisible-Living-World-Beyond-Our-Naked-Eye chapter 2.pdf/8th science cur...
Sandeep Swamy
 
CARE OF UNCONSCIOUS PATIENTS .pptx
AneetaSharma15
 
Study Material and notes for Women Empowerment
ComputerScienceSACWC
 
SAROCES Action-Plan FOR ARAL PROGRAM IN DEPED
Levenmartlacuna1
 
family health care settings home visit - unit 6 - chn 1 - gnm 1st year.pptx
Priyanshu Anand
 
Unit 5: Speech-language and swallowing disorders
JELLA VISHNU DURGA PRASAD
 
Sunset Boulevard Student Revision Booklet
jpinnuck
 
Virat Kohli- the Pride of Indian cricket
kushpar147
 
Health-The-Ultimate-Treasure (1).pdf/8th class science curiosity /samyans edu...
Sandeep Swamy
 
HISTORY COLLECTION FOR PSYCHIATRIC PATIENTS.pptx
PoojaSen20
 

Chapter2 array of objects

  • 1. Object Oriented Programming Chapter 2: Array of objects Prepared by: Mahmoud Rafeek Alfarra 2016
  • 3. Outlines ◉ User defined type ◉ Array of User defined type (new class) ◉ Passing Objects to Methods ◉ Immutable Objects and Classes ◉ Full Example Note: I have prepared this material Based on (Liang: “Introduction to Programming using Java”, 10’th edition, 2015)
  • 4. Lecture Let’s think on fieldes of class 3
  • 5. o As the defined class is a new data type, we can defined any variables or arrays of it. User defined type
  • 6. Array of User defined type int sal; int id; String name; … Employee class e1 e2 e3 e4 e5 e6 e7 e8 Employee [ ] x ;
  • 7. Array of User defined type o An array of objects is actually an array of reference variables. Circle[] circleArray = new Circle[10];
  • 8. Array of User defined type Class [ ] x ; Add objects Delete objects Looking for objects Printing all data …. Class To management many objects which are stored in array
  • 9. o Passing by value for primitive type value (the value is passed to the parameter) o Passing by value for reference type value (the value is the reference to the object) Passing Objects to Methods
  • 11. o For a class to be immutable, it must mark all data fields private and provide no mutator methods and no accessor methods that would return a reference to a mutable data field object. o If the contents of an object cannot be changed once the object is created, the object is called an immutable object and its class is called an immutable class. Immutable Objects and Classes
  • 12. Immutable ? public class Student { private int id; private BirthDate birthDate; public Student(int ssn, int year, int month, int day) { id = ssn; birthDate = new BirthDate(year, month, day); } public int getId() { return id; } public BirthDate getBirthDate() { return birthDate; } } public class BirthDate { private int year; private int month; private int day; public BirthDate(int newYear, int newMonth, int newDay) { year = newYear; month = newMonth; day = newDay; } public void setYear(int newYear) { year = newYear; } }
  • 13. Example: ContactBook int serial; String name; String mobile; String address; … Contact class int count; void search(){} void print(){} void insert(){} … ManagArray class e1 e2 e3 e4 e5 e6 e7 e8 Contact [ ] conArray ;
  • 14. Contact book class Contact { private String name; //…. public Contact (String name, String mobile) { … } } class ManagArray { private Contact [ ] contBook; private int count; // … public ManagArray(int size){ … } public void insert(Contact c) { …. } public void printData() { … } public void searchByName(String name) { … } }
  • 15. static int x; class Test obj1 X = 0X = 1 obj2 X = 2 obj3 X = 3 Now: Print Obj1.X 3 Print Obj1.X 3 Print Obj1.X 3
  • 16. Practices Group 1 Give 3 examples to array of objects. Group 2 Diffrenciate between Passing by value and by reference. Group 3 Develop Immutable class.
  • 17. THANKS! Any questions? You can find me at: Fb/mahmoudRAlfarra Staff.cst.ps/mfarra Youtube.com/mralfarra1 @mralfarra