CS18000: Programming I Final Exam 8 May 8am-10am Lilly Functional Abstraction. Functional Specification. CS18000: Programming I 4/28/2010

Size: px
Start display at page:

Download "CS18000: Programming I Final Exam 8 May 8am-10am Lilly Functional Abstraction. Functional Specification. CS18000: Programming I 4/28/2010"

Transcription

1 CS18000: Programming I Final Exam 8 May 8am-10am Lilly 1105 Review 26 April 2010 Prof. Chris Clifton What You ve (hopefully) Learned Functional Abstraction Recursion Data Abstraction Classes as data types Polymorphism, Inheritance I/O as Abstract Data Concurrent Execution Threads Exception Handling Synchronization Putting it all together: Projects involving Visualization Interfaces Networking 4/28/2010 CS Abstraction: How Programming Scales Functional Abstraction Clear specification of what a function does Don t sweat the details of How something is done Data Abstraction Clear specification of what something is Don t worry about how it is represented Functional Abstraction Function provides a capability We use that capability We don t care how it is done! What do we care about? Input required Output produced 4/28/2010 CS /28/2010 CS Input Number of inputs Data type Permissible values Preconditions Meaning Functional Specification Output Number of outputs (is input changed)? Data type Permissible values Postconditions Meaning Data Abstraction: What makes a data type? Semantics: What is being represented not how What we can do with it Functional abstractions Constraints Can all operations be applied to any object of the type? Can an object be modified? Special values constants 4/28/2010 CS /28/2010 CS Chris Clifton 1

2 Type: (semi)formal Definition Domain: Set of possible values Infinite? Operations Constructor Field Access Methods Accessor, Mutator Invariants Must be true at completion of every operation Type: Implementation as Class Representation Must represent all possible domain values Operations Define Constructor(s) Define methods Invariants Ensure invariants hold after execution of Constructor(s), methods 4/28/2010 CS /28/2010 CS Goal: Separate Abstraction and Implementation Using an Abstract Data Type Know what it is / what it does How isn t important Once defined, can use Doesn t need to be implemented (okay, we can t run the program but we can write a program using it) Java interface Defines an (abstract) data type Javaspeak: reference type Declares Constants (static final variables) Method type, name, and parameters Assumed to be public No constructor(s) Cannot construct an instance of an interface 4/28/2010 CS /28/2010 CS Inheritance Define a new class that extends an existing class 1. Same interface (just like using an Interface) 2. Same methods 3. Same representation Three separate concepts But unfortunately not independent 4/28/2010 CS Extending the Interface Child class must support all features of parent Just like implementing an interface Key difference: Some features already implemented Can be used anywhere parent class can be used Just like an interface Can define new fields and methods But can t be used if the type is the parent class Just like an interface 4/28/2010 CS Chris Clifton 2

3 Extending the Methods (name) Overloading Overriding methods If instance of child, use child (even if you think you have parent) Gate g = new Not(); g.getvalue() will use method from Not class Caveat: Class methods (static) not overridden The one you get depends on the type of object 4/28/2010 CS Two Java methods can share a name Which is which? Signature: Method identified by type (class), name, and type/number of arguments Can do for any method Use sparingly, can be confusing 4/28/2010 CS Using methods from Parent Non-overridden methods easy Just use example in Not Overridden methods accessed using super keyword kind of like this Constructor of parent must be called in constructor Exception: Default parent constructor (no arguments) called automatically before child constructor if you don t Extending the Representation Child class gets all fields of parent class Can access those not declared private or protected Best to access through parent methods Can add new fields Also hide existing by using same name Bad idea works like class methods: Which you get depends on type 4/28/2010 CS /28/2010 CS Putting it all together: Inheritance Three concepts: 1. Inherit the interface 2. Inherit the methods 3. Inherit the representation Use inheritance (extends) when you want all three If you just want interface, use interface/implements If you just want methods, create as an instance variable What if we don t know the class? Class getclass() defined for all objects Every class (automatically) inherits from Class object Class has several useful methods String getname(); Class getsuperclass(); boolean isinstance(object obj); if(g.getclass().getname().equals( UnaryOperator )) power( (UnaryOperator) g ); 4/28/2010 CS /28/2010 CS Chris Clifton 3

