box Boxes and Arrows 3 true 7.59 'X' An object is drawn as a box that contains its data members, for example:

Similar documents
Agenda & Reading. Class Exercise. COMPSCI 105 SS 2012 Principles of Computer Science. Arrays

cisc1110 fall 2010 lecture VI.2 call by value function parameters another call by value example:

From Dependencies to Evaluation Strategies

Discussion 1 Recap. COP4600 Discussion 2 OS concepts, System call, and Assignment 1. Questions. Questions. Outline. Outline 10/24/2010

CS201 Discussion 10 DRAWTREE + TRIES

Reference types and their characteristics Class Definition Constructors and Object Creation Special objects: Strings and Arrays

Pointers and Arrays. More Pointer Examples. Pointers CS 217

ASTs, Regex, Parsing, and Pretty Printing

CS 241 Week 4 Tutorial Solutions

CIS 1068 Program Design and Abstraction Spring2015 Midterm Exam 1. Name SOLUTION

Introduction to Computer Science, Shimon Schocken, IDC Herzliya. Lecture Writing Classes

Systems I. Logic Design I. Topics Digital logic Logic gates Simple combinational logic circuits

COMPUTER SCIENCE 123. Foundations of Computer Science. 6. Tuples

10/9/2012. Operator is an operation performed over data at runtime. Arithmetic, Logical, Comparison, Assignment, Etc. Operators have precedence

Programming. Example - Complex Numbers. add_complex step by step. add_complex step by step. add_complex step by step י"ט/טבת/תשע"א

Functor (1A) Young Won Lim 8/2/17

COMP 423 lecture 11 Jan. 28, 2008

Functor (1A) Young Won Lim 10/5/17

Fig.25: the Role of LEX

Lists in Lisp and Scheme

Lecture 10 Evolutionary Computation: Evolution strategies and genetic programming

Virtual Machine (Part I)

CMPSC 470: Compiler Construction

CSc 453. Compilers and Systems Software. 4 : Lexical Analysis II. Department of Computer Science University of Arizona

2-3 search trees red-black BSTs B-trees

Implementing Automata. CSc 453. Compilers and Systems Software. 4 : Lexical Analysis II. Department of Computer Science University of Arizona

A Tautology Checker loosely related to Stålmarck s Algorithm by Martin Richards

Symbol Table management

Product of polynomials. Introduction to Programming (in C++) Numerical algorithms. Product of polynomials. Product of polynomials

Operator Precedence. Java CUP. E E + T T T * P P P id id id. Does a+b*c mean (a+b)*c or

A dual of the rectangle-segmentation problem for binary matrices

If you are at the university, either physically or via the VPN, you can download the chapters of this book as PDFs.

2 Computing all Intersections of a Set of Segments Line Segment Intersection

Mid-term exam. Scores. Fall term 2012 KAIST EE209 Programming Structures for EE. Thursday Oct 25, Student's name: Student ID:

CSCE 531, Spring 2017, Midterm Exam Answer Key

10.5 Graphing Quadratic Functions

CPSC 213. Polymorphism. Introduction to Computer Systems. Readings for Next Two Lectures. Back to Procedure Calls

Quiz2 45mins. Personal Number: Problem 1. (20pts) Here is an Table of Perl Regular Ex

CS321 Languages and Compiler Design I. Winter 2012 Lecture 5

Union-Find Problem. Using Arrays And Chains. A Set As A Tree. Result Of A Find Operation

PYTHON PROGRAMMING. The History of Python. Features of Python. This Course

Creating Flexible Interfaces. Friday, 24 April 2015

Reducing a DFA to a Minimal DFA

Definition of Regular Expression

Spring 2018 Midterm Exam 1 March 1, You may not use any books, notes, or electronic devices during this exam.

Introduction To Files In Pascal

OUTPUT DELIVERY SYSTEM

Stack Manipulation. Other Issues. How about larger constants? Frame Pointer. PowerPC. Alternative Architectures

Agilent Mass Hunter Software

Lexical Analysis. Amitabha Sanyal. ( as) Department of Computer Science and Engineering, Indian Institute of Technology, Bombay

ΕΠΛ323 - Θεωρία και Πρακτική Μεταγλωττιστών

CSCI 3130: Formal Languages and Automata Theory Lecture 12 The Chinese University of Hong Kong, Fall 2011

Midterm 2 Sample solution

Lecture Overview. Knowledge-based systems in Bioinformatics, 1MB602. Procedural abstraction. The sum procedure. Integration as a procedure

