SlideShare a Scribd company logo
1 of 16
O
O
P
Array of objects
Object Oriented Programming
Prepared & Presented by:
Mahmoud Rafeek Alfarra
2012
Chapter 2
OO
OO
PP
http://mfarra.cst.ps
Contents
Class: User defined type1
Array of type (class)2
Example: Contact book3
static Class Members4
OO
OO
PP
Class: User defined type
As the defined class is a new data type,
we can defined any variables or arrays of
it.
http://mfarra.cst.ps
OO
OO
PP
Array of objects of class
http://mfarra.cst.ps
int sal;
int id;
String name;
…
Employee class
e1
e2
e3
e4
e5
e6
e7
e8
Employee [] x ;
In this case, each item in the array will be used by using
its properties and methods.
OO
OO
PP
Example: Contact book
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 ;
From type of contact
Manages the book
http://mfarra.cst.ps
OO
OO
PP
Example: Contact book
http://mfarra.cst.ps
.
.
.
Management of contacts
Address Book
OO
OO
PP
Contact class
http://mfarra.cst.ps
class Contact {
private String name;
private String mobile;
private String address;
public Contact (String name, String mobile, String address){
this.name = name;
this.mobile = mobile;
this.address = address;
}
// Set methods of all properties
public void setName(String name){
this.name = name;
}
public void setMobile(String mobile){ … }
public void setAddress(String Address){ … }
// Get methods of all properties
public String getMobile(){
return mobile;
}
public String getAddress() { … }
public String getName(){ … }
public void printData(){
System.out.println("Name: "+name+"n Mobile:" +mobile+" n Address: "+address);
} }
OO
OO
PP
ManagArray class
http://mfarra.cst.ps
class ManagArray {
private Contact [] contBook; // Declaration of array of contact class
private int count;
public ManagArray(int size){
count = 0;
contBook = new Contact[size]; // initialize the size of array(# of contacts)
}
public void insert(Contact c){
contBook[count] = c; // insert statement
count++;
System.out.println("congratulation, a new address is inserted");
}
public void printData(){
if (count ==0)
System.out.println("Sorry, the contact book is empty");
else
{
for(int i=0; i< count; i++)
{
System.out.println("================");
contBook[i].printData(); // Print the data of object i
}
System.out.println("Print Data is done!!");} }
// rest of methods
}
OO
OO
PP
Main class
http://mfarra.cst.ps
public static void main(String[] args) {
ManagArray book1 = new ManagArray(5);
// Create objects of contact
Contact c1 = new Contact("Ali", "0599","Khan");
Contact c2 = new Contact("Ola", "0598","gaza");
Contact c3 = new Contact("Eyad", "0597","rafah");
// insert object to the book
book1.insert(c1);
book1.insert(c2);
book1.insert(c3);
// Print all the contacts’ information
book1.printData();
}
OO
OO
PP
Summary: Contact book
http://mfarra.cst.ps
3-
m
anage
objects
of contact
2- create/ contains
objects of contact
Obj
1
Obj
2
Obj
3
Obj
4
1- create object of
management class
OO
OO
PP
static class members
 A static variable represents class wide information
all objects of the class share the same piece of
data.
 The declaration of a static variable begins with the
keyword static.
http://mfarra.cst.ps
Use a static variable when all objects of a class
must use the same copy of the variable.
OO
OO
PP
Static class members
 Static variables have class scope.
 A class's public static members can be accessed
through a reference to any object of the class, or
they can be accessed by qualifying the member
name with the class name and a dot (.), as in
Math.random().
 A class's private static class members can be
