HIGHLEVEL REVIEW Chapter 9 Objects and Classes

Slides:



Advertisements
Similar presentations
L3:CSC © Dr. Basheer M. Nasef Lecture #3 By Dr. Basheer M. Nasef.
Advertisements

Liang, Introduction to Java Programming, Sixth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 7 Objects and Classes.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Chapter 8 Objects and Classes.
Road Map Introduction to object oriented programming. Classes
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 7 Objects and Classes.
Liang, Introduction to Programming with C++, Second Edition, (c) 2010 Pearson Education, Inc. All rights reserved Chapter 9 Objects and Classes.
© Copyright 2012 by Pearson Education, Inc. All Rights Reserved. 1 Chapter 7 Object-Oriented Programming.
Introduction to Java Programming, 4E Y. Daniel Liang.
Advanced Java and Android Day 1 Object-Oriented Programming in Java Advanced Java and Android -- Day 11.
Chapter 9 Objects and Classes
1 Chapter 8 Objects and Classes. 2 Motivations After learning the preceding chapters, you are capable of solving many programming problems using selections,
Syllabus (1) WeekChapters 1Introduction to the course, basic java language programming concepts: Primitive Data Types and Operations 1, 2 2Methods, Control.
DATA STRUCTURE Introduction to Systems Programming - COMP 1005, 1405 Instructor : Behnam Hajian
Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rights reserved. 1 Chapter 9 Objects and Classes.
1 Objects and Classes. 2 OO Programming Concepts Object-oriented programming (OOP) involves programming using objects. An object represents an entity.
Chapter 8. About the Midterm Exam.. Exam on March 12 Monday (Tentatively) Review on March 7 Wednesday Cover from Chapter 6 Grades will be out before spring.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Chapter 8 Objects and Classes.
Objects and Classes Chapter 6 CSCI CSCI 1302 – Objects and Classes2 Outline Introduction Defining Classes for Objects Constructing Objects Accessing.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 7 Objects and Classes.
1.  At the end of this slide, student able to:  Object-Oriented Programming  Research on OOP features.  Do a code walkthrough to examine the implementation.
Chapter 8 Objects and Classes Object Oriented programming Instructor: Dr. Essam H. Houssein.
Objects and Classes Mostafa Abdallah
COP3502 Programming Fundamentals for CIS Majors 1 Instructor: Parisa Rashidi.
Chapter 3 Introduction to Classes and Objects Definitions Examples.
Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rights reserved. 1 Chapter 9 Objects and Classes.
Liang, Introduction to Java Programming, Sixth Edition1 Objects and Classes Gang Qian Department of Computer Science University of Central Oklahoma.
1 COS240 O-O Languages AUBG, COS dept Lecture 12 Title: Java Classes and Objects Reference: COS240 Syllabus.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 7 Objects and Classes.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Objects and Classes.
Liang, Introduction to C++ Programming, (c) 2007 Pearson Education, Inc. All rights reserved X 1 Chapter 9 Objects and Classes.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 6 Objects and Classes.
1 Chapter 6 Programming with Objects and Classes F OO Programming Concepts F Creating Objects and Object Reference Variables –Differences between primitive.
CS 139 Objects Based on a lecture by Dr. Farzana Rahman Assistant Professor Department of Computer Science.
Introduction To Objects Oriented Programming Instructor: Mohammed Faisal.
1 Class and Object Lecture 7. 2 Classes Classes are constructs that define objects of the same type. A Java class uses instance variables to define data.
Chapter 7 Objects and Classes. OO Programming Concepts Object-oriented programming (OOP) involves programming using objects. An object represents an entity.
CS 112 Programming 2 Lecture 02 Objects and Classes (1)
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 7 Objects and Classes.
Object-Oriented Programming in Java. 2 CS2336: Object-Oriented Programming in Java Buzzwords interfacejavadoc encapsulation coupling cohesion polymorphic.
1 COS240 O-O Languages AUBG, COS dept Lecture 12 Title: Java Classes and Objects Reference: COS240 Syllabus.
Lecture 9: Object and Classes Michael Hsu CSULA. 2 OO Programming Concepts Object-oriented programming (OOP) involves programming using objects. An object.
Liang, Introduction to C++ Programming, (c) 2007 Pearson Education, Inc. All rights reserved X 1 Chapter 9 Introduction of Object Oriented Programming.
Lecture 3: Introduction to Object and Classes Michael Hsu CSULA.
Lecture 3: Introduction to Object and Classes Michael Hsu CSULA.
Object Oriented Programming. Constructors  Constructors are like special methods that are called implicitly as soon as an object is instantiated (i.e.
Objects and Classes. F OO Programming Concepts F Creating Objects and Object Reference Variables –Differences between primitive data type and object type.
1 Chapter 8 Objects and Classes. 2 Motivations After learning the preceding chapters, you are capable of solving many programming problems using selections,
Chapter 7 Objects and Classes
Lecture 3: Introduction to Object and Classes
Chapter 7 Object-Oriented Programming
Corresponds with Chapter 7
Chapter 10 Thinking in Objects
Outline Writing Classes Copyright © 2012 Pearson Education, Inc.
Chapter 8 Objects and Classes Part 1
Chapter 9 Objects and Classes
Chapter 9 Objects and Classes
Chapter 8 Objects and Classes
Objects and Classes Creating Objects and Object Reference Variables
Chapter 6 Objects and Classes
Chapter 6 Objects and Classes
Chapter 8 Objects and Classes
Chapter 9 Objects and Classes
Chapter 9 Objects and Classes Part 01
Chapter 7 Objects and Classes
OO Programming Concepts
Chapter 6 Objects and Classes
Chapter 9 Objects and Classes
Chapter 8 Objects and Classes Part 2
Chapter 7 Objects and Classes
Presentation transcript:

HIGHLEVEL REVIEW Chapter 9 Objects and Classes Dr. Clincy - Lecture - Ch 9 - Highlevel Review

Structured Programming Versus OO Programming Structured Programming Languages Fortran Pascal Ada C BASIC Top-Down, Subroutines, Functions, GoTo Object-Oriented Programming Languages Java Python Ruby C++ VisualBasic Classes, Objects, Methods Why OOP ? What is the point ? Dr. Clincy - Lecture - Ch 9 - Highlevel Review

OO Programming Concepts Object-oriented programming (OOP) 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, and even a loan 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. Dr. Clincy - Lecture - Ch 9 - Highlevel Review

Dr. Clincy - Lecture - Ch 9 - Highlevel Review Objects An object has both a state and behavior. The state defines the object, and the behavior defines what the object does. Dr. Clincy - Lecture - Ch 9 - Highlevel Review

Dr. Clincy - Lecture - Ch 9 - Highlevel Review Classes Classes are constructs that define objects of the same type. A Java class uses variables to define data fields and methods to define behaviors. Additionally, a class provides a special type of methods, known as constructors, which are invoked to construct objects from the class. Dr. Clincy - Lecture - Ch 9 - Highlevel Review

Dr. Clincy - Lecture - Ch 9 - Highlevel Review Classes Dr. Clincy - Lecture - Ch 9 - Highlevel Review

Dr. Clincy - Lecture - Ch 9 - Highlevel Review UML Class Diagram Dr. Clincy - Lecture - Ch 9 - Highlevel Review

Dr. Clincy - Lecture - Ch 9 - Highlevel Review Constructors A constructor with no parameters is referred to as a no-arg constructor. Constructors must have the same name as the class itself. Constructors do not have a return type—not even void. Constructors are invoked using the new operator when an object is created. Constructors play the role of initializing objects. Dr. Clincy - Lecture - Ch 9 - Highlevel Review

Dr. Clincy - Lecture - Ch 9 - Highlevel Review Default Constructor A class may be defined without constructors. In this case, a no-arg constructor with an empty body is implicitly defined in the class. This constructor, called a default constructor, is provided automatically only if no constructors are explicitly defined in the class. Dr. Clincy - Lecture - Ch 9 - Highlevel Review

Declaring/Creating Objects in a Single Step Declaring Object Reference Variables To reference an object, assign the object to a reference variable. To declare a reference variable, use the syntax: ClassName objectRefVar; Example: Circle myCircle; Declaring/Creating Objects in a Single Step ClassName objectRefVar = new ClassName(); Example: Circle myCircle = new Circle(); Assign object reference Create an object Dr. Clincy - Lecture - Ch 9 - Highlevel Review

Accessing Object’s Members Referencing the object’s data: objectRefVar.data e.g., myCircle.radius Invoking the object’s method: objectRefVar.methodName(arguments) e.g., myCircle.getArea() Dr. Clincy - Lecture - Ch 9 - Highlevel Review

Differences between Variables of Primitive Data Types and Object Types Dr. Clincy - Lecture - Ch 9 - Highlevel Review

Instance Variables, and Methods Instance variables belong to a specific instance. Instance methods are invoked by an instance of the class. Dr. Clincy - Lecture - Ch 9 - Highlevel Review

Static Variables, Constants, and Methods Static variables are shared by all the instances of the class. Static methods are not tied to a specific object. Static constants are final variables shared by all the instances of the class. To declare static variables, constants, and methods, use the static modifier. Dr. Clincy - Lecture - Ch 9 - Highlevel Review

Static Variables, Constants, and Methods, cont. Dr. Clincy - Lecture - Ch 9 - Highlevel Review

Visibility Modifiers and Accessor/Mutator Methods By default, the class, variable, or method can be accessed by any class in the same package. public The class, data, or method is visible to any class in any package. private The data or methods can be accessed only by the declaring class. The get and set methods are used to read and modify private properties. Dr. Clincy - Lecture - Ch 9 - Highlevel Review

Dr. Clincy - Lecture - Ch 9 - Highlevel Review The private modifier restricts access to within a class the public modifier enables unrestricted access. the default modifier restricts access to within a package Dr. Clincy - Lecture - Ch 9 - Highlevel Review

Example of Data Field Encapsulation Why Data Fields Should Be private? To protect data. To make code easy to maintain. Example of Data Field Encapsulation Dr. Clincy - Lecture - Ch 9 - Highlevel Review

Immutable Objects and Classes If the contents of an object cannot be changed once the object is created, the object is called an immutable object and its class is called an immutable class. If you delete the set method in the Circle class in Listing 8.10, the class would be immutable because radius is private and cannot be changed without a set method. A class with all private data fields and without mutators is not necessarily immutable. For example, the following class Student has all private data fields and no mutators, but it is mutable. For a class to be immutable, it must mark all data fields private and provide no mutator methods and no accessor methods that would return a reference to a mutable data field object. Dr. Clincy - Lecture - Ch 9 - Highlevel Review

Dr. Clincy - Lecture - Ch 9 - Highlevel Review Go Over Lab 1 Dr. Clincy - Lecture - Ch 9 - Highlevel Review