Chair of Software Engineering. Languages in Depth Series: Java Programming. Prof. Dr. Bertrand Meyer. Exercise Session 4.



Similar documents
Java SE 7 Programming

Java SE 7 Programming

Overview of CORBA 11.1 I NTRODUCTION TO CORBA Object services 11.5 New features in CORBA Summary

language 1 (source) compiler language 2 (target) Figure 1: Compiling a program

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

Java SE 7 Programming

Java Memory Model: Content

Habanero Extreme Scale Software Research Project

1.00 Lecture 1. Course information Course staff (TA, instructor names on syllabus/faq): 2 instructors, 4 TAs, 2 Lab TAs, graders

Event-based middleware services

Web Presentation Layer Architecture

Applets, RMI, JDBC Exam Review

GDB Tutorial. A Walkthrough with Examples. CMSC Spring Last modified March 22, GDB Tutorial

BBA SMALL BUSINESS MANAGEMENT Spring 2016

First Java Programs. V. Paúl Pauca. CSC 111D Fall, Department of Computer Science Wake Forest University. Introduction to Computer Science

Java SE 8 Programming

Java Interview Questions and Answers

Simple Dialog Box Management Handout.pdf. Detailed Instructions

Cognos Event Studio. Deliver By : Amit Sharma Presented By : Amit Sharma

COSC Introduction to Computer Science I Section A, Summer Question Out of Mark A Total 16. B-1 7 B-2 4 B-3 4 B-4 4 B Total 19

Java Language Tools COPYRIGHTED MATERIAL. Part 1. In this part...

Built-in Concurrency Primitives in Java Programming Language. by Yourii Martiak and Mahir Atmis

Introduction CORBA Distributed COM. Sections 9.1 & 9.2. Corba & DCOM. John P. Daigle. Department of Computer Science Georgia State University

Basic Object-Oriented Programming in Java

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

Trace-Based and Sample-Based Profiling in Rational Application Developer

16.1 DataFlavor DataFlavor Methods. Variables

Game Center Programming Guide

J a v a Quiz (Unit 3, Test 0 Practice)

CHAPTER 19 Programming Lists of Data

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

University of Twente. A simulation of the Java Virtual Machine using graph grammars

Instructor s Guide. Quick Interview and Salary Negotiation Video

Mental Health Role Plays

Lecture 7: Java RMI. CS178: Programming Parallel and Distributed Systems. February 14, 2001 Steven P. Reiss

CHAPTER 2 DATABASE MANAGEMENT SYSTEM AND SECURITY

CS330 Design Patterns - Midterm 1 - Fall 2015

Designing with Exceptions. CSE219, Computer Science III Stony Brook University

Android Application Development Course Program

Successful Mailings in The Raiser s Edge

Programming Without a Call Stack: Event-driven Architectures

Reputation Marketing Proposal. Overview Summary

CS193j, Stanford Handout #10 OOP 3

Tutorial: Getting Started

USER MANUAL. Toll Free:

Implementação. Interfaces Pessoa Máquina 2010/ Salvador Abreu baseado em material Alan Dix. Thursday, June 2, 2011

Approvals Management Engine R12 (AME) Demystified

Comp 411 Principles of Programming Languages Lecture 34 Semantics of OO Languages. Corky Cartwright Swarat Chaudhuri November 30, 20111

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

Infrastructure that supports (distributed) componentbased application development

Service Provider awareness Universal Apparatus

Class 32: The Java Collections Framework

The Job Search. Instructor s Guide. Transition to Work and Self Sufficiency Video Series. for. Overview. Presentation Suggestions

WHAT ELSE CAN YOUR HOME PHONE DO?

Summit Public Schools Summit, New Jersey Grade Level / Content Area: Mathematics Length of Course: 1 Academic Year Curriculum: AP Computer Science A

100 Pug Training Tips

Check Out These Wonder Tips About Reputation Management In The Article Below

Guide to Performance and Tuning: Query Performance and Sampled Selectivity

UI Performance Monitoring

16. Recursion. COMP 110 Prasun Dewan 1. Developing a Recursive Solution

Completing a Quiz in Moodle

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

Crash Course in Java

Thesis Proposal: Improving the Performance of Synchronization in Concurrent Haskell

KWIC Implemented with Pipe Filter Architectural Style

I/O Device and Drivers

JAVA - OBJECT & CLASSES

COMP 110 Prasun Dewan 1

Virtual Machine Learning: Thinking Like a Computer Architect

A Sample OFBiz application implementing remote access via RMI and SOAP Table of contents

CHAPTER 14 Understanding an App s Architecture

CPS122 Lecture: State and Activity Diagrams in UML

Fundamentals of Java Programming

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

How to build agent based models. Field service example

ENHANCING YOUR WEBCAST EXPERIENCE

How to use the Eclipse IDE for Java Application Development

6.170 Tutorial 3 - Ruby Basics

Stock Trader System. Architecture Description

CSE 1223: Introduction to Computer Programming in Java Chapter 2 Java Fundamentals

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

Stack Allocation. Run-Time Data Structures. Static Structures

CSE 2123 Collections: Sets and Iterators (Hash functions and Trees) Jeremy Morris

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

TESTING WITH JUNIT. Lab 3 : Testing

Database Design Basics

Inside the Java Virtual Machine

Writing Grid Service Using GT3 Core. Dec, Abstract

