CSCI 253. Object Oriented Programming (OOP) Overview. George Blankenship 1. Object Oriented Design: Java Review OOP George Blankenship.



Similar documents
Chapter 1 Fundamentals of Java Programming

Fundamentals of Java Programming

Glossary of Object Oriented Terms

Java Interview Questions and Answers

History OOP languages Year Language 1967 Simula Smalltalk

Java How to Program, 5/e Test Item File 1 of 5

Java Application Developer Certificate Program Competencies

The Java Series. Java Essentials I What is Java? Basic Language Constructs. Java Essentials I. What is Java?. Basic Language Constructs Slide 1

PHP Object Oriented Classes and objects

Programmation 2. Introduction à la programmation Java

CEC225 COURSE COMPACT

Object-Oriented Programming in Java

Java Programming Language

Object Oriented Design

Chapter 13 - Inheritance

CS 111 Classes I 1. Software Organization View to this point:

C++ INTERVIEW QUESTIONS

Object-Oriented Programming Lecture 2: Classes and Objects

CS193j, Stanford Handout #10 OOP 3

Compiling Object Oriented Languages. What is an Object-Oriented Programming Language? Implementation: Dynamic Binding

Description of Class Mutation Mutation Operators for Java

Java (12 Weeks) Introduction to Java Programming Language

Lecture 7 Notes: Object-Oriented Programming (OOP) and Inheritance

SE 360 Advances in Software Development Object Oriented Development in Java. Polymorphism. Dr. Senem Kumova Metin

Habanero Extreme Scale Software Research Project

Introduction: Abstract Data Types and Java Review

Multichoice Quetions 1. Atributes a. are listed in the second part of the class box b. its time is preceded by a colon. c. its default value is

OpenCL Static C++ Kernel Language Extension

AP Computer Science Java Subset

Agile Software Development

Storage Classes CS 110B - Rule Storage Classes Page 18-1 \handouts\storclas

Chapter 4 OOPS WITH C++ Sahaj Computer Solutions

Java CPD (I) Frans Coenen Department of Computer Science

qwertyuiopasdfghjklzxcvbnmqwerty uiopasdfghjklzxcvbnmqwertyuiopasd fghjklzxcvbnmqwertyuiopasdfghjklzx cvbnmqwertyuiopasdfghjklzxcvbnmq

KITES TECHNOLOGY COURSE MODULE (C, C++, DS)

Polymorphism. Problems with switch statement. Solution - use virtual functions (polymorphism) Polymorphism

JAVA - INHERITANCE. extends is the keyword used to inherit the properties of a class. Below given is the syntax of extends keyword.

Android Application Development Course Program

13 Classes & Objects with Constructors/Destructors

CompuScholar, Inc. Alignment to Utah's Computer Programming II Standards

CIS 190: C/C++ Programming. Polymorphism

Java Interfaces. Recall: A List Interface. Another Java Interface Example. Interface Notes. Why an interface construct? Interfaces & Java Types

CS1002: COMPUTER SCIENCE OO MODELLING & DESIGN: WEEK 5

The C Programming Language course syllabus associate level

WORKSPACE WEB DEVELOPMENT & OUTSOURCING TRAINING CENTER

C++FA 5.1 PRACTICE MID-TERM EXAM

The Sun Certified Associate for the Java Platform, Standard Edition, Exam Version 1.0

Java 6 'th. Concepts INTERNATIONAL STUDENT VERSION. edition

Part I. Multiple Choice Questions (2 points each):

Java Software Structures

Computing Concepts with Java Essentials

INTRODUCTION TO OBJECTIVE-C CSCI 4448/5448: OBJECT-ORIENTED ANALYSIS & DESIGN LECTURE 12 09/29/2011

Free Java textbook available online. Introduction to the Java programming language. Compilation. A simple java program

Java EE Web Development Course Program

Specialized Programme on Web Application Development using Open Source Tools

Free Java textbook available online. Introduction to the Java programming language. Compilation. A simple java program

Handout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner.

java Features Version April 19, 2013 by Thorsten Kracht

TOWARDS A GREEN PROGRAMMING PARADIGM FOR MOBILE SOFTWARE DEVELOPMENT

