Using Java
MINISTRY OF EDUCATION & HIGHER EDUCATION
COLLEGE OF SCIENCE AND TECHNOLOGY
KHANYOUNIS- PALESTINE
Lecture 6
Introduction to classes and objects
 What is Object-Oriented Programming ?
 What classes, objects, methods ?
 How to declare a class ?
 How to use class to create an object?
 How to declare methods in a class ?
 Emank X Mezank
2Presented & Prepared by: Mahmoud R. Alfarra
 It is a whole new way of thinking about
programming!
 It is a way of modeling software that maps
your code to the real world.
 Now please, Look in this room …
3Presented & Prepared by: Mahmoud R. Alfarra
What is Object-Oriented Programming ?
Chair
Door
Man
Window
.
.
No. of legs
Material
Color
Size
Purpose
.
.
Abstraction
Encapsulation
4Presented & Prepared by: Mahmoud R. Alfarra
What is Object-Oriented Programming ?
Any Thing
Attributes
Behavior
Each one represented
by variable in class
Each one represented
by method in class
 The terms class and object are often
confused, and it is important to understand
the distinction.
 It may help you to visualize these terms using
the earlier racecar analogy.
 Think of a class as the template for the car, or
perhaps the plans used to build the car.
 The car itself is an instance of those plans, so
it could be referred to as an object.
5Presented & Prepared by: Mahmoud R. Alfarra
What are classes, objects ?
6Presented & Prepared by: Mahmoud R. Alfarra
Classes, Objects ?
Student
Student 120090234
Student 120090236
Student 120090238
Student 120090400
car
Car-AB-201
Car-AB-323
Car-BM-291
Objectsclasses
 The behavior of the class will be represented
as a method in class.
 The method can be declared as:
7Presented & Prepared by: Mahmoud R. Alfarra
What are methods ?
Access_modifiers return_type method_name (arguments)
{
// instructions
return value;
}
8Presented & Prepared by: Mahmoud R. Alfarra
What are methods ? (Example)
Public void add (int x, int y)
{
int sum = x + y;
}
Public int even (int x)
{
if (x%2 ==0)
return x;
else
{JOptionPane.showMessageDialog(null, "The value is not even ");
Return -1; }
}
9Presented & Prepared by: Mahmoud R. Alfarra
How to declare Class?
Access_modifiers class class_name{
//variables declaration
// constructor
// methods
}
Public class Car{
public String model;
public String ID;
public int price;
public Car (){
model = “Cevic”;
ID = “20023456”;
price= 12,000;
// methods
}
10Presented & Prepared by: Mahmoud R. Alfarra
How to use class to create an object?
class_name obj_name = new constructor_name ();
Car c1 = new Car ();
Car c2 = new Car ();
Car c2 = new Car ();
c2.model = “Honda”;
c2.ID = “987435”;
c2.price = 4000;
‫تعاىل‬ ‫هللا‬ ‫قال‬:
(‫املنفوش‬ ‫كالعهن‬‫اجلبال‬ ‫تكون‬ ‫يوم‬)
11Presented & Prepared by: Mahmoud R. Alfarra
Equality and
Relational
Operators 12Presented & Prepared by: Mahmoud R. Alfarra

More Related Content

PPTX
Object oriented programing
PPTX
inheritance in C++
PPT
polymorphism
PDF
Code Craft - A game-based approach for teaching introductory programming
PPTX
Multiple inheritance in c++
PPTX
C# programming : Chapter One
Object oriented programing
inheritance in C++
polymorphism
Code Craft - A game-based approach for teaching introductory programming
Multiple inheritance in c++
C# programming : Chapter One

Similar to 5 programming-using-java intro-tooop20102011 (20)

PPT
java
PPT
Java is an Object-Oriented Language
PPTX
Oops concept in Java
PPT
Md02 - Getting Started part-2
PDF
Lecture2.pdf
PPTX
Object Oriented Programming Tutorial.pptx
PDF
01 Introduction to OOP codinggggggggggggggggggggggggggggggggg
DOCX
javaopps concepts
PDF
CS8392-OOPS-Printed-Notes-All-Units.pdf for students
PPTX
Object Oriended Programming with Java
PDF
O6u CS-315A OOP Lecture (1).pdf
PPT
Object-oriented concepts
PPTX
Nitish Chaulagai Java1.pptx
PPT
Unidad o informatica en ingles
PPT
10slide.ppt
PPTX
Android Training (Java Review)
PPTX
Ch-2ppt.pptx
PDF
Classes and Object Concept Object Oriented Programming in Java
PDF
A350103
PDF
Core Java Introduction | Basics
java
Java is an Object-Oriented Language
Oops concept in Java
Md02 - Getting Started part-2
Lecture2.pdf
Object Oriented Programming Tutorial.pptx
01 Introduction to OOP codinggggggggggggggggggggggggggggggggg
javaopps concepts
CS8392-OOPS-Printed-Notes-All-Units.pdf for students
Object Oriended Programming with Java
O6u CS-315A OOP Lecture (1).pdf
Object-oriented concepts
Nitish Chaulagai Java1.pptx
Unidad o informatica en ingles
10slide.ppt
Android Training (Java Review)
Ch-2ppt.pptx
Classes and Object Concept Object Oriented Programming in Java
A350103
Core Java Introduction | Basics
Ad

More from Mahmoud Alfarra (20)

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

Recently uploaded (20)

PDF
Hazard Identification & Risk Assessment .pdf
PDF
Uderstanding digital marketing and marketing stratergie for engaging the digi...
PDF
LIFE & LIVING TRILOGY- PART (1) WHO ARE WE.pdf
PPTX
ELIAS-SEZIURE AND EPilepsy semmioan session.pptx
PDF
semiconductor packaging in vlsi design fab
PDF
LEARNERS WITH ADDITIONAL NEEDS ProfEd Topic
PPTX
Virtual and Augmented Reality in Current Scenario
PDF
Mucosal Drug Delivery system_NDDS_BPHARMACY__SEM VII_PCI.pdf
PDF
Journal of Dental Science - UDMY (2021).pdf
PDF
BP 704 T. NOVEL DRUG DELIVERY SYSTEMS (UNIT 2).pdf
PDF
BP 704 T. NOVEL DRUG DELIVERY SYSTEMS (UNIT 1)
PPTX
Introduction to pro and eukaryotes and differences.pptx
PDF
HVAC Specification 2024 according to central public works department
PPTX
A powerpoint presentation on the Revised K-10 Science Shaping Paper
PDF
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
PDF
BP 505 T. PHARMACEUTICAL JURISPRUDENCE (UNIT 1).pdf
PDF
MBA _Common_ 2nd year Syllabus _2021-22_.pdf
PDF
Complications of Minimal Access-Surgery.pdf
PDF
Τίμαιος είναι φιλοσοφικός διάλογος του Πλάτωνα
PPTX
Unit 4 Computer Architecture Multicore Processor.pptx
Hazard Identification & Risk Assessment .pdf
Uderstanding digital marketing and marketing stratergie for engaging the digi...
LIFE & LIVING TRILOGY- PART (1) WHO ARE WE.pdf
ELIAS-SEZIURE AND EPilepsy semmioan session.pptx
semiconductor packaging in vlsi design fab
LEARNERS WITH ADDITIONAL NEEDS ProfEd Topic
Virtual and Augmented Reality in Current Scenario
Mucosal Drug Delivery system_NDDS_BPHARMACY__SEM VII_PCI.pdf
Journal of Dental Science - UDMY (2021).pdf
BP 704 T. NOVEL DRUG DELIVERY SYSTEMS (UNIT 2).pdf
BP 704 T. NOVEL DRUG DELIVERY SYSTEMS (UNIT 1)
Introduction to pro and eukaryotes and differences.pptx
HVAC Specification 2024 according to central public works department
A powerpoint presentation on the Revised K-10 Science Shaping Paper
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
BP 505 T. PHARMACEUTICAL JURISPRUDENCE (UNIT 1).pdf
MBA _Common_ 2nd year Syllabus _2021-22_.pdf
Complications of Minimal Access-Surgery.pdf
Τίμαιος είναι φιλοσοφικός διάλογος του Πλάτωνα
Unit 4 Computer Architecture Multicore Processor.pptx

5 programming-using-java intro-tooop20102011

  • 1. Using Java MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE Lecture 6 Introduction to classes and objects
  • 2.  What is Object-Oriented Programming ?  What classes, objects, methods ?  How to declare a class ?  How to use class to create an object?  How to declare methods in a class ?  Emank X Mezank 2Presented & Prepared by: Mahmoud R. Alfarra
  • 3.  It is a whole new way of thinking about programming!  It is a way of modeling software that maps your code to the real world.  Now please, Look in this room … 3Presented & Prepared by: Mahmoud R. Alfarra What is Object-Oriented Programming ? Chair Door Man Window . . No. of legs Material Color Size Purpose . . Abstraction Encapsulation
  • 4. 4Presented & Prepared by: Mahmoud R. Alfarra What is Object-Oriented Programming ? Any Thing Attributes Behavior Each one represented by variable in class Each one represented by method in class
  • 5.  The terms class and object are often confused, and it is important to understand the distinction.  It may help you to visualize these terms using the earlier racecar analogy.  Think of a class as the template for the car, or perhaps the plans used to build the car.  The car itself is an instance of those plans, so it could be referred to as an object. 5Presented & Prepared by: Mahmoud R. Alfarra What are classes, objects ?
  • 6. 6Presented & Prepared by: Mahmoud R. Alfarra Classes, Objects ? Student Student 120090234 Student 120090236 Student 120090238 Student 120090400 car Car-AB-201 Car-AB-323 Car-BM-291 Objectsclasses
  • 7.  The behavior of the class will be represented as a method in class.  The method can be declared as: 7Presented & Prepared by: Mahmoud R. Alfarra What are methods ? Access_modifiers return_type method_name (arguments) { // instructions return value; }
  • 8. 8Presented & Prepared by: Mahmoud R. Alfarra What are methods ? (Example) Public void add (int x, int y) { int sum = x + y; } Public int even (int x) { if (x%2 ==0) return x; else {JOptionPane.showMessageDialog(null, "The value is not even "); Return -1; } }
  • 9. 9Presented & Prepared by: Mahmoud R. Alfarra How to declare Class? Access_modifiers class class_name{ //variables declaration // constructor // methods } Public class Car{ public String model; public String ID; public int price; public Car (){ model = “Cevic”; ID = “20023456”; price= 12,000; // methods }
  • 10. 10Presented & Prepared by: Mahmoud R. Alfarra How to use class to create an object? class_name obj_name = new constructor_name (); Car c1 = new Car (); Car c2 = new Car (); Car c2 = new Car (); c2.model = “Honda”; c2.ID = “987435”; c2.price = 4000;
  • 11. ‫تعاىل‬ ‫هللا‬ ‫قال‬: (‫املنفوش‬ ‫كالعهن‬‫اجلبال‬ ‫تكون‬ ‫يوم‬) 11Presented & Prepared by: Mahmoud R. Alfarra
  • 12. Equality and Relational Operators 12Presented & Prepared by: Mahmoud R. Alfarra