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

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
 

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
 
Ad

Recently uploaded (20)

PDF
Aprendendo Arquitetura Framework Salesforce - Dia 03
Mauricio Alexandre Silva
 
PPT
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 
PPTX
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
PPTX
I AM MALALA The Girl Who Stood Up for Education and was Shot by the Taliban...
Beena E S
 
PDF
Dimensions of Societal Planning in Commonism
StefanMz
 
PPTX
How to Handle Salesperson Commision in Odoo 18 Sales
Celine George
 
PDF
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 
PPTX
PPT-Q1-WK-3-ENGLISH Revised Matatag Grade 3.pptx
reijhongidayawan02
 
PPTX
HUMAN RESOURCE MANAGEMENT: RECRUITMENT, SELECTION, PLACEMENT, DEPLOYMENT, TRA...
PRADEEP ABOTHU
 
PDF
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
PDF
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
PDF
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
PPTX
Stereochemistry-Optical Isomerism in organic compoundsptx
Tarannum Nadaf-Mansuri
 
PDF
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
PDF
Geographical Diversity of India 100 Mcq.pdf/ 7th class new ncert /Social/Samy...
Sandeep Swamy
 
PPTX
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 
PDF
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
PDF
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
PDF
Exploring the Different Types of Experimental Research
Thelma Villaflores
 
PPTX
CATEGORIES OF NURSING PERSONNEL: HOSPITAL & COLLEGE
PRADEEP ABOTHU
 
Aprendendo Arquitetura Framework Salesforce - Dia 03
Mauricio Alexandre Silva
 
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
I AM MALALA The Girl Who Stood Up for Education and was Shot by the Taliban...
Beena E S
 
Dimensions of Societal Planning in Commonism
StefanMz
 
How to Handle Salesperson Commision in Odoo 18 Sales
Celine George
 
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 
PPT-Q1-WK-3-ENGLISH Revised Matatag Grade 3.pptx
reijhongidayawan02
 
HUMAN RESOURCE MANAGEMENT: RECRUITMENT, SELECTION, PLACEMENT, DEPLOYMENT, TRA...
PRADEEP ABOTHU
 
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
Stereochemistry-Optical Isomerism in organic compoundsptx
Tarannum Nadaf-Mansuri
 
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
Geographical Diversity of India 100 Mcq.pdf/ 7th class new ncert /Social/Samy...
Sandeep Swamy
 
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
Exploring the Different Types of Experimental Research
Thelma Villaflores
 
CATEGORIES OF NURSING PERSONNEL: HOSPITAL & COLLEGE
PRADEEP ABOTHU
 

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