objects CIS 421 Kutztown University

Slides:



Advertisements
Similar presentations
Object-Oriented programming in C++ Classes as units of encapsulation Information Hiding Inheritance polymorphism and dynamic dispatching Storage management.
Advertisements

Written by: Dr. JJ Shepherd
Rounding Out Classes The objectives of this chapter are: To discuss issues surrounding passing parameters to methods What is "this"? To introduce class.
Object-Oriented PHP (1)
Road Map Introduction to object oriented programming. Classes
ISBN Chapter 11 Abstract Data Types and Encapsulation Concepts.
Terms and Rules Professor Evan Korth New York University (All rights reserved)
Abstract Data Types and Encapsulation Concepts
OOP in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
C++ fundamentals.
Review of C++ Programming Part II Sheng-Fang Huang.
OOP Languages: Java vs C++
Programming Languages and Paradigms Object-Oriented Programming.
Presented by: Mojtaba Khezrian. Agenda Object Creation Object Storage More on Arrays Parameter Passing For Each VarArgs Spring 2014Sharif University of.
COP INTERMEDIATE JAVA Designing Classes. Class Template or blueprint for creating objects. Their definition includes the list of properties (fields)
Programming Languages and Paradigms Object-Oriented Programming.
Java 2 More Java Then Starbucks ;-). Important Terms Primitive Data – Basic, built-in values (characters & numbers) Data Type – Used to talk about values.
Sadegh Aliakbary. Copyright ©2014 JAVACUP.IRJAVACUP.IR All rights reserved. Redistribution of JAVACUP contents is not prohibited if JAVACUP.
Objects, Classes and Syntax Dr. Andrew Wallace PhD BEng(hons) EurIng
Peyman Dodangeh Sharif University of Technology Fall 2013.
Copyright © 2012 Accenture All Rights Reserved.Copyright © 2012 Accenture All Rights Reserved. Accenture, its logo, and High Performance Delivered are.
Sadegh Aliakbary Sharif University of Technology Spring 2011.
Chapter 6 Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view.
Copyright Curt Hill Variables What are they? Why do we need them?
Summing Up Object Oriented Design. Four Major Components: Abstraction modeling real-life entities by essential information only Encapsulation clustering.
CSE 501N Fall ‘09 04: Introduction to Objects 08 September 2009 Nick Leidenfrost.
COP INTERMEDIATE JAVA Designing Classes. Class Template or blueprint for creating objects. Their definition includes the list of properties (fields)
Classes. Constructor A constructor is a special method whose purpose is to construct and initialize objects. Constructor name must be the same as the.
ISBN Chapter 11 Abstract Data Types and Encapsulation Concepts.
Peyman Dodangeh Sharif University of Technology Spring 2014.
ISBN Chapter 11 Abstract Data Types and Encapsulation Concepts.
More about Java Classes Writing your own Java Classes More about constructors and creating objects.
Today Review passing by reference and pointers. null pointers. What is an Object? Winter 2016CMPE212 - Prof. McLeod1.
© 2004 Pearson Addison-Wesley. All rights reserved3-1 Objects Declaration: String title;  title (object variable) of type String( Class )  title is just.
Basic Class Structure. Class vs. Object class - a template for building an object –defines the instance data that the object will hold –defines instance.
Objects and Memory Mehdi Einali Advanced Programming in Java 1.
Object-Oriented Programming Using C++ Third Edition Chapter 7 Using Classes.
CSE691 Software Models and Analysis.
Java Programming: Guided Learning with Early Objects
Creating and Using Objects, Exceptions, Strings
Object-Oriented Design
Abstract Data Types and Encapsulation Concepts
Review: Two Programming Paradigms
Chapter 3: Using Methods, Classes, and Objects
11.1 The Concept of Abstraction
Chapter 4: Writing Classes
Object-Oriented Programming Using C++
Fall 2017 CISC124 9/18/2018 CISC124 First onQ quiz this week – write in lab. More details in last Wednesday’s lecture. Repeated: The quiz availability.
Advanced Programming Behnam Hatami Fall 2017.
CMPE212 – Stuff… Exercises 4, 5 and 6 are all fair game now.
Lecture 9 Concepts of Programming Languages
Abstract Data Types and Encapsulation Concepts
Dynamic Memory Allocation
Encapsulation & Visibility Modifiers
Corresponds with Chapter 7
Chapter 10 Thinking in Objects
Abstract Data Types and Encapsulation Concepts
CISC124 Quiz 1 marking nears completion!
Outline Writing Classes Copyright © 2012 Pearson Education, Inc.
Group Status Project Status.
Dr. Bhargavi Dept of CS CHRIST
CS2011 Introduction to Programming I Objects and Classes
CS100J Lecture 7 Previous Lecture This Lecture Java Constructs
Fall 2018 CISC124 2/22/2019 CISC124 Quiz 1 This Week. Topics and format of quiz in last Tuesday’s notes. The prof. (me!) will start grading the quiz.
CISC/CMPE320 - Prof. McLeod
COP 3330 Object-oriented Programming in C++
Object-Oriented Programming Using C++
Winter 2019 CMPE212 5/10/2019 CMPE212 – Reminders
Lecture 9 Concepts of Programming Languages
Presentation transcript:

objects CIS 421 Kutztown University 7/23/2018 Objects CIS 421 Kutztown University objects

What are Objects An aggregation a heterogeneous collection of data members a set of behaviors to access and manipulate the data Objects often contain objects, since all but simple types are objects (including String)

What are Objects Objects are declared in a class An object is an instantiation of the non-static members of a class Objects model real things For example an object might be an account (abstract thing), a vehicle (real thing), a purchase (transaction), or a mouse click (event)

What are Objects Real objects and model objects both have attributes and behavior A model object is an object modeled in Java The attributes are the data values or references to other objects The behaviors are the methods

What are Objects The fact that an object contains behavior and data values is called encapsulation To invoke the behavior, a message is sent to the object reference (invocation) The message must have the same spelling as the method name

Summary of What Objects Are Objects encapsulate data values and behaviors upon those data They model real objects They receive messages to invoke their behaviors

The Purpose of a Class A class in Java is a mechanism used to define an object, among other possibilities Sometimes they are called templates for objects (Java doesn’t have C++ style templates) They act as a blue print of an object When an object is instantiated (created) the template is used

The Purpose of a Class class is a reserved word In addition there is a visibility (access) modifier for each class and members (data and methods) of the class private, public, or protected

The Purpose of a Class A visibility modifier tells the system how to protect the members from the outside world (other objects) To obey the OO concept, data members should be private The class is usually public (it must be designated with an access qualifier) public methods constitute the user interface methods for internal use should be private (or protected)

Static Declarations Static declarations belong to the class Some things MUST be static main() the System class’ declarations System.exit() method System.out stream InputReader is an example of a class containing only static declarations static declarations can be accessed via the class name or via an object of the class’ type

Objects vs. Simple Types All object declarations are just a reference. The object must be instantiated Arrays are objects! Simple types allocate memory for the data by their declaration IntegerObject Example of ridiculously simplistic object

Example: Array of 10 int Two ways to declare reference int[] list; no value inside [] represents a reference to an array of int size undetermined until instantiated Instantiate: list=new int[10] array now has 10 elements

Example: Array of 10 int Wait! Not always like this... IntegerObject: Example of very simple object type IntegerObject Ilist[]= new IntegerObject[10] Array has 10 references, not objects. Must instantiate each separately Examples: MinMax

Built-in Java Objects Simple types all have object wrapper type; Integer wraps int Double wraps double Character wraps char All are immutable Must be constructed with value that can’t be changed

Built-in Java Objects (con’t) String is also immutable Note: String is special; can be constructed via assignment String S=“Hello”; S=“ABCD” S is constructed twice First, with “Hello” Then, with “ABCD” What happened to the first object S referred to (“pointed” at)?

Garbage Collection String object “Hello” was abandoned when S was reassigned Memory leak? No. Java has a built-in garbage collector All objects carry info on # of references When #references is 0, memory can be “collected” and placed back onto the heap e.g String S=“Hello” String T=S “Hello” has two references to it No destructors, or memory deallocator (e.g. C++ delete operator)