Lab 5. Other things. Changes in the schedule. Will add time slots for design presentations on Tuesday, Feb 28. Disciplin.
|
|
- Bartholomew Black
- 6 years ago
- Views:
Transcription
1 this and super Examples Mutable and Immutable Objects D0010E Lecture 12 The Engineering of Computer Programming Side-effects Method Categories Finite State Machines Lab 5 The last lab assignment includes a first step where you design your solution. UML diagram + explanations (on paper) For each class: What does it represent? What is its responsibility? This is mandatory. You are not allowed to start with the programming until you have presented your design for a teacher and had it approved. 2 Other things Changes in the schedule. Rearrangements within the modul, so no big deal. Will add time slots for design presentations on Tuesday, Feb 28. Disciplin. The Engineering of Programming Through the years, practical programmers have identified many principles that influence the life of a programmer: Three important ones are: locality, side-effects, and method classification. 3 4
2 a) Create high locality Code has locality if it relies on and effects local data and methods. Place data together with methods that access the data. Advantage: Parts of a program that has high locality can be understood with only little understanding of the entire program. Encapsulation of data in classes (using private) is an example of how high locality can often be achieved. A private attribute can, for instance, only be accessed in the class containing the attribute. Global variables have low locality. This is why variables should not be public. Strive to write code that has high "locality". b) Avoid hidden side-effects Avoid methods that cause side-effects in the dark. Such a side-effect is a change of a variable that can not be inferred from the call to the method. Easy to forget about the side-effects, which might result in programming errors. If you have to use side-effects: Give methods clear and meaningful names that signal to a programmer that side-effects will occur. Document properly. 5 6 c) Method categories c) Method categories Classify methods into two categories only: Functions that always return the same result given the same arguments. Like mathematical functions. Procedures that have no return type (declared void) and only cause change in this and objects referred to by arguments. Avoid creating mixed methods. An example: If we know that f is a function, f(x) == f(x) is always true and Math.pow(f(x),2) is always equal to f(x)*f(x). Otherwise, such statements need not be true. 7 8
3 Mutable vs. immutable objects A dynamic object is mutable if its state can be changed after creation. Efficient, but could be hard to understand. Otherwise it is immutable. Once created, immutable objects never change. Most classes can be written so that their dynamic objects are either mutable or immutable. Mutable vs. immutable objects Advantage with immutable objects: Programmers do not need to keep track of (in their heads) how immutable objects change when the program is run. Immutable objects are also called values. Programming with immutable objects is easier because they can not change() Code is immediately understandable by just looking at it (locally). Make a clear difference between mutable and immutable objects Immutable objects Example: String Once created, a string can not be changed. However, it is always possible to create a new string from copies of other strings. The old strings are uneffected by this. No need for the programmer to keep track of how the strings change. Also, all string-methods return the same result given the same arguments. int length() char charat(int index) String replace(char oldchar, char newchar) The class Pair<A,B> shown earlier is also immutable: 11 Pair<A,B> class Pair<A, B> { private A first; private B second; public Pair(A first, B second) { this.first = first; this.second = second; public A fst() { return first; public B snd() { return second; public Pair<B, A> mirror() { return new Pair<B, A>(snd(), fst()); public String tostring() { return "(" + fst() + "," + snd() + ")"; 12
4 Problems with mutable objects During the programming, programmers have to keep track of [in their heads] how the mutable objects will change once the program is run. The language syntax does not support this. Well, comments can be written as reminders. Loosing track of the changes easily leads to mistakes and bugs. There are programming languages where mutation is not possible; in those, the problem above does not exist() Haskell Method categories Selector - Returns one part out of a multi-part state. getelement in Vector Predicate - Decides something about an object. isempty in lab 3 Generator - A method that generates a kind of object. Note: A constructor is not a method (you can t call a constructor). Transformer - Changes one object into another. Mutator - Changes the state of an object. (Combinations are possible.) Finite State Machines FSM:s are fundamental A (deterministic) finite state machine (FSM) is a model of behavior composed of a finite number of states, transitions between those states, and actions. A state stores information about the past, i.e. it reflects the input changes from the system start to the present moment. A transition indicates a state change and is described by a condition that would need to be fulfilled to enable the transition. An action is a description of an activity that is to be performed at a given moment. Also known as a finite state automaton. FSM:s are widely used in modeling application behavior, design of hardware digital systems, software engineering, compiler construction, network protocols, and the study of computation and languages. They come in two flavors: Transducers Acceptors 15 16
5 Basic parts and functionality A FSM consists of five parts: A set of states. A start state. A transition function :: (Input,State) -> State. An action function that associates an action with each transition. A set of end states. Each given moment, the machine is in one of the states. At first it is in its start state. The machine then repeatedly reads an input symbol, changes state depending on the transition function, and performs an action as defined by the action function. It stops ( halts ) when an end state is reached. 1. Transducer FSM A FSM that performs actions as it changes state. Action = Both produce output and perform some task. The actions can depend on both the transitions and the states. These are good at describing realtime systems that never should stop. Two different kinds of transducers: The Moore model, and the Mealy model Moore model Moore model Actions depend on state only. Example: An elevator door. 2 commands: "command_open" and "command_close. 2 user inputs: sensor_opened and sensor_closed. 4 states: 1. The entry action (E:) in state "Opening" starts a motor opening the door. When the door is open, a sensor detects this. 2. The entry action in state "Closing" starts a motor in the other direction closing the door. This is also detected by a sensor when the door is shut closed. 3. States "Opened" and 4. "Closed" don't perform any actions. They just signal to the outside world (e.g. to other state machines) the situation: "door is open" or "door is closed". E: stands for an action or output that happens when the state is entered. Input is either a pressed button or a sensor detecting something
6 Mealy Model Actions depend directly on transitions, that is both state and input. There are two input actions (I:): "start motor to close the door if command_close arrives" and "start motor in the other direction to open the door if command_open arrives". Mealy tends to give smaller FSM:s but is harder to implement. Moore is easier to handle (but larger). They are often combined in practice. Fig Fig Water Dispenser Acceptor FSM Figures An acceptor (or recognizer) is a FSM in which each state is labeled either accept or not accept. Also: yes or no. The machine outputs the label at the state reached when all input symbols have been processed. Used to recognize words in a language. Compilers, for example. Example: CypherLock Riley: Last paragraph on p. 167 to p Fig Fig Fig Simple example: Determines whether a binary number has an odd or even number of 0's, where S 1 is an accepting state
7 import javax.swing.*; import java.awt.event.*; public class FsmEmulator implements ActionListener { private CipherButton[] buttons; import javax.swing.jbutton; public class CipherButton extends JButton { private char symbol; public CipherButton(int x, int y, int s, char c) { super(); if (c < 'A' c > 'E') { throw new IllegalArgumentException(); else { setbounds(x, y, s, s); settext(c+""); private int nokeysentered = 0; private int okafter1 = 1, okafter2 = 2, okafter3 = 3; private int failafter1 = 4, failafter2 = 5, failafter3 = 6; private int[][] NextState = { {failafter1, okafter1, failafter1, failafter1, failafter1, {okafter2, failafter2, failafter2, failafter2, failafter2, {okafter3, failafter3, failafter3, failafter3, failafter3, {nokeysentered, nokeysentered, nokeysentered, nokeysentered, nokeysentered, {failafter2, failafter2, failafter2, failafter2, failafter2, {failafter3, failafter3, failafter3, failafter3, failafter3, {nokeysentered, nokeysentered, nokeysentered, nokeysentered, nokeysentered; private StateAction nullaction = new NullAction(); private StateAction soundalarm = new SoundAlarmAction(); private StateAction opendoor = new OpenDoorAction(); private StateAction[][] actiontable = { {nullaction, nullaction, nullaction, nullaction, nullaction, {nullaction, nullaction, nullaction, nullaction, nullaction, {nullaction, nullaction, nullaction, nullaction, nullaction, {soundalarm, soundalarm, soundalarm, opendoor, soundalarm, {nullaction, nullaction, nullaction, nullaction, nullaction, {nullaction, nullaction, nullaction, nullaction, nullaction, {soundalarm, soundalarm, soundalarm, soundalarm, soundalarm; private int currentstate; public FsmEmulator() { JFrame window = new JFrame(); window.setbounds(10, 10, 270, 90); window.getcontentpane().setlayout(null); buttons = new CipherButton[5]; for (int j=0; j = 5; j++) { buttons[j] = new CipherButton(10+j*50, 10, 50, (char)(j+'a')); buttons[j].addactionlistener(this); window.getcontentpane().add(buttons[j]); currentstate = nokeysentered; window.show(); public void actionperformed(actionevent e) { int buttonint = intvalueofbutton(e.getsource()); actiontable[currentstate][buttonint].performaction(); currentstate = NextState[currentState][buttonInt]; VendingMachine Another example implemented using switches. Instead of having matrices that define transitions and actions, here we have code that does this. private int intvalueofbutton(object btn) { return ((CipherButton)btn).getText().charAt(0) - 'A'; 27 28
8 Internal and external methods Using access modifiers, it is possible to limit the scope of declarations. private, public, protected, and package scope (no explicit modifier). We can control access this way. But when the right to access also means a right to shadow, we have to be extra careful as programmers. A final class can not be extended. Examples in Eclipse with SubClass and SubClass Internal and external methods If you like to prevent subclasses from changing the behavior of methods in super classes, separate the API from internal methods that do the work. Make each public method in the API call its corresponding internal (private) method. This is all it does. All the functionality lies in the internal method. Never make internal methods depend on external ones (methods in the API). Only use internal methods in a class. Note that this is a conscious design decision. It could be unsuitable to do it, but most often it is not. Also, note that final on a method prohibits shadowing. 31
Procedural Abstraction
Procedural Abstraction Comp-303 : Programming Techniques Lecture 5 Alexandre Denault Computer Science McGill University Winter 2004 February 16, 2004 Lecture 5 Comp 303 : Programming Techniques Page 1
More informationA Model of Mutation in Java
Object-Oriented Design Lecture 18 CSU 370 Fall 2008 (Pucella) Friday, Nov 21, 2008 A Model of Mutation in Java We have been avoiding mutations until now; but there are there, in the Java system, for better
More informationJAVA MOCK TEST JAVA MOCK TEST II
http://www.tutorialspoint.com JAVA MOCK TEST Copyright tutorialspoint.com This section presents you various set of Mock Tests related to Java Framework. You can download these sample mock tests at your
More informationTopic 7: Algebraic Data Types
Topic 7: Algebraic Data Types 1 Recommended Exercises and Readings From Haskell: The craft of functional programming (3 rd Ed.) Exercises: 5.5, 5.7, 5.8, 5.10, 5.11, 5.12, 5.14 14.4, 14.5, 14.6 14.9, 14.11,
More informationCS 11 java track: lecture 3
CS 11 java track: lecture 3 This week: documentation (javadoc) exception handling more on object-oriented programming (OOP) inheritance and polymorphism abstract classes and interfaces graphical user interfaces
More informationMIT AITI Swing Event Model Lecture 17
MIT AITI 2004 Swing Event Model Lecture 17 The Java Event Model In the last lecture, we learned how to construct a GUI to present information to the user. But how do GUIs interact with users? How do applications
More informationC++ Important Questions with Answers
1. Name the operators that cannot be overloaded. sizeof,.,.*,.->, ::,? 2. What is inheritance? Inheritance is property such that a parent (or super) class passes the characteristics of itself to children
More informationObject-Oriented Design Lecture 11 CS 3500 Spring 2010 (Pucella) Tuesday, Feb 16, 2010
Object-Oriented Design Lecture 11 CS 3500 Spring 2010 (Pucella) Tuesday, Feb 16, 2010 11 Polymorphism The functional iterator interface we have defined last lecture is nice, but it is not very general.
More informationIntroduction to Programming Using Java (98-388)
Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;
More informationFor this section, we will implement a class with only non-static features, that represents a rectangle
For this section, we will implement a class with only non-static features, that represents a rectangle 2 As in the last lecture, the class declaration starts by specifying the class name public class Rectangle
More informationCMPSCI 187: Programming With Data Structures. Lecture 12: Implementing Stacks With Linked Lists 5 October 2011
CMPSCI 187: Programming With Data Structures Lecture 12: Implementing Stacks With Linked Lists 5 October 2011 Implementing Stacks With Linked Lists Overview: The LinkedStack Class from L&C The Fields and
More informationCreating an Immutable Class. Based on slides by Prof. Burton Ma
Creating an Immutable Class Based on slides by Prof. Burton Ma 1 Value Type Classes A value type is a class that represents a value Examples of values: name, date, colour, mathematical vector Java examples:
More informationMidterm assessment - MAKEUP Fall 2010
M257 MTA Faculty of Computer Studies Information Technology and Computing Date: /1/2011 Duration: 60 minutes 1-Version 1 M 257: Putting Java to Work Midterm assessment - MAKEUP Fall 2010 Student Name:
More informationLecture 28. Exceptions and Inner Classes. Goals. We are going to talk in more detail about two advanced Java features:
Lecture 28 Exceptions and Inner Classes Goals We are going to talk in more detail about two advanced Java features: Exceptions supply Java s error handling mechanism. Inner classes ease the overhead of
More informationArray. Multi-dimensional arrays. Fig d"dimensional arrays 3 declarations on page 153. Mentioned in R4.1 and L1.4 Declaration: Creation: Use:
Implementing and representing ADT:S Reily 4 + O6.3 Levitin 1.2, 1.4, 2.5 Array vs. Vector Arrays Multi" dimensional Table"driven code SMD135/167 Lecture 6 Finite State Machines Lab 2 Recursion Implementing
More informationCMSC 330: Organization of Programming Languages. OCaml Imperative Programming
CMSC 330: Organization of Programming Languages OCaml Imperative Programming CMSC330 Spring 2018 1 So Far, Only Functional Programming We haven t given you any way so far to change something in memory
More informationData abstractions: ADTs Invariants, Abstraction function. Lecture 4: OOP, autumn 2003
Data abstractions: ADTs Invariants, Abstraction function Lecture 4: OOP, autumn 2003 Limits of procedural abstractions Isolate implementation from specification Dependency on the types of parameters representation
More informationJava Object Oriented Design. CSC207 Fall 2014
Java Object Oriented Design CSC207 Fall 2014 Design Problem Design an application where the user can draw different shapes Lines Circles Rectangles Just high level design, don t write any detailed code
More informationChapter 5: Procedural abstraction. Function procedures. Function procedures. Proper procedures and function procedures
Chapter 5: Procedural abstraction Proper procedures and function procedures Abstraction in programming enables distinction: What a program unit does How a program unit works This enables separation of
More informationLesson 10B Class Design. By John B. Owen All rights reserved 2011, revised 2014
Lesson 10B Class Design By John B. Owen All rights reserved 2011, revised 2014 Table of Contents Objectives Encapsulation Inheritance and Composition is a vs has a Polymorphism Information Hiding Public
More informationWeek 7 - More Java! this stands for the calling object:
Week 7 - More Java! Variable Scoping, Revisited this Parameter Encapsulation & Principles of Information Hiding: Use of public and private within class API, ADT javadoc Variables of class Type Wrapper
More informationDiscover how to get up and running with the Java Development Environment and with the Eclipse IDE to create Java programs.
Java SE11 Development Java is the most widely-used development language in the world today. It allows programmers to create objects that can interact with other objects to solve a problem. Explore Java
More informationQueens College, CUNY Department of Computer Science. CS 212 Object-Oriented Programming in Java Practice Exam 2. CS 212 Exam 2 Study Guide
Topics for Exam 2: Queens College, CUNY Department of Computer Science CS 212 Object-Oriented Programming in Java Practice Exam 2 CS 212 Exam 2 Study Guide Linked Lists define a list node define a singly-linked
More informationChapter 4 Defining Classes I
Chapter 4 Defining Classes I This chapter introduces the idea that students can create their own classes and therefore their own objects. Introduced is the idea of methods and instance variables as the
More informationReview sheet for Final Exam (List of objectives for this course)
Review sheet for Final Exam (List of objectives for this course) Please be sure to see other review sheets for this semester Please be sure to review tests from this semester Week 1 Introduction Chapter
More informationSubclassing for ADTs Implementation
Object-Oriented Design Lecture 8 CS 3500 Fall 2009 (Pucella) Tuesday, Oct 6, 2009 Subclassing for ADTs Implementation An interesting use of subclassing is to implement some forms of ADTs more cleanly,
More informationName: Checked: Learn about listeners, events, and simple animation for interactive graphical user interfaces.
Lab 15 Name: Checked: Objectives: Learn about listeners, events, and simple animation for interactive graphical user interfaces. Files: http://www.csc.villanova.edu/~map/1051/chap04/smilingface.java http://www.csc.villanova.edu/~map/1051/chap04/smilingfacepanel.java
More informationInheritance (Part 5) Odds and ends
Inheritance (Part 5) Odds and ends 1 Static Methods and Inheritance there is a significant difference between calling a static method and calling a non-static method when dealing with inheritance there
More informationContents. I. Classes, Superclasses, and Subclasses. Topic 04 - Inheritance
Contents Topic 04 - Inheritance I. Classes, Superclasses, and Subclasses - Inheritance Hierarchies Controlling Access to Members (public, no modifier, private, protected) Calling constructors of superclass
More informationCloning Enums. Cloning and Enums BIU OOP
Table of contents 1 Cloning 2 Integer representation Object representation Java Enum Cloning Objective We have an object and we need to make a copy of it. We need to choose if we want a shallow copy or
More informationThis course supports the assessment for Scripting and Programming Applications. The course covers 4 competencies and represents 4 competency units.
This course supports the assessment for Scripting and Programming Applications. The course covers 4 competencies and represents 4 competency units. Introduction Overview Advancements in technology are
More informationProgramming Languages and Techniques (CIS120)
Programming Languages and Techniques (CIS120) Lecture 10 February 2, 2018 Abstract types: Sets Chapter 10 Announcements Homework 3 due Tuesday at 11:59:59pm Midterm 1 Friday, February 9, in class Covers
More informationCMSC 330: Organization of Programming Languages. OCaml Imperative Programming
CMSC 330: Organization of Programming Languages OCaml Imperative Programming CMSC330 Fall 2017 1 So Far, Only Functional Programming We haven t given you any way so far to change something in memory All
More informationChapter 6 Introduction to Defining Classes
Introduction to Defining Classes Fundamentals of Java: AP Computer Science Essentials, 4th Edition 1 Objectives Design and implement a simple class from user requirements. Organize a program in terms of
More informationAP CS Unit 11: Graphics and Events
AP CS Unit 11: Graphics and Events This packet shows how to create programs with a graphical interface in a way that is consistent with the approach used in the Elevens program. Copy the following two
More information6.005 Elements of Software Construction Fall 2008
MIT OpenCourseWare http://ocw.mit.edu 6.005 Elements of Software Construction Fall 2008 For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms. 6.005 elements
More informationClass 16: The Swing Event Model
Introduction to Computation and Problem Solving Class 16: The Swing Event Model Prof. Steven R. Lerman and Dr. V. Judson Harward 1 The Java Event Model Up until now, we have focused on GUI's to present
More informationCSE331 Fall 2014, Final Examination December 9, 2014 Please do not turn the page until 2:30. Rules:
CSE331 Fall 2014, Final Examination December 9, 2014 Please do not turn the page until 2:30. Rules: The exam is closed-book, closed-note, etc. Please stop promptly at 4:20. There are 156 (not 100) points,
More informationComparing and Contrasting different Approaches of Code Generator(Enum,Map-Like,If-else,Graph)
Comparing and Contrasting different Approaches of Generator(Enum,Map-Like,If-else,Graph) Vivek Tripathi 1 Sandeep kumar Gonnade 2 Mtech Scholar 1 Asst.Professor 2 Department of Computer Science & Engineering,
More informationSubclass Gist Example: Chess Super Keyword Shadowing Overriding Why? L10 - Polymorphism and Abstract Classes The Four Principles of Object Oriented
Table of Contents L01 - Introduction L02 - Strings Some Examples Reserved Characters Operations Immutability Equality Wrappers and Primitives Boxing/Unboxing Boxing Unboxing Formatting L03 - Input and
More informationMidterms Save the Dates!
University of British Columbia CPSC 111, Intro to Computation Alan J. Hu (Using the Scanner and String Classes) Anatomy of a Java Program Readings This Week s Reading: Ch 3.1-3.8 (Major conceptual jump
More informationDefensive Programming
Defensive Programming Software Engineering CITS1220 Based on the Java1200 Lecture notes by Gordon Royle Lecture Outline Why program defensively? Encapsulation Access Restrictions Documentation Unchecked
More informationRecursion. What is Recursion? Simple Example. Repeatedly Reduce the Problem Into Smaller Problems to Solve the Big Problem
Recursion Repeatedly Reduce the Problem Into Smaller Problems to Solve the Big Problem What is Recursion? A problem is decomposed into smaller sub-problems, one or more of which are simpler versions of
More informationCS 251 Intermediate Programming Methods and Classes
CS 251 Intermediate Programming Methods and Classes Brooke Chenoweth University of New Mexico Fall 2018 Methods An operation that can be performed on an object Has return type and parameters Method with
More informationCS 251 Intermediate Programming Methods and More
CS 251 Intermediate Programming Methods and More Brooke Chenoweth University of New Mexico Spring 2018 Methods An operation that can be performed on an object Has return type and parameters Method with
More informationMonads. Functional Programming (CS4011) Monads
Monads Functional Programming (CS4011) Andrew Butterfield Glenn Strong Foundations & Methods Group, Discipline of Software Systems Trinity College, University of Dublin {Andrew.Butterfield,Glenn.Strong}@cs.tcd.ie
More informationIndex COPYRIGHTED MATERIAL
Index COPYRIGHTED MATERIAL Note to the Reader: Throughout this index boldfaced page numbers indicate primary discussions of a topic. Italicized page numbers indicate illustrations. A abstract classes
More informationCS3500: Object-Oriented Design Fall 2013
CS3500: Object-Oriented Design Fall 2013 Class 3 9.13.2013 Plan for Today Web-CAT Announcements Review terminology from last class Finish Recipe implementation of StackInt as a class Abstraction Barrier
More informationSide Effects (3A) Young Won Lim 1/13/18
Side Effects (3A) Copyright (c) 2016-2018 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later
More informationLab 5 Random numbers!
Lab 5 Random numbers! ADT:s as Programming Tools! D0010E! Lecture 13! Iterators! MasterMind Reminder: Groups must have their designs approved before any actual programming is allowed to start. Some review
More information3 ADT Implementation in Java
Object-Oriented Design Lecture 3 CS 3500 Spring 2010 (Pucella) Tuesday, Jan 19, 2010 3 ADT Implementation in Java Last time, we defined an ADT via a signature and a specification. We noted that the job
More informationInf1-OP. Inf1-OP Exam Review. Timothy Hospedales, adapting earlier version by Perdita Stevens and Ewan Klein. March 20, School of Informatics
Inf1-OP Inf1-OP Exam Review Timothy Hospedales, adapting earlier version by Perdita Stevens and Ewan Klein School of Informatics March 20, 2017 Overview Overview of examinable material: Lectures Week 1
More informationCS 1302 Chapter 9 (Review) Object & Classes
CS 1302 Chapter 9 (Review) Object & Classes Reference Sections 9.2-9.5, 9.7-9.14 9.2 Defining Classes for Objects 1. A class is a blueprint (or template) for creating objects. A class defines the state
More informationhttps://asd-pa.perfplusk12.com/admin/admin_curric_maps_display.asp...
1 of 8 8/27/2014 2:15 PM Units: Teacher: ProgIIIAPCompSci, CORE Course: ProgIIIAPCompSci Year: 2012-13 Computer Systems This unit provides an introduction to the field of computer science, and covers the
More informationSINGLE EVENT HANDLING
SINGLE EVENT HANDLING Event handling is the process of responding to asynchronous events as they occur during the program run. An event is an action that occurs externally to your program and to which
More informationIntroduction to Programming System Design CSCI 455x (4 Units)
Introduction to Programming System Design CSCI 455x (4 Units) Description This course covers programming in Java and C++. Topics include review of basic programming concepts such as control structures,
More informationThread Safety. Review. Today o Confinement o Threadsafe datatypes Required reading. Concurrency Wrapper Collections
Thread Safety Today o Confinement o Threadsafe datatypes Required reading Concurrency Wrapper Collections Optional reading The material in this lecture and the next lecture is inspired by an excellent
More informationIntroduction to Concepts in Functional Programming. CS16: Introduction to Data Structures & Algorithms Spring 2017
Introduction to Concepts in Functional Programming CS16: Introduction to Data Structures & Algorithms Spring 2017 Outline Functions State Functions as building blocks Higher order functions Map Reduce
More informationF1 A Java program. Ch 1 in PPIJ. Introduction to the course. The computer and its workings The algorithm concept
F1 A Java program Ch 1 in PPIJ Introduction to the course The computer and its workings The algorithm concept The structure of a Java program Classes and methods Variables Program statements Comments Naming
More informationMutable Data Types. Prof. Clarkson Fall A New Despair Mutability Strikes Back Return of Imperative Programming
Mutable Data Types A New Despair Mutability Strikes Back Return of Imperative Programming Prof. Clarkson Fall 2017 Today s music: The Imperial March from the soundtrack to Star Wars, Episode V: The Empire
More informationCS-202 Introduction to Object Oriented Programming
CS-202 Introduction to Object Oriented Programming California State University, Los Angeles Computer Science Department Lecture III Inheritance and Polymorphism Introduction to Inheritance Introduction
More informationCSE 70 Final Exam Fall 2009
Signature cs70f Name Student ID CSE 70 Final Exam Fall 2009 Page 1 (10 points) Page 2 (16 points) Page 3 (22 points) Page 4 (13 points) Page 5 (15 points) Page 6 (20 points) Page 7 (9 points) Page 8 (15
More informationPrinciples of Software Construction: Objects, Design and Concurrency. Mutability and Java Potpourri. toad Fall 2013
Principles of Software Construction: Objects, Design and Concurrency Mutability and Java Potpourri 15-214 toad Fall 2013 Jonathan Aldrich Charlie Garrod School of Computer Science 2012-13 C Garrod, J Aldrich,
More informationFall 2017 CISC124 10/1/2017
CISC124 Today First onq quiz this week write in lab. More details in last Wednesday s lecture. Repeated: The quiz availability times will change to match each lab as the week progresses. Useful Java classes:
More informationChief Reader Report on Student Responses:
Chief Reader Report on Student Responses: 2017 AP Computer Science A Free-Response Questions Number of Students Scored 60,519 Number of Readers 308 Score Distribution Exam Score N %At Global Mean 3.15
More informationProject Compiler. CS031 TA Help Session November 28, 2011
Project Compiler CS031 TA Help Session November 28, 2011 Motivation Generally, it s easier to program in higher-level languages than in assembly. Our goal is to automate the conversion from a higher-level
More informationLecture 4. Lecture
Interfaces Classes Building blocks Methods Arrays Example: BitArray Packages D0010E Object- Oriented Programming and Design InformaGon hiding Graphics and interacgon Example: A blinking signal Access Modifiers
More informationQUIZ. What is wrong with this code that uses default arguments?
QUIZ What is wrong with this code that uses default arguments? Solution The value of the default argument should be placed in either declaration or definition, not both! QUIZ What is wrong with this code
More informationCS Exam 1 Review Suggestions
CS 235 - Fall 2015 - Exam 1 Review Suggestions p. 1 last modified: 2015-09-30 CS 235 - Exam 1 Review Suggestions You are responsible for material covered in class sessions, lab exercises, and homeworks;
More informationDefining Classes and Methods
Defining Classes and Methods Chapter 5 Modified by James O Reilly Class and Method Definitions OOP- Object Oriented Programming Big Ideas: Group data and related functions (methods) into Objects (Encapsulation)
More informationLecture 8: Summary of Haskell course + Type Level Programming
Lecture 8: Summary of Haskell course + Type Level Programming Søren Haagerup Department of Mathematics and Computer Science University of Southern Denmark, Odense October 31, 2017 Principles from Haskell
More informationSwing - JButton. Adding buttons to the main window
Swing - JButton Adding buttons to the main window An empty JFrame is not very useful // In some GUI class: window = new JFrame("Window example"); window.setsize(800,600); window.setdefaultcloseoperation(jframe.exit_on_close);
More informationStatic Vulnerability Analysis
Static Vulnerability Analysis Static Vulnerability Detection helps in finding vulnerabilities in code that can be extracted by malicious input. There are different static analysis tools for different kinds
More informationWeiss Chapter 1 terminology (parenthesized numbers are page numbers)
Weiss Chapter 1 terminology (parenthesized numbers are page numbers) assignment operators In Java, used to alter the value of a variable. These operators include =, +=, -=, *=, and /=. (9) autoincrement
More informationLecture 5: Implementing Lists, Version 1
CS18 Integrated Introduction to Computer Science Fisler, Nelson Lecture 5: Implementing Lists, Version 1 Contents 1 Implementing Lists 1 2 Methods 2 2.1 isempty...........................................
More informationIntroduction to Software Testing Chapter 2, Sec#: 2.5 Graph Coverage for Specifications
Introduction to Software Testing Chapter 2, Sec#: 2.5 Graph Coverage for Specifications Paul Ammann & Jeff Offutt http://www.cs.gmu.edu/~offutt/softwa retest/ Design Specifications A design specification
More informationAssertions, pre/postconditions
Programming as a contract Assertions, pre/postconditions Assertions: Section 4.2 in Savitch (p. 239) Specifying what each method does q Specify it in a comment before method's header Precondition q What
More informationData Structures (list, dictionary, tuples, sets, strings)
Data Structures (list, dictionary, tuples, sets, strings) Lists are enclosed in brackets: l = [1, 2, "a"] (access by index, is mutable sequence) Tuples are enclosed in parentheses: t = (1, 2, "a") (access
More informationJVM ByteCode Interpreter
JVM ByteCode Interpreter written in Haskell (In under 1000 Lines of Code) By Louis Jenkins Presentation Schedule ( 15 Minutes) Discuss and Run the Virtual Machine first
More informationFinal Exam. Programming Assignment 3. University of British Columbia CPSC 111, Intro to Computation Alan J. Hu. Readings
University of British Columbia CPSC 111, Intro to Computation Alan J. Hu Interfaces vs. Inheritance Abstract Classes Inner Classes Readings This Week: No new readings. Consolidate! (Reminder: Readings
More informationCS 231 Data Structures and Algorithms, Fall 2016
CS 231 Data Structures and Algorithms, Fall 2016 Dr. Bruce A. Maxwell Department of Computer Science Colby College Course Description Focuses on the common structures used to store data and the standard
More informationAbout this exam review
Final Exam Review About this exam review I ve prepared an outline of the material covered in class May not be totally complete! Exam may ask about things that were covered in class but not in this review
More informationProtocols and Finite State Machines
Lecture1-intro+PMM.nb 1 Slide 1 of 75 Protocols and Finite State Machines Dr. Yehuda Ben-Shimol 2 Course Overview Slide 2 of 75 Ê Major topics Ë Formal methods for describing communication protocols -
More informationExample: Fibonacci Numbers
Example: Fibonacci Numbers Write a program which determines F n, the (n + 1)-th Fibonacci number. The first 10 Fibonacci numbers are 0, 1, 1, 2, 3, 5, 8, 13, 21, and 34. The sequence of Fibonacci numbers
More informationCS 315 Software Design Homework 3 Preconditions, Postconditions, Invariants Due: Sept. 29, 11:30 PM
CS 315 Software Design Homework 3 Preconditions, Postconditions, Invariants Due: Sept. 29, 11:30 PM Objectives Defining a wellformed method to check class invariants Using assert statements to check preconditions,
More informationSymbol Tables Symbol Table: In computer science, a symbol table is a data structure used by a language translator such as a compiler or interpreter, where each identifier in a program's source code is
More informationGraphical User Interface (Part-1) Supplementary Material for CPSC 233
Graphical User Interface (Part-1) Supplementary Material for CPSC 233 Introduction to Swing A GUI (graphical user interface) is a windowing system that interacts with the user The Java AWT (Abstract Window
More informationClasses Classes 2 / 36
Classes 1 / 36 Classes Classes 2 / 36 Anatomy of a Class By the end of next lecture, you ll understand everything in this class definition. package edu. gatech. cs1331. card ; import java. util. Arrays
More informationGraphical Interface and Application (I3305) Semester: 1 Academic Year: 2017/2018 Dr Antoun Yaacoub
Lebanese University Faculty of Science Computer Science BS Degree Graphical Interface and Application (I3305) Semester: 1 Academic Year: 2017/2018 Dr Antoun Yaacoub 2 Crash Course in JAVA Classes A Java
More informationSurvey #2. Programming Assignment 3. University of British Columbia CPSC 111, Intro to Computation Alan J. Hu. Readings
University of British Columbia CPSC 111, Intro to Computation Alan J. Hu Defining Interfaces Intro to Inheritance Readings This Week: Ch 9.4-9.5 and into Ch 10.1-10.8 (Ch 11.4-11.5 and into Ch 13 in old
More informationModule 10A Lecture - 20 What is a function? Why use functions Example: power (base, n)
Programming, Data Structures and Algorithms Prof. Shankar Balachandran Department of Computer Science and Engineering Indian Institute of Technology, Madras Module 10A Lecture - 20 What is a function?
More informationEncapsulation. Administrative Stuff. September 12, Writing Classes. Quick review of last lecture. Classes. Classes and Objects
Administrative Stuff September 12, 2007 HW3 is due on Friday No new HW will be out this week Next Tuesday we will have Midterm 1: Sep 18 @ 6:30 7:45pm. Location: Curtiss Hall 127 (classroom) On Monday
More information(Refer Slide Time: 4:00)
Principles of Programming Languages Dr. S. Arun Kumar Department of Computer Science & Engineering Indian Institute of Technology, Delhi Lecture - 38 Meanings Let us look at abstracts namely functional
More informationCSE 143: Computer Programming II Summer 2015 HW6: 20 Questions (due Thursday, August 13, :30pm)
CSE 143: Computer Programming II Summer 2015 HW6: 20 Questions (due Thursday, August 13, 2015 11:30pm) This assignment focuses on binary trees and recursion. Turn in the following files using the link
More informationCOP 3330 Final Exam Review
COP 3330 Final Exam Review I. The Basics (Chapters 2, 5, 6) a. comments b. identifiers, reserved words c. white space d. compilers vs. interpreters e. syntax, semantics f. errors i. syntax ii. run-time
More informationObject-Oriented Programming (OOP) Fundamental Principles of OOP
Object-Oriented Programming (OOP) O b j e c t O r i e n t e d P r o g r a m m i n g 1 Object-oriented programming is the successor of procedural programming. The problem with procedural programming is
More informationObject Oriented Programming is a programming method that combines: Advantage of Object Oriented Programming
Overview of OOP Object Oriented Programming is a programming method that combines: a) Data b) Instructions for processing that data into a self-sufficient object that can be used within a program or in
More informationPatterns and Testing
and Lecture # 7 Department of Computer Science and Technology University of Bedfordshire Written by David Goodwin, based on the lectures of Marc Conrad and Dayou Li and on the book Applying UML and (3
More informationG Programming Languages - Fall 2012
G22.2110-003 Programming Languages - Fall 2012 Lecture 2 Thomas Wies New York University Review Last week Programming Languages Overview Syntax and Semantics Grammars and Regular Expressions High-level
More informationC++ Inheritance and Encapsulation
C++ Inheritance and Encapsulation Protected members Inheritance Type Public Inheritance Private Inheritance Protected Inheritance Special method inheritance Private vs. Protected Private: private members
More information