VB.NET - CLASSES & OBJECTS

Abstract Class & Java Interface

Exception Handling. Overloaded methods Interfaces Inheritance hierarchies Constructors. OOP: Exception Handling 1

Syllabus for CS 134 Java Programming

Introduction to Object-Oriented Programming

TECHNOLOGY Computer Programming II Grade: 9-12 Standard 2: Technology and Society Interaction

Objectif. Participant. Prérequis. Remarque. Programme. C# 3.0 Programming in the.net Framework. 1. Introduction to the.

Preet raj Core Java and Databases CS4PR. Time Allotted: 3 Hours. Final Exam: Total Possible Points 75

How To Write A Program In Java (Programming) On A Microsoft Macbook Or Ipad (For Pc) Or Ipa (For Mac) (For Microsoft) (Programmer) (Or Mac) Or Macbook (For

Course MS10975A Introduction to Programming. Length: 5 Days

PROBLEM SOLVING SEVENTH EDITION WALTER SAVITCH UNIVERSITY OF CALIFORNIA, SAN DIEGO CONTRIBUTOR KENRICK MOCK UNIVERSITY OF ALASKA, ANCHORAGE PEARSON

Java is an Object-Oriented Language. As a language that has the Object Oriented feature, Java supports the following fundamental concepts:

Debugging. Common Semantic Errors ESE112. Java Library. It is highly unlikely that you will write code that will work on the first go

Checking Access to Protected Members in the Java Virtual Machine

JAVA INTERVIEW QUESTIONS

How To Teach C++ Data Structure Programming

Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer

DIPLOMADO DE JAVA - OCA

Exercise 8: SRS - Student Registration System

El Dorado Union High School District Educational Services

D06 PROGRAMMING with JAVA

Specialized Programme on Web Application Development using Open Source Tools

Java Programming Fundamentals

Morris School District. AP Computer Science A Curriculum Grades 9-12

Compile-time type versus run-time type. Consider the parameter to this function:

Object Oriented Programming With C++(10CS36) Question Bank. UNIT 1: Introduction to C++

Programming Languages Featherweight Java David Walker

Advanced Data Structures

Introduction to Programming Block Tutorial C/C++

JAVA - OBJECT & CLASSES

Génie Logiciel et Gestion de Projets. Object-Oriented Programming An introduction to Java

Cohort: BCA/07B/PT - BCA/06/PT - BCNS/06/FT - BCNS/05/FT - BIS/06/FT - BIS/05/FT - BSE/05/FT - BSE/04/PT-BSE/06/FT

Java and Java Virtual Machine security vulnerabilities and their exploitation techniques

AP Computer Science A - Syllabus Overview of AP Computer Science A Computer Facilities

PART IV Performance oriented design, Performance testing, Performance tuning & Performance solutions. Outline. Performance oriented design

public static void main(string[] args) { System.out.println("hello, world"); } }

Object-Oriented Design Lecture 4 CSU 370 Fall 2007 (Pucella) Tuesday, Sep 18, 2007

Transcription:

CSCI 253 Object Oriented Design: Java Review OOP George Blankenship George Blankenship 1 Object Oriented Programming (OOP) OO Principles Abstraction Encapsulation Abstract Data Type (ADT) Implementation independent interfaces Data and operations on data Java George Blankenship 2 Overview Objects & class References & alias this & super reference Constructor & initialization block Garbage collection & destructor Modifiers Public, Private, Protected Static Final George Blankenship 3 George Blankenship 1

Object Object & Class Abstracts away (data, algorithm) details Encapsulates data Instances exist at run time Class Blueprint for objects (of same type) Exists at compile time George Blankenship 4 References & Aliases Reference A way to get to an object, not the object itself All variables in Java are references to objects Alias Multiple references to same object X == Y operator tests for alias X.equals(Y) tests contents of object (potentially) George Blankenship 5 References & Aliases Issues Copying References X = new Object(); Y = X; Objects X = new Object(); Y = X.clone(); Modifying objects X = new Object(); Y = X; X.change(); // Y refers to same object as X // Y refers to different object // modifies object for Y George Blankenship 6 George Blankenship 2

