|
|
- Peter Dalton
- 5 years ago
- Views:
Transcription
1
2 Object-Oriented Programming concepts Object-oriented programming ( תכנות מונחה עצמים ) involves programming using objects An object ) (עצם represents an entity in the real world that can be distinctly identified For example: a student, a desk, a circle, a button can all be viewed as objects An object has a unique identity ( זהות ייחודית ), state, and behaviors The state ( מצב )of an object consists of a set of data fields (also known as properties) with their current values The behavior ( התנהגות )of an object is defined by a set of methods
3 Objects - example Object properties Object behavior 3
4 Objects - examples Robot properties? Robot behavior? Student properties? Student behavior? lecturer properties? lecturer behavior? 4
5 ) זהות ייחודית ( identity An object has : - unique ) מצב ( state - ) התנהגות ( behaviors - state(attributes) consists of a set of data fields (properties) with their current values behavior(operations) of an object is defined by a set of methods data field 1 data field m method 1 State (Properties) radius = 5 findarea() Data field, State Properties Method, Behavior Behavior method n (A) A generic object (B) An example of circle object 5
6 Classes - definitions In the real world, you'll often find many individual objects all of the same kind There may be thousands of other bicycles in existence, all of the same make and model Each bicycle was built from the same set of prototype components and (אבטיפוס therefore contains the same ( In object-oriented terms, we say that your bicycle is an instance ( מופע )of the class of (מחלקה) objects known as bicycles A class is the prototype from which individual objects are created 6
7 Classes ( מחלקות ) examples: People,books,dogs,cats,cars,airplanes,trains,etc ) מופע של מחלקה) Instance of a class You, your parents, the book you are reading, the car you drive Example: Car class : Property names model year Color Classes - examples Method Names startengine stopengine accelerate 7
8 Instance of a class Class Name: Student A class template Data Fields: name is Methods: takecourse Student Object 1 Data Fields: Student Object 2 Data Fields: Student Object 3 Data Fields: name is Kerem David name is Onur Ronit name is Meltem Vered Three objects of the Student class Instances of the class Student A class is used to define an object The state (consists of a set of data fields) defines the object, and the behavior defines what the object does 8
9 Instance of a class - example 9
10 Instances of a class Point - example Class Point ( 0, 0) (2, 3) (-3, 1) (-15, -25) 4 instances of Point class 10
11 Java Classes Classes ( (מחלקות are constructs that define objects of the same type (Building plan /prototype of similar objects) A Java class uses variables ( (משתנים to define data fields and methods ( (פעולות to define behaviors public class Point private double x; private double y; Class variables ( properties ) public void move(double dx, double dy) } public void printpoint() } // rest methods Class methods 11
12 Access Specifiers ) הכמסה ( encapsulation One of the techniques in OOP is It concerns the hiding of data in a class and making this class available only through methods Java allows you to control access to classes, methods, and variables via ) הרשאות גישה ( specifiers access public ( גישה פומבית ) classes, methods, and variables can be accessed from everywhere The private ( גישה פרטית ) keyword denotes that the variable (or method) is hidden from view of any other class public class Point private double x; // x cannot be accessed by any class except class Point private double y; // y cannot be accessed by any class except class Point 12
13 Objects - creating A variable can hold a primitive value or a reference to an object ( הפניה ) A variable that serves as an object reference must be declared A class is used to define an object, and the class name can be thought of as the type of an object To create an object we use the new operator and the act ) יצירת אובייקט) of creating an object is called instantiation For example : Point p1 = new Point(); Name Type Memory Address p1 Point 3000 p1 x = 00 y = 00 default values An object reference variable stores the memory address of an object
14 Java Constructors A class provides a special type of methods, known as constructors, which are invoked to construct objects from the class Constructor ( פעולה בונה ) is a special kind of methods that are invoked to perform initializing actions - instantiation For example : Point p2 = new Point(35,2,4); Name Type Memory Address p2 Point 2000 p2 x = 35 y = 24 Constructors must have the same name as the class itself 14
15 Constructors - example public class Point private double x; private double y; public Point(double x, double y) } public void printpoint() } // rest methods Constructors must have the same name as the class itself Constructors do not have a return type not even void 15
16 Constructors implementation public class Point private double x; private double y; Class variables (data fields) public Point(double x, double y) thisx = x; thisy = y; } // Point The this keyword is required is when a method argument or a local variable in a method has the same name as one of the data fields of the class 16
17 Constructor without parameters Point p3 = new Point( ); public Point( ) thisx = 75; thisy = 154; } // Point Choice 1 Choice 2 public Point( ) } // Point Name Type Memory Address p3 Point 1500 p3 x = 75 y = 154 p3 x = 00 y = 00 17
18 Default Constructor A class may be declared without constructors In this case, a default constructor with an empty body is implicitly declared in the class This constructor, called a,( פעולה בונה ברירת מחדל ( constructor default is provided automatically from Java compiler only if no constructors are explicitly declared in the class The default constructor initializes all instance variables to default value ( zero for numeric types, false for booleans) 18
19 Accessing the variables of an object Accessing a class variable through the class by specifying the name of the class, followed by a dot operator, followed by the name of the variable For example: Point p1 = new Point(); Point p2 = new Point(); p1x = 25; If access specifiers of x and y class variables are p1y = - 39; public,class variables can be initialized by an assignment statement p2x = 10; p2y = p1y; Systemoutprintln( p1= + p1x +, + p1y ); This would produce following result: p1 = 25,-39
20 Accessing the methods of an object public class Circle public double x, y; // The coordinates public double r; // The radius of circle // Methods that print the circumference and // return the area of the circle public void circumference() Systemoutprintln( 2 * 314 *this r); } public double area() return 314 * thisr * thisr; } } // Circle Circle c = new Circle( ); cx = 20; cy = 20; cr = 10; double a = carea( ); ccircumference( ); file testcirclejava This is why it is called Object-Oriented" Programming( OOP); the object is the focus here, not the method call To access the methods of an object, we use the same syntax as accessing the data of an object We use an object reference to invoke an object's method file Circlejava 20
21 Differences between Variables of Primitive Data Types and Object Types Primitive type int i = 1 i 1 Created using new Circle() Object type Circle c c reference c: Circle radius = 1 Reference variables are created using defined constructors of the classes They are used to access objects These variables are declared to be of a specific type that cannot be changed Class objects, and various type of array variables come under reference data type Default value of any reference variable is null: a reference that does not currently point to an object 21
22 Referenced Data Fields The data fields can be of reference types For example: the following Student class contains a data field name of the String type, a data field grades contains a data of the integer array type public class Student private String name; // name has default value null private int age; // age has default value 0 private boolean ismemberstudcomunity; // default value false private int [ ] grades; // student s grades array has default value null private char gender; // c has default value '\u0000 Class Student methods } // class Student 22
23 Copying Variables of Primitive Data Types and Object Types Primitive type assignment i = j Before: i 1 After: i 2 Objects in Java are referred using reference types, and there is no direct way to copy the contents of an object into a new object j 2 j 2 The assignment of one reference to another merely creates another reference to the same object c1 c2 Before: Object type assignment c1 = c2 After: c1 c2 c1: Circle radius = 5 C2: Circle radius = 9 c1: Circle radius = 5 C2: Circle radius = 9 23
24 Garbage collection As shown in the previous slide, after the assignment statement c1 = c2, c1 points to the same object referenced by c2 The object previously referenced by c1 is no longer referenced This object is known as garbage When the last reference to an object is lost, the object becomes a candidate for garbage collection ) אספן זבל ( collector Java performs automatic garbage by periodically reclaiming the memory space occupied by these object 24
25 Objects As Parameters file Pointjava file testpointsjava public class Point private double x; private double y; public boolean isegual(point m) return (mx == thisx && my == thisy) } public void printpoint( ) Systemoutprintln( x= + thisx+ y= + thisy); } // rest class Point methods public static void main(string[ ] args) Point p1=new Point(20,30); Point p2=new Point(20,30); p1printpoint( ); p2printpoint( ); if (p1isequal(p2)) Systemoutprintln( YES ); else Systemoutprintln( NO ); } // main This program generates the following output: x=20 y= 30 x=20 y=30 YES 25
26 Copy Constructor We can define multiple constructors in the class, with each one having a different argument list : constructor without parameter list, constructor with parameter list and copy constructor ( פעולה בונה מעתיקה ) with reference type parameter public class Point ( ) private double x; private double y; } public Point(double x, double y) thisx = x; thisy = y; } public Point( ) thisx = 50; thisy = 30; } (העמסה ( overloading In Java method means creating more than a single method with same name with different parameters In class Point three methods are created with the same name public Point( Point p) thisx = px; thisy = py; } // rest class Point methods Copy constructor 26
27 Copy Constructor - example public static void main(string[ ] args) Point p1=new Point(20,30); Point p2=new Point(p1); p1printpoint( ); p2printpoint( ); } // main This program generates the following output: x = 20 y = 30 x = 20 y = 30 p1 p2 p1 x y p2 x y Two different instances of the Point object
28 tostring method The Java tostring() method is used when we need a string representation of an object This method is defined in Object class public class Point private double x; private double y; // constructor methods public String tostring( ) String str = ( x= + thisx+ y= + thisy); return str; } public static void main(string[ ] args) Point p1 = new Point(20,30); Point p2 = new Point(40,50); String s = p1tostring ( ); Systemoutprintln(s); // Systemoutprintln(p1toString()); Systemoutprintln(p2); } // main // rest class Point methods This program generates the following output: x = 20 y = 30 x = 40 y = 50 28
29 Getter/Setter methods Getter and setter methods are used to retrieve and manipulate private variables in a different class The difference between getter and setter methods is obvious: a getter method gets the value, a setter method sets the value The reason to use is because of the principle of information hiding ( הסתרת מידע ) - classes should not reveal their innards to the outside world This is the most important feature of the Object-Oriented Programming
30 getter/setter methods - example public class Point private double x; private double y; // class Point constructor methods public double getx( ) return thisx; } public double gety( ) return thisy; } public void setx(double x) thisx = x; } public void sety(double y) thisy = y; } // rest class Point methods public static void main(string[ ] args) Point p1 = new Point(20,30); Systemoutprintln(p1toString()); Systemoutprint( Enter the x value ); double newx = readernextdouble(); p1setx(newx); Systemoutprint( Enter the y value ); double newy = readernextdouble(); p1sety(newy); Systemoutprintln(p1toString()); } // main This program generates the following output: x = 20 y = 30 Enter the x value 40 Enter the y value 50 x = 40 y = 50 30
31 Class Rational In mathematics, a rational number is any number that can be expressed as the quotient or fraction a/b of two integers, with the denominator b not equal to zero The basic arithmetic operations for rational number are addition, subtraction, multiplication, and division Class Rational represents one rational number with a numerator and denominator So, a rational number looks like this: numerator In Rational Class we examine the following basic operations: - Equality - Multiplication - Division denominator 31
32 Class public class Rational private int x; // numerator private int y; // denominator public Rational (int x, int y) thisx = x; thisy = y; } // Rational class constructor public int getnumerator() return thisx; } // getnumerator public int getdenom() return thisy; // getdenomirator public void setnumerator( int x) thisx = x; // setnumerator public void setdenom( int y) thisy = y; // setdenominator Rational Constructor Getter methods Setter methods 32
33 Class public String tostring() return thisx + "/" + thisy; // tostring Rational tostring method public boolean isequal(rational num) return ( (thisx * numy) == (numx * thisy) ); // isequal public Rational multiply(rational num) return new Rational (thisx * numx, thisy * numy); // multiply public Rational divide(rational num) if (numy == 0) return null; return new Rational(thisx * numy, thisy * numx)); // divide These methods return new Rational class variables 33
34 Class TestRational public class TestRational public static void main(string[ ] args) Rational r1 = new Rational (2,3); Rational r2 = new Rational (4,6); Systemoutprintln("r1: + r1); Systemoutprintln("r2: + r2); Systemoutprintln("r1, r2 equal? + r1isequal(r2)); Rational r3 = r1multiply(r2); Systemoutprintln("r3 = r1*r2: + r3); Rational r4 = r1divide(r2); Systemoutprintln("r4 = r1/r2: + r4); // main // class TestRational This program generates the following output: r1: 2/3 r2: 4/6 r1, r2 equal? true r3 = r1*r2: 8/18 r4 = r1/r2: 12/12 34
35 Class variables - definition When a number of objects are created from the same class definition, they each have their own distinct copies of ) תכונות מופע ( variables instance For example : Each Point object has its own values for x and y coordinates variables, stored in different memory locations Sometimes, we want to have variables that are common to all objects This is accomplished with the static modifier Fields that have the static modifier in their declaration are (תכונות מחלקה) called static fields or class variables Any object can change the value of a class variable 35
36 Class variables - implementation public class PointCounter private double x; private double y; private static int numpoints = 0; public PointCounter(double x, double y) thisx = x; thisy = y; PointCounternumPoints++; } // constructor public static int getnumberofpoints() return PointCounternumPoints; } // getnumberofpoints Rest class PointCounter methods Coordinates - not static, thus not shared among instances of PointCounter Keeps track of the number of Point objects created Since it is static, all Point objects share this variable Increment class variable numpoints to tell anyone that we have another instance of this class } // class PointCounter 36
37 Class variables - implementation, cont This method returns the new middle point of this point and a given as parameter point p of PointCounter class public PointCounter middle(pointcounter p) double middlex = (thisx + pgetx()) / 2; double middley = (thisy + pgety()) / 2; return new PointCounter(middleX, middley); } // middle This method calculates the distance between this point and a given as parameter point p of PointCounter class public double distance(pointcounter p) } return (Mathsqrt((Mathpow((thisx - pgetx()), 2) + Mathpow((thisy - pgety()),2)))); } // distance 37
38 Class variables - creation Every instance of the class PointCounter shares a class variable, which is in one fixed location in memory x p1 y p numpoints 3 x p2 y p public static void main(string[ ] args) PointCounter p1 = new PointCounter(20,30); PointCounter p2 = new PointCounter(40,50); PointCounter p3 = new PointCounter(60,70); } // main p3 x y p3 38
39 Class TestPointCounter public class TestPointCounter public static void main(string[ ] args) } PointCounter point1 = new PointCounter(9,9); PointCounter point2 = new PointCounter(5,5); double dis = point1distance(point2); Systemoutprintln("The distance between the points is :" + dis); PointCounter point3 = point1middle(point2); Systemoutprintln("The middle point is : " + point3); Systemoutprintln("Number of points is : " + PointCountergetNumberOfPoints()); } // main } // TestPointCounter This program generates the following output: The distance between the points is : 565 The middle point is : (70,70) Number of points is : 3 39
40 Constants The static modifier, in combination with the final modifier, is also used to define constants The final modifier indicates that the value of this field cannot change For example: the following variable declaration defines a constant named PI static final double PI = ; Constants defined in this way cannot be reassigned By convention, the names of constant values are spelled in uppercase letters 40
41 Class (static) methods - definition The Java programming language supports class (static) methods as well as static variables Static methods, which have the static modifier in their declarations, should be invoked with the class name, without the need for creating an instance of the class A common use for static methods is to access static fields For example: we could add a static method to the PointCounter class to access the numpoints static field :
42 Class (static) methods example 1 public class PointCounter private double x; private double y; private static int numpoints = 0; // constructors public static int getnumpoints( ) return PointCounternumPoints; } // rest class PointCounter methods } // class PointCounter public static void main(string[ ] args) Systemoutprintln("Num of points : + PointCountergetNumPoints()); PointCounter p1 = new PointCounter(20,30); Systemoutprintln("Num of points : + PointCountergetNumPoints()); PointCounter p2 = new PointCounter(30,40); Systemoutprintln("Num of points : + PointCountergetNumPoints()); } // main This program generates the following output: Num of points : 0 Num of points : 1 Num of points : 2 NOTE : class method can be invoked with the class name, without the need for creating an instance of the class 42
43 Class (static) methods example 2 public class TestPointCounter public static int PointsNumber() return PointCountergetNumPoints(); } // PointsNumber public static void main(string[ ] args) Systemoutprintln("Num of points is: + PointsNumber()); PointCounter p1= new PointCounter(20,30); Systemoutprintln("Num of points is: + PointsNumber()); PointCounter p2 = new PointCounter(30,40); Systemoutprintln("Num of points is: + PointsNumber()); } // main } // class TestPoint This program generates the following output: External (static) method Main method Num of points is: 0 Num of points is: 1 Num of points is: 2 43
Object-Oriented Programming Concepts
Object-Oriented Programming Concepts Object-oriented programming מונחה עצמים) (תכנות involves programming using objects An object ) represents (עצם an entity in the real world that can be distinctly identified
More informationClasses. Classes. Classes. Class Circle with methods. Class Circle with fields. Classes and Objects in Java. Introduce to classes and objects in Java.
Classes Introduce to classes and objects in Java. Classes and Objects in Java Understand how some of the OO concepts learnt so far are supported in Java. Understand important features in Java classes.
More informationExample: Fibonacci Numbers
Example: Fibonacci Numbers Write a program which determines F n, the (n + 1)-th Fibonacci number. The first 10 Fibonacci numbers are 0, 1, 1, 2, 3, 5, 8, 13, 21, and 34. The sequence of Fibonacci numbers
More informationObjects and Classes. 1 Creating Classes and Objects. CSCI-UA 101 Objects and Classes
Based on Introduction to Java Programming, Y. Daniel Liang, Brief Version, 10/E 1 Creating Classes and Objects Classes give us a way of defining custom data types and associating data with operations on
More informationRecursion 1. Recursion is the process of defining something in terms of itself.
Recursion 1 Recursion is the process of defining something in terms of itself. A method that calls itself is said to be recursive. Recursion is an alternative form of program control. It is repetition
More informationObject Oriented Modeling
Object Oriented Modeling Object oriented modeling is a method that models the characteristics of real or abstract objects from application domain using classes and objects. Objects Software objects are
More informationJava Programming. U Hou Lok. Java Aug., Department of Computer Science and Information Engineering, National Taiwan University
Java Programming U Hou Lok Department of Computer Science and Information Engineering, National Taiwan University Java 272 8 19 Aug., 2016 U Hou Lok Java Programming 1 / 51 A Math Toolbox: Math Class The
More informationObject Oriented Programming. Week 1 Part 3 Writing Java with Eclipse and JUnit
Object Oriented Programming Part 3 Writing Java with Eclipse and JUnit Today's Lecture Test Driven Development Review (TDD) Building up a class using TDD Adding a Class using Test Driven Development in
More information- Aggregation - UML diagram - Self-Referential Classes - Generisity
- Aggregation - UML diagram - Self-Referential Classes - Generisity 1 Class Circle public class Circle private double xcenter; // x center coordinate private double ycenter; // y center coordinate private
More informationCHAPTER 7 OBJECTS AND CLASSES
CHAPTER 7 OBJECTS AND CLASSES OBJECTIVES After completing Objects and Classes, you will be able to: Explain the use of classes in Java for representing structured data. Distinguish between objects and
More informationJava How to Program, 10/e. Copyright by Pearson Education, Inc. All Rights Reserved.
Java How to Program, 10/e Education, Inc. All Rights Reserved. Each class you create becomes a new type that can be used to declare variables and create objects. You can declare new classes as needed;
More informationLecture 12: Classes II
Lecture 12: Classes II Building Java Programs: A Back to Basics Approach by Stuart Reges and Marty Stepp Copyright (c) Pearson 2013. All rights reserved. Encapsulation Encapsulation encapsulation: Hiding
More informationLecture 7: Classes and Objects CS2301
Lecture 7: Classes and Objects NADA ALZAHRANI CS2301 1 What is OOP? Object-oriented programming (OOP) involves programming using objects. An object represents an entity in the real world that can be distinctly
More information( &% class MyClass { }
Recall! $! "" # ' ' )' %&! ( &% class MyClass { $ Individual things that differentiate one object from another Determine the appearance, state or qualities of objects Represents any variables needed for
More informationCSEN401 Computer Programming Lab. Topics: Introduction and Motivation Recap: Objects and Classes
CSEN401 Computer Programming Lab Topics: Introduction and Motivation Recap: Objects and Classes Prof. Dr. Slim Abdennadher 16.2.2014 c S. Abdennadher 1 Course Structure Lectures Presentation of topics
More informationLecture 11: Intro to Classes
Lecture 11: Intro to Classes Building Java Programs: A Back to Basics Approach by Stuart Reges and Marty Stepp Copyright (c) Pearson 2013. All rights reserved. Classes and objects class: A program entity
More informationBBM 102 Introduction to Programming II Spring 2017
BBM 102 Introduction to Programming II Spring 2017 Classes and Objects in Java Instructors: Ayça Tarhan, Fuat Akal, Gönenç Ercan, Vahid Garousi TAs: Selma Dilek, Selim Yılmaz, Selman Bozkır 1 Today Defining
More informationCHAPTER 7 OBJECTS AND CLASSES
CHAPTER 7 OBJECTS AND CLASSES OBJECTIVES After completing Objects and Classes, you will be able to: Explain the use of classes in Java for representing structured data. Distinguish between objects and
More informationClasses and Objects. EECS2030 B: Advanced Object Oriented Programming Fall 2018 CHEN-WEI WANG
Classes and Objects EECS2030 B: Advanced Object Oriented Programming Fall 2018 CHEN-WEI WANG Separation of Concerns: App/Tester vs. Model In EECS1022: Model Component: One or More Java Classes e.g., Person
More informationChapter 6 Introduction to Defining Classes
Introduction to Defining Classes Fundamentals of Java: AP Computer Science Essentials, 4th Edition 1 Objectives Design and implement a simple class from user requirements. Organize a program in terms of
More informationThe return Statement
The return Statement The return statement is the end point of the method. A callee is a method invoked by a caller. The callee returns to the caller if the callee completes all the statements (w/o a return
More informationECOM 2324 COMPUTER PROGRAMMING II
ECOM 2324 COMPUTER PROGRAMMING II Object Oriented Programming with JAVA Instructor: Ruba A. Salamh Islamic University of Gaza 2 CHAPTER 9 OBJECTS AND CLASSES Motivations 3 After learning the preceding
More informationCS 251 Intermediate Programming Methods and Classes
CS 251 Intermediate Programming Methods and Classes Brooke Chenoweth University of New Mexico Fall 2018 Methods An operation that can be performed on an object Has return type and parameters Method with
More informationCS 251 Intermediate Programming Methods and More
CS 251 Intermediate Programming Methods and More Brooke Chenoweth University of New Mexico Spring 2018 Methods An operation that can be performed on an object Has return type and parameters Method with
More informationITI Introduction to Computing II
ITI 1121. Introduction to Computing II Marcel Turcotte School of Electrical Engineering and Computer Science Inheritance Introduction Generalization/specialization Version of January 20, 2014 Abstract
More informationSelected Questions from by Nageshwara Rao
Selected Questions from http://way2java.com by Nageshwara Rao Swaminathan J Amrita University swaminathanj@am.amrita.edu November 24, 2016 Swaminathan J (Amrita University) way2java.com (Nageshwara Rao)
More informationIslamic University of Gaza Faculty of Engineering Computer Engineering Department
Student Mark Islamic University of Gaza Faculty of Engineering Computer Engineering Department Question # 1 / 18 Question # / 1 Total ( 0 ) Student Information ID Name Answer keys Sector A B C D E A B
More informationZheng-Liang Lu Java Programming 45 / 79
1 class Lecture2 { 2 3 "Elementray Programming" 4 5 } 6 7 / References 8 [1] Ch. 2 in YDL 9 [2] Ch. 2 and 3 in Sharan 10 [3] Ch. 2 in HS 11 / Zheng-Liang Lu Java Programming 45 / 79 Example Given a radius
More informationUFCE3T-15-M Object-oriented Design and Programming
UFCE3T-15-M Object-oriented Design and Programming Block1: Objects and Classes Jin Sa 27-Sep-05 UFCE3T-15-M Programming part 1 Objectives To understand objects and classes and use classes to model objects.
More informationCmSc 150 Fundamentals of Computing I. Lesson 28: Introduction to Classes and Objects in Java. 1. Classes and Objects
CmSc 150 Fundamentals of Computing I Lesson 28: Introduction to Classes and Objects in Java 1. Classes and Objects True object-oriented programming is based on defining classes that represent objects with
More informationBuilding Java Programs
Building Java Programs Chapter 8 Lecture 18: Classes and Objects reading: 8.1-8.2 (Slides adapted from Stuart Reges, Hélène Martin, and Marty Stepp) 2 File output reading: 6.4-6.5 3 Output to files PrintStream:
More informationJava Programming. MSc Induction Tutorials Stefan Stafrace PhD Student Department of Computing
Java Programming MSc Induction Tutorials 2011 Stefan Stafrace PhD Student Department of Computing s.stafrace@surrey.ac.uk 1 Tutorial Objectives This is an example based tutorial for students who want to
More informationITI Introduction to Computing II
ITI 1121. Introduction to Computing II Marcel Turcotte School of Electrical Engineering and Computer Science Inheritance Introduction Generalization/specialization Version of January 21, 2013 Abstract
More informationAP Computer Science Chapter 10 Implementing and Using Classes Study Guide
AP Computer Science Chapter 10 Implementing and Using Classes Study Guide 1. A class that uses a given class X is called a client of X. 2. Private features of a class can be directly accessed only within
More informationAn introduction to Java II
An introduction to Java II Bruce Eckel, Thinking in Java, 4th edition, PrenticeHall, New Jersey, cf. http://mindview.net/books/tij4 jvo@ualg.pt José Valente de Oliveira 4-1 Java: Generalities A little
More informationObject Oriented Programming in C#
Introduction to Object Oriented Programming in C# Class and Object 1 You will be able to: Objectives 1. Write a simple class definition in C#. 2. Control access to the methods and data in a class. 3. Create
More informationChapter 11: Creating Classes
Chapter 11: Creating Classes Objectives Students should Recall the meaning of classes and objects in Java Know the components in the definition of a Java class Understand how constructors work Be able
More informationObject Oriented Programming
Object Oriented Programming Objectives To review the concepts and terminology of object-oriented programming To discuss some features of objectoriented design 1-2 Review: Objects In Java and other Object-Oriented
More informationInstance Members and Static Members
Instance Members and Static Members You may notice that all the members are declared w/o static. These members belong to some specific object. They are called instance members. This implies that these
More informationDay 3. COMP 1006/1406A Summer M. Jason Hinek Carleton University
Day 3 COMP 1006/1406A Summer 2016 M. Jason Hinek Carleton University today s agenda assignments 1 was due before class 2 is posted (be sure to read early!) a quick look back testing test cases for arrays
More informationIntroduction to Programming Using Java (98-388)
Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;
More informationCOMP 250: Java Programming I. Carlos G. Oliver, Jérôme Waldispühl January 17-18, 2018 Slides adapted from M. Blanchette
COMP 250: Java Programming I Carlos G. Oliver, Jérôme Waldispühl January 17-18, 2018 Slides adapted from M. Blanchette Variables and types [Downey Ch 2] Variable: temporary storage location in memory.
More informationOO Programming Concepts. Classes. Objects. Chapter 8 User-Defined Classes and ADTs
Chapter 8 User-Defined Classes and ADTs Objectives To understand objects and classes and use classes to model objects To learn how to declare a class and how to create an object of a class To understand
More informationIntroduction to OOP with Java. Instructor: AbuKhleif, Mohammad Noor Sep 2017
Introduction to OOP with Java Instructor: AbuKhleif, Mohammad Noor Sep 2017 Lecture 07: OOP Part 1 Instructor: AbuKhleif, Mohammad Noor Sep 2017 Instructor AbuKhleif, Mohammad Noor Computer Engineer (JU
More informationImportant Java terminology
1 Important Java terminology The information we manage in a Java program is either represented as primitive data or as objects. Primitive data פרימיטיביים) (נתונים include common, fundamental values as
More informationChapter 9 Objects and Classes. Liang, Introduction to C++ Programming, (c) 2007 Pearson Education, Inc. All rights reserved.
Chapter 9 Objects and Classes 1 Objectives Classes & Objects ( 9.2). UML ( 9.2). Constructors ( 9.3). How to declare a class & create an object ( 9.4). Separate a class declaration from a class implementation
More informationProgramming in the Large II: Objects and Classes (Part 1)
Programming in the Large II: Objects and Classes (Part 1) 188230 Advanced Computer Programming Asst. Prof. Dr. Kanda Runapongsa Saikaew (krunapon@kku.ac.th) Department of Computer Engineering Khon Kaen
More information12/22/11. Java How to Program, 9/e. public must be stored in a file that has the same name as the class and ends with the.java file-name extension.
Java How to Program, 9/e Education, Inc. All Rights Reserved. } Covered in this chapter Classes Objects Methods Parameters double primitive type } Create a new class (GradeBook) } Use it to create an object.
More informationOperations. I Forgot 9/4/2016 COMPUTER SCIENCE DEPARTMENT PICNIC. If you forgot your IClicker, or your batteries fail during the exam
COMPUTER SCIENCE DEPARTMENT PICNIC Welcome to the 2016-2017 Academic year! Meet your faculty, department staff, and fellow students in a social setting. Food and drink will be provided. When: Saturday,
More informationComputer Science II (20082) Week 1: Review and Inheritance
Computer Science II 4003-232-08 (20082) Week 1: Review and Inheritance Richard Zanibbi Rochester Institute of Technology Review of CS-I Syntax and Semantics of Formal (e.g. Programming) Languages Syntax
More informationComments are almost like C++
UMBC CMSC 331 Java Comments are almost like C++ The javadoc program generates HTML API documentation from the javadoc style comments in your code. /* This kind of comment can span multiple lines */ //
More informationObject-Oriented Programming Concepts
Object-Oriented Programming Concepts Real world objects include things like your car, TV etc. These objects share two characteristics: they all have state and they all have behavior. Software objects are
More informationinside: THE MAGAZINE OF USENIX & SAGE August 2003 volume 28 number 4 PROGRAMMING McCluskey: Working with C# Classes
THE MAGAZINE OF USENIX & SAGE August 2003 volume 28 number 4 inside: PROGRAMMING McCluskey: Working with C# Classes & The Advanced Computing Systems Association & The System Administrators Guild working
More informationChapter 8 Objects and Classes Dr. Essam Halim Date: Page 1
Assignment (1) Chapter 8 Objects and Classes Dr. Essam Halim Date: 18-3-2014 Page 1 Section 8.2 Defining Classes for Objects 1 represents an entity in the real world that can be distinctly identified.
More informationEncapsulation. Administrative Stuff. September 12, Writing Classes. Quick review of last lecture. Classes. Classes and Objects
Administrative Stuff September 12, 2007 HW3 is due on Friday No new HW will be out this week Next Tuesday we will have Midterm 1: Sep 18 @ 6:30 7:45pm. Location: Curtiss Hall 127 (classroom) On Monday
More informationJava Classes & Primitive Types
Java Classes & Primitive Types Rui Moreira Classes Ponto (from figgeom) x : int = 0 y : int = 0 n Attributes q Characteristics/properties of classes q Primitive types (e.g., char, byte, int, float, etc.)
More informationJava Classes & Primitive Types
Java Classes & Primitive Types Rui Moreira Classes Ponto (from figgeom) x : int = 0 y : int = 0 n Attributes q Characteristics/properties of classes q Primitive types (e.g., char, byte, int, float, etc.)
More informationCS111: PROGRAMMING LANGUAGE II. Lecture 1: Introduction to classes
CS111: PROGRAMMING LANGUAGE II Lecture 1: Introduction to classes Lecture Contents 2 What is a class? Encapsulation Class basics: Data Methods Objects Defining and using a class In Java 3 Java is an object-oriented
More informationObject Oriented Programming is a programming method that combines: Advantage of Object Oriented Programming
Overview of OOP Object Oriented Programming is a programming method that combines: a) Data b) Instructions for processing that data into a self-sufficient object that can be used within a program or in
More informationPIC 10A. Lecture 15: User Defined Classes
PIC 10A Lecture 15: User Defined Classes Intro to classes We have already had some practice with classes. Employee Time Point Line Recall that a class is like a souped up variable that can store data,
More informationChapter 4: Writing Classes
Chapter 4: Writing Classes Java Software Solutions Foundations of Program Design Sixth Edition by Lewis & Loftus Writing Classes We've been using predefined classes. Now we will learn to write our own
More informationThe Java language has a wide variety of modifiers, including the following:
PART 5 5. Modifier Types The Java language has a wide variety of modifiers, including the following: Java Access Modifiers Non Access Modifiers 5.1 Access Control Modifiers Java provides a number of access
More informationLecture 18 Tao Wang 1
Lecture 18 Tao Wang 1 Abstract Data Types in C++ (Classes) A procedural program consists of one or more algorithms that have been written in computerreadable language Input and display of program output
More informationCOE318 Lecture Notes Week 4 (Sept 26, 2011)
COE318 Software Systems Lecture Notes: Week 4 1 of 11 COE318 Lecture Notes Week 4 (Sept 26, 2011) Topics Announcements Data types (cont.) Pass by value Arrays The + operator Strings Stack and Heap details
More informationMethod Invocation. Zheng-Liang Lu Java Programming 189 / 226
Method Invocation Note that the input parameters are sort of variables declared within the method as placeholders. When calling the method, one needs to provide arguments, which must match the parameters
More information2. The object-oriented paradigm!
2. The object-oriented paradigm! Plan for this section:! n Look at things we have to be able to do with a programming language! n Look at Java and how it is done there" Note: I will make a lot of use of
More informationESc101 : Fundamental of Computing. Object Oriented programming
ESc101 : Fundamental of Computing I Semester 2008-09 Lecture 21 Object Oriented programming class and object (recap from previous lecture) Object : reference, creation Object : accessing attributes and
More informationLecture 06: Classes and Objects
Accelerating Information Technology Innovation http://aiti.mit.edu Lecture 06: Classes and Objects AITI Nigeria Summer 2012 University of Lagos. What do we know so far? Primitives: int, float, double,
More informationProgramming II (CS300)
1 Programming II (CS300) Chapter 02: Using Objects MOUNA KACEM mouna@cs.wisc.edu Fall 2018 Using Objects 2 Introduction to Object Oriented Programming Paradigm Objects and References Memory Management
More informationLecture 3. Lecture
True Object-Oriented programming: Dynamic Objects Static Object-Oriented Programming Reference Variables Eckel: 30-31, 41-46, 107-111, 114-115 Riley: 5.1, 5.2 D0010E Object-Oriented Programming and Design
More informationBM214E Object Oriented Programming Lecture 8
BM214E Object Oriented Programming Lecture 8 Instance vs. Class Declarations Instance vs. Class Declarations Don t be fooled. Just because a variable might be declared as a field within a class that does
More informationChapter 4 Defining Classes I
Chapter 4 Defining Classes I This chapter introduces the idea that students can create their own classes and therefore their own objects. Introduced is the idea of methods and instance variables as the
More informationComputer Programming, I. Laboratory Manual. Experiment #2. Elementary Programming
Think Twice Code Once The Islamic University of Gaza Engineering Faculty Department of Computer Engineering Fall 2017 ECOM 2005 Khaleel I. Shaheen Computer Programming, I Laboratory Manual Experiment #2
More informationFull file at
Java Programming: From Problem Analysis to Program Design, 3 rd Edition 2-1 Chapter 2 Basic Elements of Java At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class
More informationCS1004: Intro to CS in Java, Spring 2005
CS1004: Intro to CS in Java, Spring 2005 Lecture #13: Java OO cont d. Janak J Parekh janak@cs.columbia.edu Administrivia Homework due next week Problem #2 revisited Constructors, revisited Remember: a
More informationChapter 9 Objects and Classes. OO Programming Concepts. Classes. Objects. Motivations. Objectives. CS1: Java Programming Colorado State University
Chapter 9 Objects and Classes CS1: Java Programming Colorado State University Motivations After learning the preceding chapters, you are capable of solving many programming problems using selections, loops,
More informationProgramming with Java
Programming with Java Data Types & Input Statement Lecture 04 First stage Software Engineering Dep. Saman M. Omer 2017-2018 Objectives q By the end of this lecture you should be able to : ü Know rules
More informationGraphical Interface and Application (I3305) Semester: 1 Academic Year: 2017/2018 Dr Antoun Yaacoub
Lebanese University Faculty of Science Computer Science BS Degree Graphical Interface and Application (I3305) Semester: 1 Academic Year: 2017/2018 Dr Antoun Yaacoub 2 Crash Course in JAVA Classes A Java
More informationChapter 9 Objects and Classes. Liang, Introduction to Java Programming, Eleventh Edition, (c) 2017 Pearson Education, Inc. All rights reserved.
Chapter 9 Objects and Classes 1 Motivations After learning the preceding chapters, you are capable of solving many programming problems using selections, loops, methods, and arrays. However, these Java
More informationClasses Basic Overview
Final Review!!! Classes and Objects Program Statements (Arithmetic Operations) Program Flow String In-depth java.io (Input/Output) java.util (Utilities) Exceptions Classes Basic Overview A class is a container
More informationCS 170, Section /3/2009 CS170, Section 000, Fall
Lecture 18: Objects CS 170, Section 000 3 November 2009 11/3/2009 CS170, Section 000, Fall 2009 1 Lecture Plan Homework 5 : questions, comments? Managing g g Data: objects to make your life easier ArrayList:
More informationCOMP-202 Unit 8: Defining Your Own Classes. CONTENTS: Class Definitions Attributes Methods and Constructors Access Modifiers and Encapsulation
COMP-202 Unit 8: Defining Your Own Classes CONTENTS: Class Definitions Attributes Methods and Constructors Access Modifiers and Encapsulation Defining Our Own Classes (1) So far, we have been creating
More informationBuilding Java Programs
Building Java Programs Chapter 8 Lecture 8-2: Object Behavior (Methods) and Constructors reading: 8.2-8.3 Recall: Instance methods instance method (or object method): Exists inside each object of a class
More informationCreating an object Instance variables
Introduction to Objects: Semantics and Syntax Defining i an object Creating an object Instance variables Instance methods What is OOP? Object-oriented programming (constructing software using objects)
More informationAnatomy of a Class Encapsulation Anatomy of a Method
Writing Classes Writing Classes We've been using predefined classes. Now we will learn to write our own classes to define objects Chapter 4 focuses on: class definitions instance data encapsulation and
More informationCMPT 125: Lecture 3 Data and Expressions
CMPT 125: Lecture 3 Data and Expressions Tamara Smyth, tamaras@cs.sfu.ca School of Computing Science, Simon Fraser University January 3, 2009 1 Character Strings A character string is an object in Java,
More informationComputer Science II (20073) Week 1: Review and Inheritance
Computer Science II 4003-232-01 (20073) Week 1: Review and Inheritance Richard Zanibbi Rochester Institute of Technology Review of CS-I Hardware and Software Hardware Physical devices in a computer system
More informationClasses and Objects 3/28/2017. How can multiple methods within a Java class read and write the same variable?
Peer Instruction 8 Classes and Objects How can multiple methods within a Java class read and write the same variable? A. Allow one method to reference a local variable of the other B. Declare a variable
More informationSimple Java Reference
Simple Java Reference This document provides a reference to all the Java syntax used in the Computational Methods course. 1 Compiling and running... 2 2 The main() method... 3 3 Primitive variable types...
More informationBuilding Java Programs. Chapter 2: Primitive Data and Definite Loops
Building Java Programs Chapter 2: Primitive Data and Definite Loops Copyright 2008 2006 by Pearson Education 1 Lecture outline data concepts Primitive types: int, double, char (for now) Expressions: operators,
More informationCS171:Introduction to Computer Science II
CS171:Introduction to Computer Science II Department of Mathematics and Computer Science Li Xiong 1/24/2012 1 Roadmap Lab session Pretest Postmortem Java Review Types, variables, assignments, expressions
More informationThe Basic Parts of Java
Data Types Primitive Composite The Basic Parts of Java array (will also be covered in the lecture on Collections) Lexical Rules Expressions and operators Methods Parameter list Argument parsing An example
More informationChapter 8 Objects and Classes. Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved.
Chapter 8 Objects and Classes 1 Motivations After learning the preceding chapters, you are capable of solving many programming problems using selections, loops, methods, and arrays. However, these Java
More informationChapter 3 Classes. Activity The class as a file drawer of methods. Activity Referencing static methods
Chapter 3 Classes Lesson page 3-1. Classes Activity 3-1-1 The class as a file drawer of methods Question 1. The form of a class definition is: public class {
More informationIntroduction to Visual Basic and Visual C++ Introduction to Java. JDK Editions. Overview. Lesson 13. Overview
Introduction to Visual Basic and Visual C++ Introduction to Java Lesson 13 Overview I154-1-A A @ Peter Lo 2010 1 I154-1-A A @ Peter Lo 2010 2 Overview JDK Editions Before you can write and run the simple
More informationJava Magistère BFA
Java 101 - Magistère BFA Lesson 2 Stéphane Airiau Université Paris-Dauphine Lesson 2 (Stéphane Airiau) Java 1 Object Oriented Programming in Java Lesson 2 (Stéphane Airiau) Java 2 Objects and Classes An
More informationOBJECT ORIENTED SIMULATION LANGUAGE. OOSimL Reference Manual - Part 1
OBJECT ORIENTED SIMULATION LANGUAGE OOSimL Reference Manual - Part 1 Technical Report TR-CSIS-OOPsimL-1 José M. Garrido Department of Computer Science Updated November 2014 College of Computing and Software
More informationCS170 Introduction to Computer Science Midterm 2
CS170 Introduction to Computer Science Midterm 2 03/25/2009 Name: Solution You are to honor the Emory Honor Code. This is a closed book and closednotes exam, and you are not to use any other resource than
More informationOutline. Overview. Control statements. Classes and methods. history and advantage how to: program, compile and execute 8 data types 3 types of errors
Outline Overview history and advantage how to: program, compile and execute 8 data types 3 types of errors Control statements Selection and repetition statements Classes and methods methods... 2 Oak A
More informationCSCI 1101 Winter 2017 Laboratory No Submission deadline is p.m. (5 minutes to midnight) on Saturday, February 4th, 2017.
CSCI 1101 Winter 2017 Laboratory No. 3 This lab is a continuation of the concepts of object-oriented programming, specifically the use of static variables and static methods, and object interactions. If
More information