Model Simulation in Rational Software Architect: Business Process Simulation

CSCI E 98: Managed Environments for the Execution of Programs

Best Practices For PL/SQL Development in Oracle Application Express

Introduction to MIPS Programming with Mars

Link-Time Static Analysis for Efficient Separate Compilation of Object-Oriented Languages

Chapter 5 Names, Bindings, Type Checking, and Scopes

Guide to Upsizing from Access to SQL Server

UIL Computer Science for Dummies by Jake Warren and works from Mr. Fleming

Java Virtual Machine Locks

BBC Learning English Talk about English Business Language To Go Part 2 - Induction

How to Write AllSeen Alliance Self- Certification Test Cases September 25, 2014

Description of Class Mutation Mutation Operators for Java

Transcription:

Chair of Software Engineering Languages in Depth Series: Java Programming Prof. Dr. Bertrand Meyer Exercise Session 4 Adriana Ispas

Today s Exercise Session Assignment III Walkthrough the master solution (your solutions) Questions Assignment IV Calculator & Streams Pattern of the Day The Observer Pattern Quizzes 2

Assignment III Walkthrough the master solution (your solutions) Questions 3

Assignment IV Calculator Component & Streams 4

The Observer Pattern Behavioral pattern Thus concerned with communication between objects. Defines the way a number of classes can be notified of a change Define a one-to-many dependency between objects. A Subject may have any number of dependent Observers When the Subject object changes state, all its Observers are notified and updated automatically Also known as Each Observer queries the Subject to synchronize its state with the Subject's state. Dependents, Publish-Subscribe. 5

The Observer Pattern - Structure 6

The Observer Pattern - Collaborations 7

The Observer Pattern - Example Display data in more than one form at the same time and have all of the displays reflect any changes in that data. 8

The Observer Pattern - Example Separate the object containing the data from the objects displaying the data and make display objects observe changes in that data. Refer to the data as the Subject and each of the displays as Observers. Each of the observers registers its interest in the data by calling a public method in the Subject. 9

The Observer Pattern - Example 10

Watching Colors Change 11

Watching Colors Change Subject 12

Watching Colors Change Observers 13

The Observer Pattern JDK Implementation java.util.observable java.util.observable#notifyobservers() java.util.observable#notifyobservers(java.lang.object) java.util.observer java.util.observer#update(java.util.observable, java.lang.object) 14

The Observer Pattern Consequences 1 Observers promote abstract coupling to Subjects. A subject doesn t know the details of its observers. Potential disadvantage of successive or repeated updates to the Observers. If the cost of these updates is high, it may be necessary to introduce some sort of change management, so that the Observers are not notified too soon or too frequently. 15

The Observer Pattern Consequences 2 Need to decide which object initiates the notification of the change to the other observers. Subject notifies all the observers when one client changes the data. Client is not responsible for remembering to initiate the notification. But this can result in a number of small successive updates being triggered. Clients tell the Subject when to notify the other clients. But the clients are left with the responsibility of telling the Subject when to send the notifications. If one client forgets the program simply won t work properly. 16

The Observer Pattern Consequences 3 May specify different kinds of notifications by defining a number of update methods for the Observers to receive depending on the type or scope of change. In some cases, the clients will thus be able to ignore some of these notifications. 17

The Observer Pattern Consequences 4 Obtaining additional information about the change. Push model Subject sends detailed information about the change to the Observers (as argument to update). A superset of information including everything any Observer might need is transferred. Pull model Subject sends nothing but the most minimal notification, and Observers ask for details explicitly (via getstate()). Potential problems in asynchronous / concurrent environments if Subject's state changes again between the original announcement and the time the Observer issues its query. 18

Quiz 1:What is Printed? 19

Quiz 1:What is Printed? Output: false Name class does not override hashcode, thus it inherits the implementation from Object. Hash set chooses the hash bucket based on the hash value of the instance, as computed by the hashcode method. Second instance is distinct from the first, thus likely to have a different hash value. If the two hash values map to different buckets, the contains method will return false. Fix Override hashcode whenever you override equals. Ex: 37 * first.hashcode() + last.hashcode(); 20

Quiz 2:What Does the Program Print? The Basenji is a breed of small, curly-tailed dogs of African origin that do not bark. 21

Quiz 2:What Does the Program Print? Output: woof woof There is no dynamic dispatch on static methods. But bark is a static method. When a program calls a static method, the method to be invoked is selected at compile time, based on the compiletime type of the qualifier (the name we give to the part of the method invocation expression to the left of the dot). In this case, the qualifiers of the two method invocations are the variables woofer and nipper of type Dog. The invoked method is Dog.bark (it doesn't matter that the runtime type of nipper is Basenji; only its compiletime). Never qualify a static method invocation with an expression. 22

Quiz 3: Null and Void 23

Quiz 3: Null and Void Output: Hello world! Null.greet is a static method. Bad idea to use an expression as the qualifier in a static method invocation. The run-time type of the object referenced by the expression's value plays no role in determining which method gets invoked, nor does the identity of the object. In this case, there is no object, but that makes no difference. A qualifying expression for a static method invocation is evaluated, but its value is ignored. There is no requirement that the value be non-null. 24

Questions? 25

Exercise Session 5 Pattern of the Day The Singleton Pattern Quizzes Assignment IV Correction Assignment V Hand-out 26