Class object initialization block destructor Class object

Similar documents
CSCI 253. Outline. Background. George Blankenship 1

Fundamentals of Programming Session 12

Lesson 10A OOP Fundamentals. By John B. Owen All rights reserved 2011, revised 2014

Objects and Classes -- Introduction

Introduction to Programming Using Java (98-388)

Chapter 4: Writing Classes

And Even More and More C++ Fundamentals of Computer Science

Data Structures using OOP C++ Lecture 3

Object-Oriented Concepts and Principles (Adapted from Dr. Osman Balci)

Anatomy of a Class Encapsulation Anatomy of a Method

CmSc 150 Fundamentals of Computing I. Lesson 28: Introduction to Classes and Objects in Java. 1. Classes and Objects

CMSC 132: Object-Oriented Programming II

Programs as Models. Procedural Paradigm. Class Methods. CS256 Computer Science I Kevin Sahr, PhD. Lecture 11: Objects

CS1004: Intro to CS in Java, Spring 2005

COMSC-051 Java Programming Part 1. Part-Time Instructor: Joenil Mistal

Announcement. Agenda 7/31/2008. Polymorphism, Dynamic Binding and Interface. The class will continue on Tuesday, 12 th August

9 Working with the Java Class Library

CS162: Introduction to Computer Science II. Primitive Types. Primitive types. Operations on primitive types. Limitations

Object-Oriented Programming Concepts

Remote Invocation. 1. Introduction 2. Remote Method Invocation (RMI) 3. RMI Invocation Semantics

Graphical Interface and Application (I3305) Semester: 1 Academic Year: 2017/2018 Dr Antoun Yaacoub

Chapter 4 Defining Classes I

JAVA: A Primer. By: Amrita Rajagopal

nptr = new int; // assigns valid address_of_int value to nptr std::cin >> n; // assigns valid int value to n

Object Oriented Programming. Assistant Lecture Omar Al Khayat 2 nd Year

ECE 122. Engineering Problem Solving with Java

CS162: Introduction to Computer Science II

Part 3. Why do we need both of them? The object-oriented programming paradigm (OOP) Two kinds of object. Important Special Kinds of Member Function

Objectives of CS 230. Java portability. Why ADTs? 8/18/14

JAVA GUI PROGRAMMING REVISION TOUR III

Defining Classes and Methods

CMSC 132: Object-Oriented Programming II

Packages & Random and Math Classes

7. C++ Class and Object

After a lecture on cosmology and the structure of the solar system, William James was accosted by a little old lady.

AP Computer Science Chapter 10 Implementing and Using Classes Study Guide

C++ Basic Syntax. Constructors and destructors. Wojciech Frohmberg / OOP Laboratory. Poznan University of Technology

CMSC 132: Object-Oriented Programming II

Objects Managing a Resource

The Dynamic Typing Interlude

Defining Classes and Methods

Sri Vidya College of Engineering & Technology

CS111: PROGRAMMING LANGUAGE II. Lecture 1: Introduction to classes

Short Notes of CS201

Object Oriented Design

Data Structures. Data structures. Data structures. What is a data structure? Simple answer: a collection of data equipped with some operations.

Encapsulation. Administrative Stuff. September 12, Writing Classes. Quick review of last lecture. Classes. Classes and Objects

CS201 - Introduction to Programming Glossary By

10. Abstract Data Types

Exam 1 - (20 points)

2. Introducing Classes



Motivation was to facilitate development of systems software, especially OS development.

ECE 122. Engineering Problem Solving with Java

ECE 122. Engineering Problem Solving with Java

Computer Science II. OO Programming Classes Scott C Johnson Rochester Institute of Technology

Dynamic memory in class Ch 9, 11.4, 13.1 & Appendix F

Object Oriented Programming COP3330 / CGS5409

Chapter 6 Introduction to Defining Classes

CSE 12, Week Six, Lecture Two Discussion: Getting started on hw7 & hw8

Cpt S 122 Data Structures. Templates

Lesson 10B Class Design. By John B. Owen All rights reserved 2011, revised 2014

Java Fundamentals (II)

CONTENTS: Array Usage Multi-Dimensional Arrays Reference Types. COMP-202 Unit 6: Arrays

Objectives for this class meeting. 1. Conduct review of core concepts concerning contracts and pre/post conditions

George Blankenship 1

CSCI Object Oriented Design: Frameworks and Design Patterns George Blankenship. Frameworks and Design George Blankenship 1

Agenda. Objects and classes Encapsulation and information hiding Documentation Packages

Motivation was to facilitate development of systems software, especially OS development.

CPS122 Lecture: From Python to Java last revised January 4, Objectives:

CPS 506 Comparative Programming Languages. Programming Language

Compaq Interview Questions And Answers

Timing for Interfaces and Abstract Classes

Array. 9 January 2015 OSU CSE 1

CS110D: PROGRAMMING LANGUAGE I

Java: Classes. An instance of a class is an object based on the class. Creation of an instance from a class is called instantiation.

Iterator: A way to sequentially access ( traverse ) each object in a container or collection. - Access is done as needed, not necessarily at once.

Lecture 18 Tao Wang 1

CSCI Object Oriented Design: Java Review Errors George Blankenship. Java Review - Errors George Blankenship 1

An Introduction To Writing Your Own Classes CSC 123 Fall 2018 Howard Rosenthal

