Using Java MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE Lecture 6 Introduction to classes and objects.

Slides:



Advertisements
Similar presentations
Introduction to Java Objects CSIS 3701: Advanced Object Oriented Programming.
Advertisements

DATA STRUCTURE Presented By: Mahmoud Rafeek Alfarra Using C# MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE.
Constructors & An Introduction to Methods. Defining Constructor – Car Example Public class car { String Model; double speed; String colour; { Public Car.
Function Overloading Having more than one function with the same name. list of argument of a function are called signature of a function. We can have more.
Introduction to Programming with Java, for Beginners Intro OOP with Java Java Program Structure.
ECE122 Feb Introduction to Class and Object Java is an object-oriented language. Java’s view of the world is a collection of objects and their.
Objects and Classes First Programming Concepts. 14/10/2004Lecture 1a: Introduction 2 Fundamental Concepts object class method parameter data type.
1 Objects and Classes Introduction to Classes Object Variables and Object References Instantiating Objects Using Methods in Objects Reading for this Lecture:
1. 2 Introduction to Classes  Motivation  Class Components  Instance Variables  Constructors  The Student Class  Exercises.
C# Programming: From Problem Analysis to Program Design1 Creating Your Own Classes C# Programming: From Problem Analysis to Program Design 3rd Edition.
CS 106 Introduction to Computer Science I 03 / 21 / 2008 Instructor: Michael Eckmann.
Evan Korth New York University Computer Science I Classes and Objects Professor: Evan Korth New York University.
Class template Describing a generic class Instantiating classes that are type- specific version of this generic class Also are called parameterized types.
Using Java MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE.
Computer Programming 2 Lecture 2: Advanced Array Data Structure Using Methods Prepared & Presented by: Mahmoud Rafeek Alfarra MINISTRY OF EDUCATION & HIGHER.
CSM-Java Programming-I Spring,2005 Introduction to Objects and Classes Lesson - 1.
BIT 1003 – Presentation 7. Contents GENERATIONS OF LANGUAGES COMPILERS AND INTERPRETERS VIRTUAL MACHINES OBJECT-ORIENTED PROGRAMMING SCRIPTING LANGUAGES.
Computer Programming 2 Lecture 3: Methods in Advanced & Practices Prepared & Presented by: Mahmoud Rafeek Alfarra MINISTRY OF EDUCATION & HIGHER EDUCATION.
CS 106 Introduction to Computer Science I 03 / 19 / 2007 Instructor: Michael Eckmann.
Using Java MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE Lecture 7 Decision Making : selection statements.
DATA STRUCTURE Presented By: Mahmoud Rafeek Alfarra Using C# MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE.
Computer Programming 2 Lecture 1: Advanced Array Data Structure Using Methods Prepared & Presented by: Mahmoud Rafeek Alfarra MINISTRY OF EDUCATION & HIGHER.
Computer Programming 2 Lecture 5: String Processing Part b: Class StringTokenizer Prepared & Presented by: Mahmoud Rafeek Alfarra MINISTRY OF EDUCATION.
Using Java MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE.
1 Chapter 8 – Classes and Object: A Deeper Look Outline 1 Introduction 2 Implementing a Time Abstract Data Type with a Class 3 Class Scope 4 Controlling.
Introduction To Programming Information Technology , 1’st Semester
Using Java MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE Lecture 9 & 10 Repetition Statements.
DATA STRUCTURE Presented By: Mahmoud Rafeek Alfarra Using C# MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE.
CS 106 Introduction to Computer Science I 10 / 29 / 2007 Instructor: Michael Eckmann.
Objects and Classes Mostafa Abdallah
PHY281 Scientific Java Programming ObjectsSlide 1 Classes & Objects In this section we will learn about Classes and Objects in Java :  What are Objects?
Chapter 3 Introduction to Classes and Objects Definitions Examples.
Liang, Introduction to Java Programming, Sixth Edition1 Objects and Classes Gang Qian Department of Computer Science University of Central Oklahoma.
Using Java MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE Lecture 15,16 Java’s Methods.
CSci 162 Lecture 10 Martin van Bommel. Procedures vs Objects Procedural Programming –Centered on the procedures or actions that take place in a program.
DATA STRUCTURE Presented By: Mahmoud Rafeek Alfarra Using C# MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE.
DATA STRUCTURE Presented By: Mahmoud Rafeek Alfarra Using C# MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE.
Mahmoud Rafeek Alfarra Computer Programming || Chapter 1: Introduction & OOP.
Using Java MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE.
Computer Programming 2 Lecture 9: Object Oriented Programming Array Of Objects Prepared & Presented by: Mahmoud Rafeek Alfarra MINISTRY OF EDUCATION &
Computer Programming 2 Lecture 8: Object Oriented Programming Creating Classes & Objects Prepared & Presented by: Mahmoud Rafeek Alfarra MINISTRY OF EDUCATION.
DATA STRUCTURE Presented By: Mahmoud Rafeek Alfarra Using C# MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE.
DATA STRUCTURE Presented By: Mahmoud Rafeek Alfarra Using C# MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE.
DATA STRUCTURE Presented By: Mahmoud Rafeek Alfarra Using C# MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE.
YG - CS Concept of Encapsulation What is encapsulation? - data and functions/methods are packaged together in the class normally.
DATA STRUCTURE Presented By: Mahmoud Rafeek Alfarra Using C# MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE.
Using Java MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE Lecture 18 Recursion & Pointers in Java.
Int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } 5 void main () { Int Sum; : Sum = fact (5); : } Factorial Program Using Recursion.
Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 6-1 Learning Objectives  Classes  Constructors  Principles of OOP  Class type member.
 By the end of this lecture, you should …  Understand the three pillars of Object- Oriented Programming: Inheritance, Encapsulation and Polymorphism.
CS 116 Object Oriented Programming II Acknowledgement: Contains materials provided by George Koutsogiannakis and Matt Bauer.
DATA STRUCTURE Presented By: Mahmoud Rafeek Alfarra Using C# MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE.
Basic Class Structure. Class vs. Object class - a template for building an object –defines the instance data that the object will hold –defines instance.
Introduction to java (class and object). Programming languages: –Easier to understand than CPU instructions –Needs to be translated for the CPU to understand.
Presented By: Mahmoud Rafeek Alfarra
Presented By: Mahmoud Rafeek Alfarra
Introduction To Programming Information Technology , 1’st Semester
OBJECT ORIENTED PROGRAMMING II LECTURE 8 GEORGE KOUTSOGIANNAKIS
Part a: Fundamentals & Class String
Variables and Their scope
Presented By: Mahmoud Rafeek Alfarra
Introduction To Programming Information Technology , 1’st Semester
Implementing Classes Chapter 3.
Introduction To Programming Information Technology , 1’st Semester
Presented By: Mahmoud Rafeek Alfarra
Class Everything if Java is in a class. The class has a constructor that creates the object. public class ClassName private Field data (instance variables)
Presented By: Mahmoud Rafeek Alfarra
Introduction to Objects & Classes
Introduction To Programming Information Technology , 1’st Semester
Presented By: Mahmoud Rafeek Alfarra
Presentation transcript:

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 2 Presented & 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 … 3 Presented & Prepared by: Mahmoud R. Alfarra What is Object-Oriented Programming ? Chair Door Man Window. No. of legs Material Color Size Purpose. Abstraction Encapsulation

4 Presented & 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. 5 Presented & Prepared by: Mahmoud R. Alfarra What are classes, objects ?

6 Presented & Prepared by: Mahmoud R. Alfarra Classes, Objects ? Student Student Student Student Student car Car-AB-201 Car-AB-323 Car-BM-291 Objects classes

 The behavior of the class will be represented as a method in class.  The method can be declared as: 7 Presented & Prepared by: Mahmoud R. Alfarra What are methods ? Access_modifiers return_type method_name (arguments) { // instructions return value; }

8 Presented & 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 Presented & Prepared by: Mahmoud R. Alfarra How to declare Class? Access_modifiers class class_name{ //variables declaration // constructor // methods } 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 = “ ”; price= 12,000; // methods } Public class Car{ public String model; public String ID; public int price; public Car (){ model = “Cevic”; ID = “ ”; price= 12,000; // methods }

10 Presented & 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 (); c2.model = “Honda”; c2.ID = “987435”; c2.price = 4000; Car c2 = new Car (); c2.model = “Honda”; c2.ID = “987435”; c2.price = 4000;

قال الله تعالى‏:‏ ‏ (‏يوم تكون الجبال كالعهن المنفوش) 11 Presented & Prepared by: Mahmoud R. Alfarra

Equality and Relational Operators 12 Presented & Prepared by: Mahmoud R. Alfarra