accessed only through methods of the class.
http://mfarra.cst.ps
OO
OO
PP
Example: static class members
http://mfarra.cst.ps
class Contact {
private String name;
private String mobile;
private String address;
private static int counter =0;
public Contact (String name, String mobile, String address){
this.name = name;
this.mobile = mobile;
this.address = address;
counter++;
}
//….
}
The value of this variable
will be incremented by
each creation of new
object.
When we declare the variable as static, all objects will
read the same value.
OO
OO
PP
Summary: static class members
http://mfarra.cst.ps
static int x;static int x;
class Test
obj1obj1
X = 0X = 1
obj2obj2
X = 2
obj3obj3
X = 3
Now:
Print Obj1.XPrint Obj1.X
3
Print Obj1.XPrint Obj1.X
3
Print Obj1.XPrint Obj1.X
3
Every time, all objects have the same
value of static variable
Every time, all objects have the same
value of static variable
OO
OO
PP
‫ربكم‬ ‫استغفروا‬
:‫ذكره‬ ‫تعالى‬ ‫ا‬ ‫قال‬
}‫ن‬ّ ‫إ‬ ‫ه‬َ ‫ل‬ّ ‫ال‬ ‫روا‬ُ ‫ف‬ِ ‫غ‬ْ ‫ت‬َ ‫س‬ْ ‫وا‬َ
‫فورا‬ُ ‫غ‬َ ‫ن‬َ ‫كا‬ ‫ه‬َ ‫ل‬ّ ‫ال‬
{‫حيما‬ِ ‫ر‬َ
: ]‫النساء‬106[
http://mfarra.cst.ps
OO
OO
PP
QUESTIONS?QUESTIONS?
http://mfarra.cst.ps
Thank You …Thank You …

More Related Content

What's hot (20)

Data members and member functions
Data members and member functionsData members and member functions
Data members and member functions
 
C++ classes
C++ classesC++ classes
C++ classes
 
Object and class
Object and classObject and class
Object and class
 
Class or Object
Class or ObjectClass or Object
Class or Object
 
Structures in c++
Structures in c++Structures in c++
Structures in c++
 
Data members and member functions
Data members and member functionsData members and member functions
Data members and member functions
 
Structure in c sharp
Structure in c sharpStructure in c sharp
Structure in c sharp
 
Lect 1-class and object
Lect 1-class and objectLect 1-class and object
Lect 1-class and object
 
Core Java
Core JavaCore Java
Core Java
 
C# program structure
C# program structureC# program structure
C# program structure
 
Static Data Members and Member Functions
Static Data Members and Member FunctionsStatic Data Members and Member Functions
Static Data Members and Member Functions
 
Lecture 4.2 c++(comlete reference book)
Lecture 4.2 c++(comlete reference book)Lecture 4.2 c++(comlete reference book)
Lecture 4.2 c++(comlete reference book)
 
Introduction to c ++ part -2
Introduction to c ++   part -2Introduction to c ++   part -2
Introduction to c ++ part -2
 
Pi j3.2 polymorphism
Pi j3.2 polymorphismPi j3.2 polymorphism
Pi j3.2 polymorphism
 
Class and object in C++
Class and object in C++Class and object in C++
Class and object in C++
 
Constructor in java
Constructor in javaConstructor in java
Constructor in java
 
ITFT-Classes and object in java
ITFT-Classes and object in javaITFT-Classes and object in java
ITFT-Classes and object in java
 
Class and Objects in Java
Class and Objects in JavaClass and Objects in Java
Class and Objects in Java
 
Java Concepts
Java ConceptsJava Concepts
Java Concepts
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 

Viewers also liked

15 نصيحة للطالب الجامعي الجديد
15 نصيحة للطالب الجامعي الجديد15 نصيحة للطالب الجامعي الجديد
15 نصيحة للطالب الجامعي الجديدMahmoud Alfarra
 
graph based cluster labeling using GHSOM
graph based cluster labeling using GHSOMgraph based cluster labeling using GHSOM
graph based cluster labeling using GHSOMMahmoud Alfarra
 
ثلاث خطوات عملية للطالب الجامعي قبل الامتحان
ثلاث خطوات عملية للطالب الجامعي قبل الامتحانثلاث خطوات عملية للطالب الجامعي قبل الامتحان
ثلاث خطوات عملية للطالب الجامعي قبل الامتحانMahmoud Alfarra
 
البرمجة الهدفية بلغة جافا - مقدمة
البرمجة الهدفية بلغة جافا - مقدمةالبرمجة الهدفية بلغة جافا - مقدمة
البرمجة الهدفية بلغة جافا - مقدمةMahmoud Alfarra
 
Object Oriented Programming in Java _lecture 1
Object Oriented Programming in Java _lecture 1Object Oriented Programming in Java _lecture 1
Object Oriented Programming in Java _lecture 1Mahmoud Alfarra
 
Document clustering and classification
Document clustering and classification Document clustering and classification
Document clustering and classification Mahmoud Alfarra
 

Viewers also liked (7)

15 نصيحة للطالب الجامعي الجديد
15 نصيحة للطالب الجامعي الجديد15 نصيحة للطالب الجامعي الجديد
15 نصيحة للطالب الجامعي الجديد
 
graph based cluster labeling using GHSOM
graph based cluster labeling using GHSOMgraph based cluster labeling using GHSOM
graph based cluster labeling using GHSOM
 
ثلاث خطوات عملية للطالب الجامعي قبل الامتحان
ثلاث خطوات عملية للطالب الجامعي قبل الامتحانثلاث خطوات عملية للطالب الجامعي قبل الامتحان
ثلاث خطوات عملية للطالب الجامعي قبل الامتحان
 
البرمجة الهدفية بلغة جافا - مقدمة
البرمجة الهدفية بلغة جافا - مقدمةالبرمجة الهدفية بلغة جافا - مقدمة
البرمجة الهدفية بلغة جافا - مقدمة
 
Object Oriented Programming in Java _lecture 1
Object Oriented Programming in Java _lecture 1Object Oriented Programming in Java _lecture 1
Object Oriented Programming in Java _lecture 1
 
Graphs data Structure
Graphs data StructureGraphs data Structure
Graphs data Structure
 
Document clustering and classification
Document clustering and classification Document clustering and classification
Document clustering and classification
 

Similar to البرمجة الهدفية بلغة جافا - مصفوفة الكائنات

Similar to البرمجة الهدفية بلغة جافا - مصفوفة الكائنات (20)

3 functions and class
3   functions and class3   functions and class
3 functions and class
 
Intake 38 5 1
Intake 38 5 1Intake 38 5 1
Intake 38 5 1
 
Object oriented programming using c++
Object oriented programming using c++Object oriented programming using c++
Object oriented programming using c++
 
Lecture 8 Library classes
Lecture 8 Library classesLecture 8 Library classes
Lecture 8 Library classes
 
Unit 4 qba
Unit 4 qbaUnit 4 qba
Unit 4 qba
 
C++ Notes
C++ NotesC++ Notes
C++ Notes
 
JAVA CONCEPTS
JAVA CONCEPTS JAVA CONCEPTS
JAVA CONCEPTS
 
My c++
My c++My c++
My c++
 
Introduction to objects and inputoutput
Introduction to objects and inputoutput Introduction to objects and inputoutput
Introduction to objects and inputoutput
 
TEMPLATES in C++
TEMPLATES in C++TEMPLATES in C++
TEMPLATES in C++
 
Ccourse 140618093931-phpapp02
Ccourse 140618093931-phpapp02Ccourse 140618093931-phpapp02
Ccourse 140618093931-phpapp02
 
C++ Programming Course
C++ Programming CourseC++ Programming Course
C++ Programming Course
 
CS215 Lec 1 introduction
CS215 Lec 1   introductionCS215 Lec 1   introduction
CS215 Lec 1 introduction
 
Classes & objects new
Classes & objects newClasses & objects new
Classes & objects new
 
Visula C# Programming Lecture 6
Visula C# Programming Lecture 6Visula C# Programming Lecture 6
Visula C# Programming Lecture 6
 
Java: Objects and Object References
Java: Objects and Object ReferencesJava: Objects and Object References
Java: Objects and Object References
 
Lecture 04
Lecture 04Lecture 04
Lecture 04
 
Module IV_updated(old).pdf
Module IV_updated(old).pdfModule IV_updated(old).pdf
Module IV_updated(old).pdf
 
Unit vi(dsc++)
Unit vi(dsc++)Unit vi(dsc++)
Unit vi(dsc++)
 
Java class
Java classJava class
Java class
 

More from Mahmoud Alfarra

Computer Programming, Loops using Java - part 2
Computer Programming, Loops using Java - part 2Computer Programming, Loops using Java - part 2
Computer Programming, Loops using Java - part 2Mahmoud Alfarra
 
Computer Programming, Loops using Java
Computer Programming, Loops using JavaComputer Programming, Loops using Java
Computer Programming, Loops using JavaMahmoud Alfarra
 
Chapter 10: hashing data structure
Chapter 10:  hashing data structureChapter 10:  hashing data structure
Chapter 10: hashing data structureMahmoud Alfarra
 
Chapter9 graph data structure
Chapter9  graph data structureChapter9  graph data structure
Chapter9 graph data structureMahmoud Alfarra
 
Chapter 8: tree data structure
Chapter 8:  tree data structureChapter 8:  tree data structure
Chapter 8: tree data structureMahmoud Alfarra
 
Chapter 7: Queue data structure
Chapter 7:  Queue data structureChapter 7:  Queue data structure
Chapter 7: Queue data structureMahmoud Alfarra
 
Chapter 6: stack data structure
Chapter 6:  stack data structureChapter 6:  stack data structure
Chapter 6: stack data structureMahmoud Alfarra
 
Chapter 5: linked list data structure
Chapter 5: linked list data structureChapter 5: linked list data structure
Chapter 5: linked list data structureMahmoud Alfarra
 
Chapter 4: basic search algorithms data structure
Chapter 4: basic search algorithms data structureChapter 4: basic search algorithms data structure
Chapter 4: basic search algorithms data structureMahmoud Alfarra
 
Chapter 3: basic sorting algorithms data structure
Chapter 3: basic sorting algorithms data structureChapter 3: basic sorting algorithms data structure
Chapter 3: basic sorting algorithms data structureMahmoud Alfarra
 
Chapter 2: array and array list data structure
Chapter 2: array and array list  data structureChapter 2: array and array list  data structure
Chapter 2: array and array list data structureMahmoud Alfarra
 
Chapter1 intro toprincipleofc#_datastructure_b_cs
Chapter1  intro toprincipleofc#_datastructure_b_csChapter1  intro toprincipleofc#_datastructure_b_cs
Chapter1 intro toprincipleofc#_datastructure_b_csMahmoud Alfarra
 
Chapter 0: introduction to data structure
Chapter 0: introduction to data structureChapter 0: introduction to data structure
Chapter 0: introduction to data structureMahmoud Alfarra
 
8 programming-using-java decision-making practices 20102011
8 programming-using-java decision-making practices 201020118 programming-using-java decision-making practices 20102011
8 programming-using-java decision-making practices 20102011Mahmoud Alfarra
 
7 programming-using-java decision-making220102011
7 programming-using-java decision-making2201020117 programming-using-java decision-making220102011
7 programming-using-java decision-making220102011Mahmoud Alfarra
 
6 programming-using-java decision-making20102011-
6 programming-using-java decision-making20102011-6 programming-using-java decision-making20102011-
6 programming-using-java decision-making20102011-Mahmoud Alfarra
 
5 programming-using-java intro-tooop20102011
5 programming-using-java intro-tooop201020115 programming-using-java intro-tooop20102011
5 programming-using-java intro-tooop20102011Mahmoud Alfarra
 
4 programming-using-java intro-tojava20102011
4 programming-using-java intro-tojava201020114 programming-using-java intro-tojava20102011
4 programming-using-java intro-tojava20102011Mahmoud Alfarra
 
3 programming-using-java introduction-to computer
3 programming-using-java introduction-to computer3 programming-using-java introduction-to computer
3 programming-using-java introduction-to computerMahmoud Alfarra
 

More from Mahmoud Alfarra (20)

Computer Programming, Loops using Java - part 2
Computer Programming, Loops using Java - part 2Computer Programming, Loops using Java - part 2
Computer Programming, Loops using Java - part 2
 
Computer Programming, Loops using Java
Computer Programming, Loops using JavaComputer Programming, Loops using Java
Computer Programming, Loops using Java
 
Chapter 10: hashing data structure
Chapter 10:  hashing data structureChapter 10:  hashing data structure
Chapter 10: hashing data structure
 
Chapter9 graph data structure
Chapter9  graph data structureChapter9  graph data structure
Chapter9 graph data structure
 
Chapter 8: tree data structure
Chapter 8:  tree data structureChapter 8:  tree data structure
Chapter 8: tree data structure
 
Chapter 7: Queue data structure
Chapter 7:  Queue data structureChapter 7:  Queue data structure
Chapter 7: Queue data structure
 
Chapter 6: stack data structure
Chapter 6:  stack data structureChapter 6:  stack data structure
Chapter 6: stack data structure
 
Chapter 5: linked list data structure
Chapter 5: linked list data structureChapter 5: linked list data structure
Chapter 5: linked list data structure
 
Chapter 4: basic search algorithms data structure
Chapter 4: basic search algorithms data structureChapter 4: basic search algorithms data structure
Chapter 4: basic search algorithms data structure
 
Chapter 3: basic sorting algorithms data structure
Chapter 3: basic sorting algorithms data structureChapter 3: basic sorting algorithms data structure
Chapter 3: basic sorting algorithms data structure
 
Chapter 2: array and array list data structure
Chapter 2: array and array list  data structureChapter 2: array and array list  data structure
Chapter 2: array and array list data structure
 
Chapter1 intro toprincipleofc#_datastructure_b_cs
Chapter1  intro toprincipleofc#_datastructure_b_csChapter1  intro toprincipleofc#_datastructure_b_cs
Chapter1 intro toprincipleofc#_datastructure_b_cs
 
Chapter 0: introduction to data structure
Chapter 0: introduction to data structureChapter 0: introduction to data structure
Chapter 0: introduction to data structure
 
3 classification
3  classification3  classification
3 classification
 
8 programming-using-java decision-making practices 20102011
8 programming-using-java decision-making practices 201020118 programming-using-java decision-making practices 20102011
8 programming-using-java decision-making practices 20102011
 
7 programming-using-java decision-making220102011
7 programming-using-java decision-making2201020117 programming-using-java decision-making220102011
7 programming-using-java decision-making220102011
 
6 programming-using-java decision-making20102011-
6 programming-using-java decision-making20102011-6 programming-using-java decision-making20102011-
6 programming-using-java decision-making20102011-
 
5 programming-using-java intro-tooop20102011
5 programming-using-java intro-tooop201020115 programming-using-java intro-tooop20102011
5 programming-using-java intro-tooop20102011
 
4 programming-using-java intro-tojava20102011
4 programming-using-java intro-tojava201020114 programming-using-java intro-tojava20102011
4 programming-using-java intro-tojava20102011
 
3 programming-using-java introduction-to computer
3 programming-using-java introduction-to computer3 programming-using-java introduction-to computer
3 programming-using-java introduction-to computer
 

Recently uploaded

Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfadityarao40181
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxJiesonDelaCerna
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...jaredbarbolino94
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerunnathinaik
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupJonathanParaisoCruz
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitolTechU
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 

Recently uploaded (20)

Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdf
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptx
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developer
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized Group
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptx
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 

البرمجة الهدفية بلغة جافا - مصفوفة الكائنات

  • 1. O O P Array of objects Object Oriented Programming Prepared & Presented by: Mahmoud Rafeek Alfarra 2012 Chapter 2
  • 2. OO OO PP http://mfarra.cst.ps Contents Class: User defined type1 Array of type (class)2 Example: Contact book3 static Class Members4
  • 3. OO OO PP Class: User defined type As the defined class is a new data type, we can defined any variables or arrays of it. http://mfarra.cst.ps
  • 4. OO OO PP Array of objects of class http://mfarra.cst.ps int sal; int id; String name; … Employee class e1 e2 e3 e4 e5 e6 e7 e8 Employee [] x ; In this case, each item in the array will be used by using its properties and methods.
  • 5. OO OO PP Example: Contact book 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 ; From type of contact Manages the book http://mfarra.cst.ps
  • 7. OO OO PP Contact class http://mfarra.cst.ps class Contact { private String name; private String mobile; private String address; public Contact (String name, String mobile, String address){ this.name = name; this.mobile = mobile; this.address = address; } // Set methods of all properties public void setName(String name){ this.name = name; } public void setMobile(String mobile){ … } public void setAddress(String Address){ … } // Get methods of all properties public String getMobile(){ return mobile; } public String getAddress() { … } public String getName(){ … } public void printData(){ System.out.println("Name: "+name+"n Mobile:" +mobile+" n Address: "+address); } }
  • 8. OO OO PP ManagArray class http://mfarra.cst.ps class ManagArray { private Contact [] contBook; // Declaration of array of contact class private int count; public ManagArray(int size){ count = 0; contBook = new Contact[size]; // initialize the size of array(# of contacts) } public void insert(Contact c){ contBook[count] = c; // insert statement count++; System.out.println("congratulation, a new address is inserted"); } public void printData(){ if (count ==0) System.out.println("Sorry, the contact book is empty"); else { for(int i=0; i< count; i++) { System.out.println("================"); contBook[i].printData(); // Print the data of object i } System.out.println("Print Data is done!!");} } // rest of methods }
  • 9. OO OO PP Main class http://mfarra.cst.ps public static void main(String[] args) { ManagArray book1 = new ManagArray(5); // Create objects of contact Contact c1 = new Contact("Ali", "0599","Khan"); Contact c2 = new Contact("Ola", "0598","gaza"); Contact c3 = new Contact("Eyad", "0597","rafah"); // insert object to the book book1.insert(c1); book1.insert(c2); book1.insert(c3); // Print all the contacts’ information book1.printData(); }
  • 10. OO OO PP Summary: Contact book http://mfarra.cst.ps 3- m anage objects of contact 2- create/ contains objects of contact Obj 1 Obj 2 Obj 3 Obj 4 1- create object of management class
  • 11. OO OO PP static class members  A static variable represents class wide information all objects of the class share the same piece of data.  The declaration of a static variable begins with the keyword static. http://mfarra.cst.ps Use a static variable when all objects of a class must use the same copy of the variable.
  • 12. OO OO PP Static class members  Static variables have class scope.  A class's public static members can be accessed through a reference to any object of the class, or they can be accessed by qualifying the member name with the class name and a dot (.), as in Math.random().  A class's private static class members can be accessed only through methods of the class. http://mfarra.cst.ps
  • 13. OO OO PP Example: static class members http://mfarra.cst.ps class Contact { private String name; private String mobile; private String address; private static int counter =0; public Contact (String name, String mobile, String address){ this.name = name; this.mobile = mobile; this.address = address; counter++; } //…. } The value of this variable will be incremented by each creation of new object. When we declare the variable as static, all objects will read the same value.
  • 14. OO OO PP Summary: static class members http://mfarra.cst.ps static int x;static int x; class Test obj1obj1 X = 0X = 1 obj2obj2 X = 2 obj3obj3 X = 3 Now: Print Obj1.XPrint Obj1.X 3 Print Obj1.XPrint Obj1.X 3 Print Obj1.XPrint Obj1.X 3 Every time, all objects have the same value of static variable Every time, all objects have the same value of static variable
  • 15. OO OO PP ‫ربكم‬ ‫استغفروا‬ :‫ذكره‬ ‫تعالى‬ ‫ا‬ ‫قال‬ }‫ن‬ّ ‫إ‬ ‫ه‬َ ‫ل‬ّ ‫ال‬ ‫روا‬ُ ‫ف‬ِ ‫غ‬ْ ‫ت‬َ ‫س‬ْ ‫وا‬َ ‫فورا‬ُ ‫غ‬َ ‫ن‬َ ‫كا‬ ‫ه‬َ ‫ل‬ّ ‫ال‬ {‫حيما‬ِ ‫ر‬َ : ]‫النساء‬106[ http://mfarra.cst.ps