CSCI Object-Oriented Design. Java Review Topics. Program Errors. George Blankenship 1. Java Review Errors George Blankenship

Wrapper Classes double pi = new Double(3.14); 3 double pi = new Double("3.14"); 4... Zheng-Liang Lu Java Programming 290 / 321

Cpt S 122 Data Structures. Course Review Midterm Exam # 2

Module 10A Lecture - 20 What is a function? Why use functions Example: power (base, n)

Inheritance and Polymorphism

Fundamentals of Programming Session 15

Chapter 11. Categories of languages that support OOP: 1. OOP support is added to an existing language

Chapter 3 Objects and Classes

Inheritance and Polymorphism

OBJECT ORIENTED PROGRAMMING

CPS122 Lecture: From Python to Java

Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

Chapter 10. Class & Objects in JAVA. By: Deepak Bhinde PGT Com.Sc.

CMSC131. Library Classes

Object-Oriented Programming (OOP) Basics. CSCI 161 Introduction to Programming I

CSE 307: Principles of Programming Languages

OOPS Viva Questions. Object is termed as an instance of a class, and it has its own state, behavior and identity.

CONSTRUCTOR & Description. String() This initializes a newly created String object so that it represents an empty character sequence.

EECS168 Exam 3 Review

Transcription:

In this segment, I will review the Java statements and primitives that relate explicitly to Object Oriented Programming. I need to re-enforce Java s commitment to OOP. Unlike C++, there is no way to build a Java program that does not follow the OOP principles. The Java program itself is an object. George Blankenship 1

The key concepts of OOP are the creation of a object definition which is normally called a class. The class is the fundamental component of OOP programming; all objects trace their roots, their definition to a class. The program has no free standing constructs outside the class. The result of using the class to define all entities in the program is that the programmer is able to create new data types based upon the class paradigm. The class is an abstract definition of an object that allows objects to treated a data items with individual characteristics and behavior. Java, as was said earlier, is completely object oriented. George Blankenship 2

There are a number of terms that are paired. They will be used throughout the rest of the discussion and the next few slides are devoted to explaining the terms and their relationships. Class and object are intrinsically related, as I have said earlier. Once an object is created, the object may have many handles as reference points. Some of the pairings are language unique and not present in Java such as initialization block and destructor; however, the terms need to be clarified. Finally, there are modifies that define the scope of the name, whether it is a Class, data item (object) or method (behavior). George Blankenship 3

The Class is defined in the code; the object does not exist in the code. The code will indicate that an object is to be created (instantiated), but instantiation is performed during the execution of the program. In Java, an object is instantiated by use of the new operator. The Java snippet new ClassName() would instantiate an object based upon the Class ClassName. The Class blueprint defines the attributes and behavior of the object. The attributes of a class are the internal data items of the object. Each attribute is either a fundamental data item such as an integer (int) or an object. The attributes define the state of the object; that is, give the object uniqueness. The behavior of a Class is defined by the methods defined in the source; the methods would be called functions in other languages such as C. The Java snippet void computethenationaldebt(date year, Value grossdomesticproduct, Value nationalbonds){} is an example of the definition of a method with the name computethenationaldebt and a void body. When the method is invoked, it expects three parameters: year, grossdomesticproduct, and nationalbonds. The three parameters are objects; the first is of the class Date and the second two are of the class Value. A method is invoked much like a function in other languages and may return a single object as a result. Generally, when discussing objects, the invocation of a method is sometimes done describing the invocation as passing the object a message. The invocation is accomplished by using the object handle (object name) with the method name; in the example, if the name of the object is name, then the Java snippet name. computethenationaldebt(year, gdp, bonds) would invoke the method with the George Blankenship 4

parameters: year, gdp, and bonds. George Blankenship 4

The new operator creates an object. The object does not have an known immutable identity; it is known by an associated handle. In the prior example the Class name was ClassName. The Java statement ClassName newobject = new ClassName(); would create an object with handle newobject. The handle for the object is not the object; the handle may be associated with another object from the same class. The same object might have multiple handles. The equality test (==) tests that the two sides are the same object, not just the same attributes. If one needs to know whether two handles are references to the same object, or aliases for the same object, the equality operator is used. If one wishes to know whether the attributes are the same, one must use the equals method from the class. The statement zack == Zack does not test the contents of the object zack; it tests that the handle zack is also the handle for the static compiler generated string Zack. There is no string comparison performed; the equals method would perform a string comparison between the two distinct objects. George Blankenship 5

In these two examples, the references example creates an object with two handles (X and Y); the objects example creates two unique objects (X and Y) that start with the same attributes. The two examples demonstrate the difference between a single object with two handles and two unique objects. The modifying example clarifies the difference. The references example is used to demonstrate that the two handles really reference the same object. When X is changed, so is Y. The two unique objects do not have the same behavior; if X is changed, Y retains the initial value. George Blankenship 6

George Blankenship 7

George Blankenship 8

George Blankenship 9

George Blankenship 10

George Blankenship 11

George Blankenship 12

George Blankenship 13

George Blankenship 14

George Blankenship 15

George Blankenship 16

George Blankenship 17

George Blankenship 18

George Blankenship 19

George Blankenship 20

George Blankenship 21

George Blankenship 22

George Blankenship 23

George Blankenship 24

George Blankenship 25

George Blankenship 26