Sample Midterm Solutions COMS W4115 Programming Languages and Translators Monday, October 12, 2009

MIPS I/O and Interrupt

Java CUP. Java CUP Specifications. User Code Additions. Package and Import Specifications

CS412/413. Introduction to Compilers Tim Teitelbaum. Lecture 4: Lexical Analyzers 28 Jan 08

Control-Flow Analysis and Loop Detection

L2-Python-Data-Structures

Math 464 Fall 2012 Notes on Marginal and Conditional Densities October 18, 2012

CS 340, Fall 2014 Dec 11 th /13 th Final Exam Note: in all questions, the special symbol ɛ (epsilon) is used to indicate the empty string.

INTRODUCTION TO SIMPLICIAL COMPLEXES

In the last lecture, we discussed how valid tokens may be specified by regular expressions.

EXPONENTIAL & POWER GRAPHS

MTH 146 Conics Supplement

Languages. L((a (b)(c))*) = { ε,a,bc,aa,abc,bca,... } εw = wε = w. εabba = abbaε = abba. (a (b)(c)) *

View, evaluate, and publish assignments using the Assignment dropbox.

1.5 Extrema and the Mean Value Theorem

Lab 1 - Counter. Create a project. Add files to the project. Compile design files. Run simulation. Debug results

Here is an example where angles with a common arm and vertex overlap. Name all the obtuse angles adjacent to

Assignment 11 (The Last One) Due Date for Programs: December 13, 2016

Unit #9 : Definite Integral Properties, Fundamental Theorem of Calculus

Error Numbers of the Standard Function Block

Summer Review Packet For Algebra 2 CP/Honors

Lexical analysis, scanners. Construction of a scanner

Example: 2:1 Multiplexer

Introduction to Julia for Bioinformatics

Scanner Termination. Multi Character Lookahead. to its physical end. Most parsers require an end of file token. Lex and Jlex automatically create an

Simrad ES80. Software Release Note Introduction

P(r)dr = probability of generating a random number in the interval dr near r. For this probability idea to make sense we must have

OPERATION MANUAL. DIGIFORCE 9307 PROFINET Integration into TIA Portal

Introduction to Algebra

ITEC2620 Introduction to Data Structures

WebAssign Lesson 1-3a Substitution Part 1 (Homework)

Deletion The Two Child Case 10 Delete(5) Deletion The Two Child Case. Balanced BST. Finally

Engineer-to-Engineer Note

CS311H: Discrete Mathematics. Graph Theory IV. A Non-planar Graph. Regions of a Planar Graph. Euler s Formula. Instructor: Işıl Dillig

UNIVERSITY OF EDINBURGH COLLEGE OF SCIENCE AND ENGINEERING SCHOOL OF INFORMATICS INFORMATICS 1 COMPUTATION & LOGIC INSTRUCTIONS TO CANDIDATES

Compression Outline :Algorithms in the Real World. Lempel-Ziv Algorithms. LZ77: Sliding Window Lempel-Ziv

Grade 7/8 Math Circles Geometric Arithmetic October 31, 2012

On the Detection of Step Edges in Algorithms Based on Gradient Vector Analysis

CS 241. Fall 2017 Midterm Review Solutions. October 24, Bits and Bytes 1. 3 MIPS Assembler 6. 4 Regular Languages 7.

Homework. Context Free Languages III. Languages. Plan for today. Context Free Languages. CFLs and Regular Languages. Homework #5 (due 10/22)

ΕΠΛ323 - Θεωρία και Πρακτική Μεταγλωττιστών. Lecture 3b Lexical Analysis Elias Athanasopoulos

PARALLEL AND DISTRIBUTED COMPUTING

Lecture 7: Integration Techniques

LR Parsing, Part 2. Constructing Parse Tables. Need to Automatically Construct LR Parse Tables: Action and GOTO Table

Fall 2018 Midterm 1 October 11, ˆ You may not ask questions about the exam except for language clarifications.

What do all those bits mean now? Number Systems and Arithmetic. Introduction to Binary Numbers. Questions About Numbers

Transcription:

Boxes nd Arrows There re two kinds of vriles in Jv: those tht store primitive vlues nd those tht store references. Primitive vlues re vlues of type long, int, short, chr, yte, oolen, doule, nd flot. References re used to ccess ojects. A is good metphor for either kind of vrile. Drwing es for primitive vriles is esy. The contents of the is the stored primitive vlue. A few exmples pper elow. 3 true 7.59 'X' n int vrile oolen vrile doule vrile chr vrile An oject is drwn s tht contins its dt memers, for exmple: clss Account { privte doule myblnce; privte long myid; privte oolen isspecil; myblnce 1523.67 myid 12345678 isspecil true Finlly, reference to n oject (returned y new) is drwn s n rrow: clss Account { privte doule myblnce; privte long myid; privte oolen isspecil; myblnce myid isspecil Account = new Account ( ); clss Word { privte String mychrs; Word toguess = new Word ("syzygy"); toguess mychrs "syzygy" A reference-vlued vrile is sometimes referred to s pointer. 64

How the ssignment sttement reltes to es An ssignment sttement merely copies the vlue in one to nother. When the contins reference n rrow two references to the sme oject result. Below re some sequences of ssignment sttements, long with their -nd-rrow representtions. We strt with int vriles: int m, n; m = 5; m 5 n? n = m; m = 7; m 7 n 5 In lmost ll progrmming lnguges, the effect is the sme: the vlue 5 in m gets copied into n, then the vlue 7 gets copied into m, replcing the 5 tht it formerly contined. Now consider n Account clss with single dt memer nmed myblnce nd three methods, constructor, deposit method, nd withdrw method. pulic clss Account { pulic Account (int initamount) { myblnce = initamount; pulic void deposit (int mount) { myblnce += mount; pulic void withdrw (int mount) { myblnce -= mount; privte int myblnce; Account = new Account (100); 100 Account = ; = new Account (200); Here, the reference vlue initilly stored into nmely, the rrow is copied into. After the ssignment sttement, nd contin references to the sme ccount. A new reference vlue is then creted vi the new opertor, nd tht reference is stored into, replcing s former contents. 200 100 65

Let s try nother one. Account = new Account (100); 100 Account = ;.withdrw (10); 90 A reference to new ccount is stored into. Tht reference (the rrow) is copied into ; oth vriles now contin references to the sme ccount. The withdrwl from tht ccount is visile either through s reference or through s. In C (without structs) nd Scheme, we hve essentilly the sme ehvior. Code segments tht hve the effect of the exmple just discussed pper elow. C int [1] = {100; int* = ; [0] -= 10; Scheme (define '(100)) (define ) (set-cr! (- (cr ) 10)) Prmeter pssing All method prmeters in Jv re pssed y vlue, which mens they re copied into temporry vriles in the function. As with the ssignment sttement, the copying of reference involves only the reference itself, not the oject referred to. (Agin, this is the sme ehvior s in C nd Scheme.) Suppose we supply n dditionl method for the Account clss: pulic void mke900 (Account ) { = new Account (900); Consider now the effect of the two ssignment sttements = new Account (); mke900 (); The first sets up reference to n ccount with lnce of $ The second sttement, cll to mke900, cretes copy of the reference nd stores it in the vrile (which is locl to mke900). 66

Within mke900, reference to new ccount is creted nd stored into. The effect is shown elow. 900 Upon return from mke900, the locl vrile disppers nd the reference still points to the ccount with $. Consider now method mke99 defined inside the Account clss: pulic void mke99 (Account ) {.myblnce = 99; Contrst the effect of the two sequences of ssignment sttements: ssignment sttements result immeditely efore returning from the method = new Account (); mke900 (); 900 = new Account (); mke99 (); 99 For one finl exmple, we consider the following method: pulic void swp (Account, Account ) { Account temp; temp = ; = ; = temp; Account = new Account (3000); Account crol = new Account (1500); swp (, crol); 67

Wht s the effect of the cll to swp? It hs no effect on either of the ccounts. Here s why. We strt with the initiliztion of nd crol: 3000 crol 1500 Then we enter the method, copying the rgument references to the locl vriles nd : 3000 temp crol 1500 After the first two ssignments, we hve 3000 temp crol 1500 The finl ssignment sttement copies reference to Mike s ccount into. Neither the vrile, the crol vrile, nor the corresponding Account ojects re modified y the swp method. 68

Comprisons A comprison of two references using == determines whether the two things compred re references to the sme ojects. (This ehvior is the sme s in C, nd the sme s wht the eq? function provides in Scheme.) Here s n exmple. Account = new Account (100); Account = ;.withdrw (10); Account c = new Account (90); c 90 90 After execution of the four sttements, comprisons etween the reference vlues would hve the results shown elow. expression vlue reson == true oth nd refer to the sme oject == c flse nd c refer to different ojects, even though those ojects oth hve the sme lnce == c flse sme reson Comprison of two ojects in Jv is conventionlly done with the equls method s shown elow. pulic oolen equls (Account ) { return this.myblnce ==.myblnce; 69