this Reference Reserved keyword Refers to object through which method was invoked Allows object to refer to itself Use to refer to instance variables of object George Blankenship 7 Inheritance Definition Relationship between classes when state and behavior of one class is a subset of another class Terminology Superclass / parent More general class Subclass More specialized class Forms a class hierarchy Helps promote code reuse George Blankenship 8 super Reference Reserved keyword Refers to superclass Allows object to refer to methods and encapsulated data in superclass Examples super.x // accesses x in superclass super() // invokes constructor in superclass super.foo() // invokes method foo in superclass George Blankenship 9 George Blankenship 3

Constructor Method invoked when object is instantiated Helps initialize object Method with same name as class w/o return type Implicitly invokes constructor for superclass If not explicitly included George Blankenship 10 Constructor Example class foo { foo() { // constructor for foo class bar extends foo { bar() { // constructor for bar // implicitly invokes foo() here class bar2 extends foo { bar2() { // constructor for bar super(); // explicitly invokes foo() here George Blankenship 11 Initialization Block Definition Block of code used to initialize static & instance variables for class Motivation Enable complex initializations for static variables Control flow Exceptions Share code between multiple constructors for same class George Blankenship 12 George Blankenship 4

Variable Initialization Variables may be initialized At time of declaration In initialization block In constructor Order of initialization Declaration, initialization block (in the same order as in the class definition) Constructor George Blankenship 13 Garbage Collection Concepts All interactions with objects occur through reference variables If no reference to object exists, object becomes garbage (useless, no longer affects program) Garbage collection Reclaiming memory used by unreferenced objects Periodically performed by Java Not guaranteed to occur Only needed if running low on memory George Blankenship 14 Destructor Method with name finalize() Returns void Contains action performed when object is freed Invoked automatically by garbage collector Not invoked if garbage collection does not occur Usually needed only for non-java methods George Blankenship 15 George Blankenship 5

Method Overloading Description Same name refers to multiple methods Sources of overloading Multiple methods with different parameters Constructors frequently overloaded Redefine method in subclass George Blankenship 16 Package Definition Group related classes under one name Helps manage software complexity Separate namespace for each package Package name added in front of actual name Put generic / utility classes in packages Avoid code duplication George Blankenship 17 Package Import Import Make classes from package available for use Java API java.* (core) javax.* (optional) Example import java.util.random; // import single class import java.util.*; // all classes in package // class definitions George Blankenship 18 George Blankenship 6

Scope Part of program where a variable may be referenced Determined by location of variable declaration Boundary usually demarcated by { George Blankenship 19 Modifier Java keyword (added to definition) Specifies characteristics of a language construct (Partial) list of modifiers Public / private / protected Static Final Abstract George Blankenship 20 Visibility Modifier Properties Controls access to class members Applied to instance variables & methods Four types of access in Java Public Most visible Protected Package Default if no modifier specified Private Least visible George Blankenship 21 George Blankenship 7

Visibility Modifier Scope public Referenced anywhere (i.e., outside package) protected Referenced within package, or by subclasses outside package None specified (package) Referenced only within package private Referenced only within class definition Applicable to class fields & methods George Blankenship 22 Visibility Modifier - Use For instance variables Should usually be private to enforce encapsulation Sometimes may be protected for subclass access For methods Public methods provide services to clients Private methods provide support other methods Protected methods provide support for subclass George Blankenship 23 Modifier Static Static variable Single copy for class Shared among all objects of class Static method Can be invoked through class name Does not need to be invoked through object Can be used even if no objects of class exist Can not reference instance variables George Blankenship 24 George Blankenship 8

Modifier Final Final variable Value can not be changed Must be initialized in every constructor Attempts to modify final are caught at compile time Final static variable Used for constants Final method Method can not be overloaded by subclass Private methods are implicitly final Final class Class can not be a superclass (extended) Methods in final class are implicitly final Using final classes Prevents inheritance / polymorphism May be useful for Security Object oriented design George Blankenship 25 Modifier Abstract Description Represents generic concept Can not be instantiated Abstract class Placeholder in class hierarchy Can be partial description of class Can contain non-abstract methods Required if any method in class is abstract George Blankenship 26 George Blankenship 9