4 Caveats Solution: Generics getclass() can be used as a crutch for bad design It should be used only when you can t find a better way Try to compare Class objects, not names In a large system, same name can be used multiple places (class defined inside a class) What if we want to support many types? But only one at a time Generics: Parameter attached to a type Queue<Integer>, Queue<String> instead of IntegerQueue, StringQueue One class (Messy) alternative: ObjectQueue use getclass() to enforce single type 4/28/2010 CS /28/2010 CS Error Handling Handling an Exception 0 Let it crash 1. Preconditions forbid misuse May be okay for programmers But what about user input? 2. Error return code Check if empty If it is, return special value Only works if the return type has room for error codes bs = Stack<boolean>; 3. Exceptions End function without return ing Method can t return normally You won t be able to used a returned result Instead, continue someplace else try { catch So what is an EmptyPop? A type (Class) that extends Exception Stack<boolean> s; try { boolean result = s.pop(); if (result) { else { catch (EmptyPop e) { /* Whatever you want to do if the stack was empty */ 4/28/2010 CS /28/2010 CS Declaring an Exception Generating an Exception To use an exception you must pick one or define your own Can extend Exception without doing anything Gives a unique name for your exception Or can add information Reason it was generated If specific to a class, make it a nested class Stack.EmptyPop interface Stack<E> { public class EmptyPop extends Exception { ; void push (E item); E pop() throws EmptyPop; /* Precondition:!isEmpty(); */ boolean isempty; First, create an instance of the exception May contain error message Sample of the bad input Then throw it public E pop() throws EmptyPop { if (isempty()) throw new EmptyPop(); E result = top; top = rest.top; rest = rest.rest; return result; 4/28/2010 CS /28/2010 CS Chris Clifton 4

5 Do use In unexpected situations No meaningful return value Can t recover/process inside a method Doesn t make sense to continue after failed method call When to use exceptions (guidelines) Don t use Under normal conditions Possible to return something sensible Possible to recover and complete method The next steps are the same regardless of the exception Concurrency: Model program as Tasks Multiple (independent) tasks Each is its own program All run (apparently) simultaneously Programming in Java: Thread class Task becomes an instance of a Thread Number of threads matches number of tasks Need not match number of processors/cores In practice: task is an instance of a class inheriting from thread 4/28/2010 CS /28/2010 CS Running a task: Steps Initialize the task Constructor Method calls Do as little work as possible Start the task Begins concurrent execution Thread has to know what to do (no arguments passed in) Make results available run() cannot return results but instance (and its fields/methods) stays around 4/28/2010 CS What happens t.start() causes two programs to run The program calling t.start() the run() method inside instance t What if we don t have enough processors? Scheduler chooses which to run Periodically stops one to let another run We have little control over what runs 4/28/2010 CS Communicating with Threads So far: Task is initialized, runs, results available Nice model for functions Problem: What if task needs to know things in the middle? Video game: move other objects task needs to know if player has moved Solution: Synchronization Allow concurrency But limit when needed Once account has given one ATM the balance, it doesn t respond to the other until the balance is updated Why isn t this easy? At least when we don t deal with the real world 4/28/2010 CS /28/2010 CS Chris Clifton 5

6 Why is this hard? Synchronization Theory Concurrent system architecture Two things really can happen at once! How do you control which gets to memory? CPU Cache Operations: Read or Write Bus Memory CPU Cache Semaphores Test value and set in one operation if (! semaphore) semaphore=true; Only use resource after testing and setting semaphore Full version: counter if (semaphore > 0) semaphore -= 1; Monitors Protected block of code Can t be executed concurrently Perform critical operations in monitor Don t leave until done Different threads can call the monitor But won t start until previous one done. 4/28/2010 CS /28/2010 CS Doing this in Java: synchronized A synchronized method is a monitor public synchronized void updatebalance (int amount) throws insufficientfunds { if (amount > balance) throw new insufficientfunds(); balance = balance amount; Synchronization is on a per-object basis Can run same method concurrently for different objects Cannot run two synchronized methods concurrently on the same object Also synchronize block of code on object of choice synchronized(semaphore) { Concurrency: Coordination Synchronized blocks others until we are done What if we need another task to finish before we can complete? Example: Waiting for ATM to dispensecash(); Solution: wait(); Used in synchronized code Allows others to use that object but we stop They call notify() or notifyall() when done 4/28/2010 CS /28/2010 CS Wait Method in the Object class Can call wait() from any object, or on any object. Call wait() only in synchronized block for that object Synchronized method of that instance Synchronized(theInstance) { theinstance.wait(); Synchronized static method of class Gives up synchronization Other threads can use that object, even though we are still in synchronized block 4/28/2010 CS Wait Current thread will stop until notify() is called on that object Thread resumes when nobody else is in synchronized block for object Can also interrupt thread that is waiting interrupt() is method in Thread class causes wait() to throws InterruptedException Wait with timeout wait(long milliseconds); wait(long milliseconds, int nanoseconds); Returns on notify OR timeout 4/28/2010 CS Chris Clifton 6

7 Notify Method in the Object class Call notify() only in synchronized block for that object Synchronized method of that instance Synchronized(theInstance) { theinstance.notify(); Synchronized static method of class Otherwise you ll get an IllegalMonitorStateException Waiting thread resumes when notifying thread leaves Synchronized block/method NotifyAll all compete to start Recommendations on use Remember that concurrency / synchronization doesn t hold while you wait Make sure it is okay for someone else to be using / modifying the waiting instance. Make sure the wait is on the right object Synchronized(lock) { wait(); waits for notify on instance of current method, not on lock Make sure you SHOULD be awake Synchronized(lock) { while (! lock.readytocontinue() ) lock.wait(); 4/28/2010 CS /28/2010 CS Common Errors: Concurrency Race conditions Two threads try to change the same data Challenge: May not happen the same way every time! Make sure you use synchronized properly Deadlock/Livelock Thread in a synchronized block calls another synchronized block But that is in use by a thread trying to use the first Sequential execution Over-use of synchronized blocks EntryForm Done Name Number Event-Based Programming (Example: GUIs) Jbutton Done JTextField Name JTextField Number Panel JLabel Name 4/28/2010 CS /28/2010 CS Components with actions Component isn t just about looking good Needs to accept (user) interaction Acting on the component generates Event MouseEvent button press, release; enter object; leave object KeyEvent Key Pressed, Key Released But how do we find out about the event? Event-Based Programming Component has listener waits for event to occur executes method when it does Easy to use simply define appropriate methods But need to be careful Think like concurrent programs 4/28/2010 CS /28/2010 CS Chris Clifton 7

8 ActionListener Using a listener Listen for event When event occurs, method in listener will be executed This method can do whatever is needed ActionListener is an Interface Requires one method: actionperformed(actionevent e); You define class with appropriate actionperformed 4/28/2010 CS Must add listener to the object What events cause action set by the object Listener can also look at the event to decide what action should be Some objects may have multiple listeners JButton text disabled? NoticeEvent name a NoticeEvent name b ActionListener 4/28/2010 CS Question: Are GUIs really concurrent? It seems like things are just happening Similar to concurrent threads Program doesn t end without window finishing Similar to concurrent threads Is it really the same? Exercise: Test and find out Files: Stream of Data Values written sequentially Write the value of name Write the value of address Write the next name Read in same order Read name Read address 4/28/2010 CS /28/2010 CS History First storage devices were tape drives Inherently sequential Does this still make sense? Direct Access Storage Device Can move to anyplace But faster in sequence Why sequentially? 4/28/2010 CS Stream as an Abstraction Many devices good at sequential access Tape drive Telephone line Satellite link Fewer good at truly random access Disks read a block, not individual byte Even then, sequential blocks faster USB flash drive seems random access But designed to give a block of sequential data per request Best if you need the whole thing And then there is concurrent access 4/28/2010 CS Chris Clifton 8

9 (Generic) Stream Operations Buffered I/O open Make ready for reading (at beginning), writing (at beginning or at end) Generally done by a Stream constructor in Java read / write Get data from stream or put data on stream skip Move ahead (or back) some distance in stream Equivalent to reading and throwing away what is read reset Move to beginning of stream flush Make sure data sent to stream Used only when writing close Make sure data sent to stream Stream can t be used without open ing again Others may use stream Stream reads an entire block (or more) Saves it in memory When you ask for the next byte, you get it When you ask for a byte that isn t there, get the next block Dramatic performance improvements But not always invisible to program 4/28/2010 CS /28/2010 CS Network I/O Network connection is a stream One end writes data (OutputStream) Other end reads data (InputStream) Some network connections have both Can use higher-level abstractions Scanner Printwriter Network I/O: Socket Endpoint of network stream Analogous to File class (but not quite) FileInputStream constructed using a File Socket has getinputstream(), getoutputstream() new Socket( 80); Creates a (2-way) connection to given address 4/28/2010 CS /28/2010 CS Network I/O: Server What if we don t know who will connect? E.g., web server Solution: Listener new ServerSocket(80); // Listen on port 80 accept() method waits returns a Socket when someone connects Linked Data Structures Array: List of pointers to contained objects lset: aset: n: abc i: 3 n: hjk i: 2 n: dc i: 3 n: abc i: 25 n: def i: 7 Alternative: Object has pointer to next contained object! 4/28/2010 CS /28/2010 CS Chris Clifton 9

10 What goes in a Linked Data Structure? Contents of one cell Instance variables for object Pointer to an object Data Pointer to next object Instance of your own class Data Null value for this variable means end Can even have multiple next objects Data Data Recursion Idea: break a problem down into small, similar sub-problems Write a method to solve first Call that method to solve next Sounds similar to a loop Same basic effect But often an easier way to conceptualize the solution 4/28/2010 CS /28/2010 CS Save what is left to do Call (recursive) method public static int factorial( int n ) { if ( n==1 ) return 1; else return n * factorial( n-1 ); factorial(3) Visualizing Recursion: Call Stack factorial(3) return 3 * factorial(2) factorial(2) return 2 * factorial(1) factorial(1) return Exceptions as a Programming Technique Difficulties with Dynamic Data Structures: Removing self Solution 1: Violate Encapsulation Operate on your child Move child to self Solution 2: Exceptions LinkedSet s = item5 item4 item2 item1 item3 4/28/2010 CS /28/2010 CS Idea: Inform Parent Tell parent to eliminate us Parent has called us with recursive call Return new head void remove(item); Should it be LinkedSet<E> remove(e item);? Does this make sense if nothing changed? What if we want to return (for example) the removed item? Solution: throw exception Exception has information parent needs to know 4/28/2010 CS Loops Off-by-one Infinite Zero Arrays Out-of-bounds Uninitialized objects Scope int i=0; void func() { for (int i=0; i<5; i++) i+=1; // What is i? Testing and Debugging: Common Errors Equivalence Testing == tests if same object.equals() tests if objects same Failure to initialize Null pointer exception Numeric Errors Precision Overflow/Underflow Casting 4/28/2010 CS Chris Clifton 10

11 Types of Testing Black-Box Tests Black-Box Testing Based purely on program specifications White-Box Testing Exercise the code (as written) Regression Testing Re-run tests when changes made 4/28/2010 CS Boundary Value Testing If known ranges of inputs, test at ends of ranges Both inside and outside of bounds Equivalence Partitioning Choose one (or more) from a group of functionally similar values All-Pairs Testing Test different pairs of input values Fuzz Testing Random choices of (potentially unlikely) values 4/28/2010 CS White-Box Tests Branch Testing Make sure every statement is exercised Ensure each side of a decision (if-then or loop) is taken Loop Testing Like boundary case testing for loops All-Paths testing Make sure every path through the program is tested Gets to be very expensive Exponential growth in number of cases Testing Scope System Testing Test the entire program And the environment the system runs in Unit Testing Test individual modules Use skeletons / stub procedures, Driver code Integration Testing Test interfaces between units 4/28/2010 CS /28/2010 CS Package: Namespace Class names are unique in a package Different packages can use the same class names real class name is package.class datastructures.set<recipe>.add(r); Within a package, don t need package name Assumed to refer to current package 4/28/2010 CS Declaring a package Put package name at top of every file package datastructures; Naming Conventions All lowercase Companies use domain name in reverse Use _ in place of things that don t work or after reserved words, e.g. int_. has no special meaning java.awt and java.awt.event separate packages Just a convention that they have something in common 4/28/2010 CS Chris Clifton 11

CS18000: Programming I

CS18000: Programming I CS18000: Programming I Synchronization 22 February, 2010 Prof. Chris Clifton Concurrency Example: Banking class ATM { public void withdrawcash(acct a) { Scanner sc = new Scanner(System.in); int amount

More information

CS18000: Problem Solving And Object-Oriented Programming

CS18000: Problem Solving And Object-Oriented Programming CS18000: Problem Solving And Object-Oriented Programming Data Abstraction: Inheritance 7 March 2011 Prof. Chris Clifton Data Abstraction Continued Abstract data type provides Well-defined interface Separation

More information

CS18000: Programming I

CS18000: Programming I CS18000: Programming I File I/O 22 March, 2010 Prof. Chris Clifton Goal: Make Data Useful Beyond Program Execution Program data stored in variables Okay, a little more than that Arrays Linked data structures

More information

Announcements. CS18000: Problem Solving And Object-Oriented Programming

Announcements. CS18000: Problem Solving And Object-Oriented Programming Announcements Exam 1 Monday, February 28 Wetherill 200, 4:30pm-5:20pm Coverage: Through Week 6 Project 2 is a good study mechanism Final Exam Tuesday, May 3, 3:20pm-5:20pm, PHYS 112 If you have three or

More information

CS18000: Problem Solving and Object-Oriented Programming

CS18000: Problem Solving and Object-Oriented Programming CS18000: Problem Solving and Object-Oriented Programming Recursion 28 March 2011 Prof. Chris Clifton Recursion Idea: break a problem down into small, similar sub-problems Write a method to solve first

More information

CS18000: Programming I

CS18000: Programming I CS18000: Programming I Data Abstraction January 25, 2010 Prof. Chris Clifton Announcements Book is available (Draft 2.0) Syllabus updated with readings corresponding to new edition Lab consulting hours

More information

CS18000: Programming I

CS18000: Programming I CS18000: Programming I Dynamic Data Structures 12 April 2010 Prof. Chris Clifton More on Dynamic Data Structures Difficulties with Dynamic Data Structures: Removing self Solution 1: Violate Encapsulation

More information

CS18000: Programming I

CS18000: Programming I CS18000: Programming I Linked Data Structures 5 April 2010 Prof. Chris Clifton Multiple Items: Beyond Arrays interface Set { boolean contains(e item); /* true iff x s.t. item.equals(x) */ void add(e

More information

Review sheet for Final Exam (List of objectives for this course)

Review 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 information

Chapter 4 Defining Classes I

Chapter 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 information

CS61B, Spring 2003 Discussion #17 Amir Kamil UC Berkeley 5/12/03

CS61B, Spring 2003 Discussion #17 Amir Kamil UC Berkeley 5/12/03 CS61B, Spring 2003 Discussion #17 Amir Kamil UC Berkeley 5/12/03 Topics: Threading, Synchronization 1 Threading Suppose we want to create an automated program that hacks into a server. Many encryption

More information

CS180 Spring 2010 Exam 2 Solutions, 29 March, 2010 Prof. Chris Clifton

CS180 Spring 2010 Exam 2 Solutions, 29 March, 2010 Prof. Chris Clifton CS180 Spring 2010 Exam 2 Solutions, 29 March, 2010 Prof. Chris Clifton Turn Off Your Cell Phone. Use of any electronic device during the test is prohibited. Time will be tight. If you spend more than the

More information

CS18000: Programming I

CS18000: Programming I CS18000: Programming I Testing Basics 19 April 2010 Prof. Chris Clifton Testing Programs Your programs are getting large and more complex How do you make sure they work? 1. Reason about the program Think

More information

Introduction to Programming Using Java (98-388)

Introduction 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 information

Thread Safety. Review. Today o Confinement o Threadsafe datatypes Required reading. Concurrency Wrapper Collections

Thread 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 information

Classes, interfaces, & documentation. Review of basic building blocks

Classes, interfaces, & documentation. Review of basic building blocks Classes, interfaces, & documentation Review of basic building blocks Objects Data structures literally, storage containers for data constitute object knowledge or state Operations an object can perform

More information

Concurrent Programming using Threads

Concurrent Programming using Threads Concurrent Programming using Threads Threads are a control mechanism that enable you to write concurrent programs. You can think of a thread in an object-oriented language as a special kind of system object

More information

1 Looping Constructs (4 minutes, 2 points)

1 Looping Constructs (4 minutes, 2 points) Name: Career Account ID: Recitation#: 1 CS180 Spring 2011 Final Exam, 3 May, 2011 Prof. Chris Clifton Turn Off Your Cell Phone. Use of any electronic device during the test is prohibited. Time will be

More information

CSE332: Data Abstractions Lecture 23: Programming with Locks and Critical Sections. Tyler Robison Summer 2010

CSE332: Data Abstractions Lecture 23: Programming with Locks and Critical Sections. Tyler Robison Summer 2010 CSE332: Data Abstractions Lecture 23: Programming with Locks and Critical Sections Tyler Robison Summer 2010 1 Concurrency: where are we Done: The semantics of locks Locks in Java Using locks for mutual

More information

Basic Principles of OO. Example: Ice/Water Dispenser. Systems Thinking. Interfaces: Describing Behavior. People's Roles wrt Systems

Basic Principles of OO. Example: Ice/Water Dispenser. Systems Thinking. Interfaces: Describing Behavior. People's Roles wrt Systems Basics of OO Programming with Java/C# Basic Principles of OO Abstraction Encapsulation Modularity Breaking up something into smaller, more manageable pieces Hierarchy Refining through levels of abstraction

More information

Absolute C++ Walter Savitch

Absolute C++ Walter Savitch Absolute C++ sixth edition Walter Savitch Global edition This page intentionally left blank Absolute C++, Global Edition Cover Title Page Copyright Page Preface Acknowledgments Brief Contents Contents

More information

Lab 10: Sockets 12:00 PM, Apr 4, 2018

Lab 10: Sockets 12:00 PM, Apr 4, 2018 CS18 Integrated Introduction to Computer Science Fisler, Nelson Lab 10: Sockets 12:00 PM, Apr 4, 2018 Contents 1 The Client-Server Model 1 1.1 Constructing Java Sockets.................................

More information

Need for synchronization: If threads comprise parts of our software systems, then they must communicate.

Need for synchronization: If threads comprise parts of our software systems, then they must communicate. Thread communication and synchronization There are two main aspects to Outline for Lecture 19 multithreaded programming in Java: I. Thread synchronization. thread lifecycle, and thread synchronization.

More information

The Dining Philosophers Problem CMSC 330: Organization of Programming Languages

The Dining Philosophers Problem CMSC 330: Organization of Programming Languages The Dining Philosophers Problem CMSC 0: Organization of Programming Languages Threads Classic Concurrency Problems Philosophers either eat or think They must have two forks to eat Can only use forks on

More information

CS180 Review. Recitation Week 15

CS180 Review. Recitation Week 15 CS180 Review Recitation Week 15 Announcement Final exam will be held on Thursday(12/17) 8:00~10:00 AM The coverage is comprehensive Project 5 is graded. Check your score in Blackboard. Classes and Methods

More information

Software Development & Education Center. Java Platform, Standard Edition 7 (JSE 7)

Software Development & Education Center. Java Platform, Standard Edition 7 (JSE 7) Software Development & Education Center Java Platform, Standard Edition 7 (JSE 7) Detailed Curriculum Getting Started What Is the Java Technology? Primary Goals of the Java Technology The Java Virtual

More information

CMSC 330: Organization of Programming Languages

CMSC 330: Organization of Programming Languages CMSC 330: Organization of Programming Languages Threads Synchronization Refers to mechanisms allowing a programmer to control the execution order of some operations across different threads in a concurrent

More information

CMSC 330: Organization of Programming Languages. The Dining Philosophers Problem

CMSC 330: Organization of Programming Languages. The Dining Philosophers Problem CMSC 330: Organization of Programming Languages Threads Classic Concurrency Problems The Dining Philosophers Problem Philosophers either eat or think They must have two forks to eat Can only use forks

More information

Computation Abstractions. Processes vs. Threads. So, What Is a Thread? CMSC 433 Programming Language Technologies and Paradigms Spring 2007

Computation Abstractions. Processes vs. Threads. So, What Is a Thread? CMSC 433 Programming Language Technologies and Paradigms Spring 2007 CMSC 433 Programming Language Technologies and Paradigms Spring 2007 Threads and Synchronization May 8, 2007 Computation Abstractions t1 t1 t4 t2 t1 t2 t5 t3 p1 p2 p3 p4 CPU 1 CPU 2 A computer Processes

More information

Java Threads. COMP 585 Noteset #2 1

Java Threads. COMP 585 Noteset #2 1 Java Threads The topic of threads overlaps the boundary between software development and operation systems. Words like process, task, and thread may mean different things depending on the author and the

More information

Inheritance. Transitivity

Inheritance. Transitivity Inheritance Classes can be organized in a hierarchical structure based on the concept of inheritance Inheritance The property that instances of a sub-class can access both data and behavior associated

More information

CS 31: Introduction to Computer Systems : Threads & Synchronization April 16-18, 2019

CS 31: Introduction to Computer Systems : Threads & Synchronization April 16-18, 2019 CS 31: Introduction to Computer Systems 22-23: Threads & Synchronization April 16-18, 2019 Making Programs Run Faster We all like how fast computers are In the old days (1980 s - 2005): Algorithm too slow?

More information

Problem Solving with C++

Problem Solving with C++ GLOBAL EDITION Problem Solving with C++ NINTH EDITION Walter Savitch Kendrick Mock Ninth Edition PROBLEM SOLVING with C++ Problem Solving with C++, Global Edition Cover Title Copyright Contents Chapter

More information

Text Input and Conditionals

Text Input and Conditionals Text Input and Conditionals Text Input Many programs allow the user to enter information, like a username and password. Python makes taking input from the user seamless with a single line of code: input()

More information

Java for Programmers Course (equivalent to SL 275) 36 Contact Hours

Java for Programmers Course (equivalent to SL 275) 36 Contact Hours Java for Programmers Course (equivalent to SL 275) 36 Contact Hours Course Overview This course teaches programmers the skills necessary to create Java programming system applications and satisfies the

More information

1 Method Signatures and Overloading (3 minutes, 2 points)

1 Method Signatures and Overloading (3 minutes, 2 points) CS180 Spring 2010 Exam 1 Solutions, 15 February, 2010 Prof. Chris Clifton Turn Off Your Cell Phone. Use of any electronic device during the test is prohibited. Time will be tight. If you spend more than

More information

Intro. Scheme Basics. scm> 5 5. scm>

Intro. Scheme Basics. scm> 5 5. scm> Intro Let s take some time to talk about LISP. It stands for LISt Processing a way of coding using only lists! It sounds pretty radical, and it is. There are lots of cool things to know about LISP; if

More information

A Sophomoric Introduction to Shared-Memory Parallelism and Concurrency Lecture 5 Programming with Locks and Critical Sections

A Sophomoric Introduction to Shared-Memory Parallelism and Concurrency Lecture 5 Programming with Locks and Critical Sections A Sophomoric Introduction to Shared-Memory Parallelism and Concurrency Lecture 5 Programming with Locks and Critical Sections Dan Grossman Last Updated: May 2012 For more information, see http://www.cs.washington.edu/homes/djg/teachingmaterials/

More information

1B1b Inheritance. Inheritance. Agenda. Subclass and Superclass. Superclass. Generalisation & Specialisation. Shapes and Squares. 1B1b Lecture Slides

1B1b Inheritance. Inheritance. Agenda. Subclass and Superclass. Superclass. Generalisation & Specialisation. Shapes and Squares. 1B1b Lecture Slides 1B1b Inheritance Agenda Introduction to inheritance. How Java supports inheritance. Inheritance is a key feature of object-oriented oriented programming. 1 2 Inheritance Models the kind-of or specialisation-of

More information

Lecture 3. COMP1006/1406 (the Java course) Summer M. Jason Hinek Carleton University

Lecture 3. COMP1006/1406 (the Java course) Summer M. Jason Hinek Carleton University Lecture 3 COMP1006/1406 (the Java course) Summer 2014 M. Jason Hinek Carleton University today s agenda assignments 1 (graded) & 2 3 (available now) & 4 (tomorrow) a quick look back primitive data types

More information

CS 2112 Lecture 20 Synchronization 5 April 2012 Lecturer: Andrew Myers

CS 2112 Lecture 20 Synchronization 5 April 2012 Lecturer: Andrew Myers CS 2112 Lecture 20 Synchronization 5 April 2012 Lecturer: Andrew Myers 1 Critical sections and atomicity We have been seeing that sharing mutable objects between different threads is tricky We need some

More information

Overview. CMSC 330: Organization of Programming Languages. Concurrency. Multiprocessors. Processes vs. Threads. Computation Abstractions

Overview. CMSC 330: Organization of Programming Languages. Concurrency. Multiprocessors. Processes vs. Threads. Computation Abstractions CMSC 330: Organization of Programming Languages Multithreaded Programming Patterns in Java CMSC 330 2 Multiprocessors Description Multiple processing units (multiprocessor) From single microprocessor to

More information

Java Threads. Written by John Bell for CS 342, Spring 2018

Java Threads. Written by John Bell for CS 342, Spring 2018 Java Threads Written by John Bell for CS 342, Spring 2018 Based on chapter 9 of Learning Java, Fourth Edition by Niemeyer and Leuck, and other sources. Processes A process is an instance of a running program.

More information

Program Graph. Lecture 25: Parallelism & Concurrency. Performance. What does it mean?

Program Graph. Lecture 25: Parallelism & Concurrency. Performance. What does it mean? Program Graph Lecture 25: Parallelism & Concurrency CS 62 Fall 2015 Kim Bruce & Michael Bannister Some slides based on those from Dan Grossman, U. of Washington Program using fork and join can be seen

More information

G51PGP Programming Paradigms. Lecture 009 Concurrency, exceptions

G51PGP Programming Paradigms. Lecture 009 Concurrency, exceptions G51PGP Programming Paradigms Lecture 009 Concurrency, exceptions 1 Reminder subtype polymorphism public class TestAnimals public static void main(string[] args) Animal[] animals = new Animal[6]; animals[0]

More information

Introduction to Computers and C++ Programming p. 1 Computer Systems p. 2 Hardware p. 2 Software p. 7 High-Level Languages p. 8 Compilers p.

Introduction to Computers and C++ Programming p. 1 Computer Systems p. 2 Hardware p. 2 Software p. 7 High-Level Languages p. 8 Compilers p. Introduction to Computers and C++ Programming p. 1 Computer Systems p. 2 Hardware p. 2 Software p. 7 High-Level Languages p. 8 Compilers p. 9 Self-Test Exercises p. 11 History Note p. 12 Programming and

More information

COP 3330 Final Exam Review

COP 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 information

Multitasking Multitasking allows several activities to occur concurrently on the computer. A distinction is usually made between: Process-based multit

Multitasking Multitasking allows several activities to occur concurrently on the computer. A distinction is usually made between: Process-based multit Threads Multitasking Multitasking allows several activities to occur concurrently on the computer. A distinction is usually made between: Process-based multitasking Thread-based multitasking Multitasking

More information

Programming Languages. Streams Wrapup, Memoization, Type Systems, and Some Monty Python

Programming Languages. Streams Wrapup, Memoization, Type Systems, and Some Monty Python Programming Languages Streams Wrapup, Memoization, Type Systems, and Some Monty Python Quick Review of Constructing Streams Usually two ways to construct a stream. Method 1: Use a function that takes a(n)

More information

M301: Software Systems & their Development. Unit 4: Inheritance, Composition and Polymorphism

M301: Software Systems & their Development. Unit 4: Inheritance, Composition and Polymorphism Block 1: Introduction to Java Unit 4: Inheritance, Composition and Polymorphism Aims of the unit: Study and use the Java mechanisms that support reuse, in particular, inheritance and composition; Analyze

More information

CMSC 330: Organization of Programming Languages. Threads Classic Concurrency Problems

CMSC 330: Organization of Programming Languages. Threads Classic Concurrency Problems : Organization of Programming Languages Threads Classic Concurrency Problems The Dining Philosophers Problem Philosophers either eat or think They must have two forks to eat Can only use forks on either

More information

Prelim 1 SOLUTION. CS 2110, September 29, 2016, 7:30 PM Total Question Name Loop invariants. Recursion OO Short answer

Prelim 1 SOLUTION. CS 2110, September 29, 2016, 7:30 PM Total Question Name Loop invariants. Recursion OO Short answer Prelim 1 SOLUTION CS 2110, September 29, 2016, 7:30 PM 0 1 2 3 4 5 Total Question Name Loop invariants Recursion OO Short answer Exception handling Max 1 15 15 25 34 10 100 Score Grader 0. Name (1 point)

More information

5/29/2006. Announcements. Last Time. Today. Text File I/O Sample Programs. The File Class. Without using FileReader. Reviewed method overloading.

5/29/2006. Announcements. Last Time. Today. Text File I/O Sample Programs. The File Class. Without using FileReader. Reviewed method overloading. Last Time Reviewed method overloading. A few useful Java classes: Other handy System class methods Wrapper classes String class StringTokenizer class Assn 3 posted. Announcements Final on June 14 or 15?

More information

Lecture 5: Implementing Lists, Version 1

Lecture 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 information

CS 180 Final Exam Review 12/(11, 12)/08

CS 180 Final Exam Review 12/(11, 12)/08 CS 180 Final Exam Review 12/(11, 12)/08 Announcements Final Exam Thursday, 18 th December, 10:20 am 12:20 pm in PHYS 112 Format 30 multiple choice questions 5 programming questions More stress on topics

More information

1 Epic Test Review 2 Epic Test Review 3 Epic Test Review 4. Epic Test Review 5 Epic Test Review 6 Epic Test Review 7 Epic Test Review 8

1 Epic Test Review 2 Epic Test Review 3 Epic Test Review 4. Epic Test Review 5 Epic Test Review 6 Epic Test Review 7 Epic Test Review 8 Epic Test Review 1 Epic Test Review 2 Epic Test Review 3 Epic Test Review 4 Write a line of code that outputs the phase Hello World to the console without creating a new line character. System.out.print(

More information

Type Hierarchy. Comp-303 : Programming Techniques Lecture 9. Alexandre Denault Computer Science McGill University Winter 2004

Type Hierarchy. Comp-303 : Programming Techniques Lecture 9. Alexandre Denault Computer Science McGill University Winter 2004 Type Hierarchy Comp-303 : Programming Techniques Lecture 9 Alexandre Denault Computer Science McGill University Winter 2004 February 16, 2004 Lecture 9 Comp 303 : Programming Techniques Page 1 Last lecture...

More information

M257 Past Paper Oct 2008 Attempted Solution

M257 Past Paper Oct 2008 Attempted Solution M257 Past Paper Oct 2008 Attempted Solution Part 1 Question 1 A version of Java is a particular release of the language, which may be succeeded by subsequent updated versions at a later time. Some examples

More information

CMSC131. Inheritance. Object. When we talked about Object, I mentioned that all Java classes are "built" on top of that.

CMSC131. Inheritance. Object. When we talked about Object, I mentioned that all Java classes are built on top of that. CMSC131 Inheritance Object When we talked about Object, I mentioned that all Java classes are "built" on top of that. This came up when talking about the Java standard equals operator: boolean equals(object

More information

CS Exam 1 Review Suggestions

CS 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 information

RACE CONDITIONS AND SYNCHRONIZATION

RACE CONDITIONS AND SYNCHRONIZATION RACE CONDITIONS AND SYNCHRONIZATION Lecture 21 CS2110 Fall 2010 Reminder 2 A race condition arises if two threads try and share some data One updates it and the other reads it, or both update the data

More information

Quiz on Tuesday April 13. CS 361 Concurrent programming Drexel University Fall 2004 Lecture 4. Java facts and questions. Things to try in Java

Quiz on Tuesday April 13. CS 361 Concurrent programming Drexel University Fall 2004 Lecture 4. Java facts and questions. Things to try in Java CS 361 Concurrent programming Drexel University Fall 2004 Lecture 4 Bruce Char and Vera Zaychik. All rights reserved by the author. Permission is given to students enrolled in CS361 Fall 2004 to reproduce

More information

Programming Exercise 14: Inheritance and Polymorphism

Programming Exercise 14: Inheritance and Polymorphism Programming Exercise 14: Inheritance and Polymorphism Purpose: Gain experience in extending a base class and overriding some of its methods. Background readings from textbook: Liang, Sections 11.1-11.5.

More information

Concurrency in Java Prof. Stephen A. Edwards

Concurrency in Java Prof. Stephen A. Edwards Concurrency in Java Prof. Stephen A. Edwards The Java Language Developed by James Gosling et al. at Sun Microsystems in the early 1990s Originally called Oak, first intended application was as an OS for

More information

1 Constructors and Inheritance (4 minutes, 2 points)

1 Constructors and Inheritance (4 minutes, 2 points) CS180 Spring 2010 Final Exam 8 May, 2010 Prof. Chris Clifton Turn Off Your Cell Phone. Use of any electronic device during the test is prohibited. Time will be tight. If you spend more than the recommended

More information

Chapter 6 Introduction to Defining Classes

Chapter 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 information

Java Threads and intrinsic locks

Java Threads and intrinsic locks Java Threads and intrinsic locks 1. Java and OOP background fundamentals 1.1. Objects, methods and data One significant advantage of OOP (object oriented programming) is data encapsulation. Each object

More information

About this exam review

About 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 information

Note that if both p1 and p2 are null, equals returns true.

Note that if both p1 and p2 are null, equals returns true. 258 students took the exam. The average was 26.4 out of 36; the median was 27.5; scores ranged from 3 to 35.5. 133 students scored between 27.5 and 36, 99 between 18.5 and 27, 24 between 9.5 and 18, and

More information

QUIZ. Write the following for the class Bar: Default constructor Constructor Copy-constructor Overloaded assignment oper. Is a destructor needed?

QUIZ. Write the following for the class Bar: Default constructor Constructor Copy-constructor Overloaded assignment oper. Is a destructor needed? QUIZ Write the following for the class Bar: Default constructor Constructor Copy-constructor Overloaded assignment oper. Is a destructor needed? Or Foo(x), depending on how we want the initialization

More information

OOPs Concepts. 1. Data Hiding 2. Encapsulation 3. Abstraction 4. Is-A Relationship 5. Method Signature 6. Polymorphism 7. Constructors 8.

OOPs Concepts. 1. Data Hiding 2. Encapsulation 3. Abstraction 4. Is-A Relationship 5. Method Signature 6. Polymorphism 7. Constructors 8. OOPs Concepts 1. Data Hiding 2. Encapsulation 3. Abstraction 4. Is-A Relationship 5. Method Signature 6. Polymorphism 7. Constructors 8. Type Casting Let us discuss them in detail: 1. Data Hiding: Every

More information

1 Inheritance (8 minutes, 9 points)

1 Inheritance (8 minutes, 9 points) Name: Career Account ID: Recitation#: 1 CS180 Spring 2011 Exam 2, 6 April, 2011 Prof. Chris Clifton Turn Off Your Cell Phone. Use of any electronic device during the test is prohibited. Time will be tight.

More information

Concurrency Control. Synchronization. Brief Preview of Scheduling. Motivating Example. Motivating Example (Cont d) Interleaved Schedules

Concurrency Control. Synchronization. Brief Preview of Scheduling. Motivating Example. Motivating Example (Cont d) Interleaved Schedules Brief Preview of Scheduling Concurrency Control Nan Niu (nn@cs.toronto.edu) CSC309 -- Summer 2008 Multiple threads ready to run Some mechanism for switching between them Context switches Some policy for

More information

CS 221 Review. Mason Vail

CS 221 Review. Mason Vail CS 221 Review Mason Vail Inheritance (1) Every class - except the Object class - directly inherits from one parent class. Object is the only class with no parent. If a class does not declare a parent using

More information

CS Lecture #14

CS Lecture #14 CS 213 -- Lecture #14 We re starting to catch up! Administrative... Late Night Guide to C++ Chapter 9 pg 222-239 MORE ABOUT CLASSES Part I Interfaces in C++ For those with Java experience, you know that

More information

Outline. Java Models for variables Types and type checking, type safety Interpretation vs. compilation. Reasoning about code. CSCI 2600 Spring

Outline. Java Models for variables Types and type checking, type safety Interpretation vs. compilation. Reasoning about code. CSCI 2600 Spring Java Outline Java Models for variables Types and type checking, type safety Interpretation vs. compilation Reasoning about code CSCI 2600 Spring 2017 2 Java Java is a successor to a number of languages,

More information

Written by John Bell for CS 342, Spring 2018

Written by John Bell for CS 342, Spring 2018 Advanced OO Concepts Written by John Bell for CS 342, Spring 2018 Based on chapter 3 of The Object-Oriented Thought Process by Matt Weisfeld, with additional material from other sources. Constructors Constructors

More information

CS 231 Data Structures and Algorithms, Fall 2016

CS 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 information

CS125 : Introduction to Computer Science. Lecture Notes #38 and #39 Quicksort. c 2005, 2003, 2002, 2000 Jason Zych

CS125 : Introduction to Computer Science. Lecture Notes #38 and #39 Quicksort. c 2005, 2003, 2002, 2000 Jason Zych CS125 : Introduction to Computer Science Lecture Notes #38 and #39 Quicksort c 2005, 2003, 2002, 2000 Jason Zych 1 Lectures 38 and 39 : Quicksort Quicksort is the best sorting algorithm known which is

More information

Threads SPL/2010 SPL/20 1

Threads SPL/2010 SPL/20 1 Threads 1 Today Processes and Scheduling Threads Abstract Object Models Computation Models Java Support for Threads 2 Process vs. Program processes as the basic unit of execution managed by OS OS as any

More information

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2018 Lecture 11

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2018 Lecture 11 CS24: INTRODUCTION TO COMPUTING SYSTEMS Spring 2018 Lecture 11 EXCEPTION HANDLING Many higher-level languages provide exception handling Concept: One part of the program knows how to detect a problem,

More information

CSCI 136 Written Exam #1 Fundamentals of Computer Science II Spring 2015

CSCI 136 Written Exam #1 Fundamentals of Computer Science II Spring 2015 CSCI 136 Written Exam #1 Fundamentals of Computer Science II Spring 2015 Name: This exam consists of 5 problems on the following 7 pages. You may use your double- sided hand- written 8 ½ x 11 note sheet

More information

Only one thread can own a specific monitor

Only one thread can own a specific monitor Java 5 Notes Threads inherit their priority and daemon properties from their creating threads The method thread.join() blocks and waits until the thread completes running A thread can have a name for identification

More information

Lecture 20. Java Exceptional Event Handling. Dr. Martin O Connor CA166

Lecture 20. Java Exceptional Event Handling. Dr. Martin O Connor CA166 Lecture 20 Java Exceptional Event Handling Dr. Martin O Connor CA166 www.computing.dcu.ie/~moconnor Topics What is an Exception? Exception Handler Catch or Specify Requirement Three Kinds of Exceptions

More information

PREPARING FOR PRELIM 2

PREPARING FOR PRELIM 2 PREPARING FOR PRELIM 2 CS 1110: FALL 2012 This handout explains what you have to know for the second prelim. There will be a review session with detailed examples to help you study. To prepare for the

More information

AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS

AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS PAUL L. BAILEY Abstract. This documents amalgamates various descriptions found on the internet, mostly from Oracle or Wikipedia. Very little of this

More information

THREADS AND CONCURRENCY

THREADS AND CONCURRENCY THREADS AND CONCURRENCY Lecture 22 CS2110 Spring 2013 Graphs summary 2 Dijkstra: given a vertex v, finds shortest path from v to x for each vertex x in the graph Key idea: maintain a 5-part invariant on

More information

Java Fundamentals p. 1 The Origins of Java p. 2 How Java Relates to C and C++ p. 3 How Java Relates to C# p. 4 Java's Contribution to the Internet p.

Java Fundamentals p. 1 The Origins of Java p. 2 How Java Relates to C and C++ p. 3 How Java Relates to C# p. 4 Java's Contribution to the Internet p. Preface p. xix Java Fundamentals p. 1 The Origins of Java p. 2 How Java Relates to C and C++ p. 3 How Java Relates to C# p. 4 Java's Contribution to the Internet p. 5 Java Applets and Applications p. 5

More information

CS Internet programming Unit- I Part - A 1 Define Java. 2. What is a Class? 3. What is an Object? 4. What is an Instance?

CS Internet programming Unit- I Part - A 1 Define Java. 2. What is a Class? 3. What is an Object? 4. What is an Instance? CS6501 - Internet programming Unit- I Part - A 1 Define Java. Java is a programming language expressly designed for use in the distributed environment of the Internet. It was designed to have the "look

More information

Highlights. - Making threads. - Waiting for threads. - Review (classes, pointers, inheritance)

Highlights. - Making threads. - Waiting for threads. - Review (classes, pointers, inheritance) Parallel processing Highlights - Making threads - Waiting for threads - Review (classes, pointers, inheritance) Review: CPUs Review: CPUs In the 2000s, computing too a major turn: multi-core processors

More information

Writing a Protocol Handler

Writing a Protocol Handler Writing a Protocol Handler A URL object uses a protocol handler to establish a connection with a server and perform whatever protocol is necessary to retrieve data. For example, an HTTP protocol handler

More information

PREPARING FOR THE FINAL EXAM

PREPARING FOR THE FINAL EXAM PREPARING FOR THE FINAL EXAM CS 1110: FALL 2017 This handout explains what you have to know for the final exam. Most of the exam will include topics from the previous two prelims. We have uploaded the

More information

Core Java - SCJP. Q2Technologies, Rajajinagar. Course content

Core Java - SCJP. Q2Technologies, Rajajinagar. Course content Core Java - SCJP Course content NOTE: For exam objectives refer to the SCJP 1.6 objectives. 1. Declarations and Access Control Java Refresher Identifiers & JavaBeans Legal Identifiers. Sun's Java Code

More information

CS 6456 OBJCET ORIENTED PROGRAMMING IV SEMESTER/EEE

CS 6456 OBJCET ORIENTED PROGRAMMING IV SEMESTER/EEE CS 6456 OBJCET ORIENTED PROGRAMMING IV SEMESTER/EEE PART A UNIT I 1. Differentiate object oriented programming from procedure oriented programming. 2. Define abstraction and encapsulation. 3. Differentiate

More information

Week 7. Concurrent Programming: Thread Synchronization. CS 180 Sunil Prabhakar Department of Computer Science Purdue University

Week 7. Concurrent Programming: Thread Synchronization. CS 180 Sunil Prabhakar Department of Computer Science Purdue University Week 7 Concurrent Programming: Thread Synchronization CS 180 Sunil Prabhakar Department of Computer Science Purdue University Announcements Exam 1 tonight 6:30 pm - 7:30 pm MTHW 210 2 Outcomes Understand

More information

Distributed Systems Recitation 2. Tamim Jabban

Distributed Systems Recitation 2. Tamim Jabban 15-440 Distributed Systems Recitation 2 Tamim Jabban Agenda Communication via Sockets in Java (this enables you to complete PS1 and start P1 (goes out today!)) Multi-threading in Java Coding a full Client-Server

More information

CONTENTS. PART 1 Structured Programming 1. 1 Getting started 3. 2 Basic programming elements 17

CONTENTS. PART 1 Structured Programming 1. 1 Getting started 3. 2 Basic programming elements 17 List of Programs xxv List of Figures xxix List of Tables xxxiii Preface to second version xxxv PART 1 Structured Programming 1 1 Getting started 3 1.1 Programming 3 1.2 Editing source code 5 Source code

More information

Index. Index. More information. block statements 66 y 107 Boolean 107 break 55, 68 built-in types 107

Index. Index. More information. block statements 66 y 107 Boolean 107 break 55, 68 built-in types 107 A abbreviations 17 abstract class 105 abstract data types 105 abstract method 105 abstract types 105 abstraction 92, 105 access level 37 package 114 private 115 protected 115 public 115 accessors 24, 105

More information

Threads Chate Patanothai

Threads Chate Patanothai Threads Chate Patanothai Objectives Knowing thread: 3W1H Create separate threads Control the execution of a thread Communicate between threads Protect shared data C. Patanothai Threads 2 What are threads?

More information

CS211 Computers and Programming Matthew Harris and Alexa Sharp July 9, Boggle

CS211 Computers and Programming Matthew Harris and Alexa Sharp July 9, Boggle Boggle If you are not familiar with the game Boggle, the game is played with 16 dice that have letters on all faces. The dice are randomly deposited into a four-by-four grid so that the players see the

More information