10.07.2015 Views

Introduction to Programming Using Java - Department of ...

Introduction to Programming Using Java - Department of ...

Introduction to Programming Using Java - Department of ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

viiiCONTENTS7.5 Multi-dimensional Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3527.5.1 Creating Two-dimensional Arrays . . . . . . . . . . . . . . . . . . . . . . 3527.5.2 <strong>Using</strong> Two-dimensional Arrays . . . . . . . . . . . . . . . . . . . . . . . . 3547.5.3 Example: Checkers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 357Exercises for Chapter 7 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 364Quiz on Chapter 7 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3708 Correctness and Robustness 3738.1 <strong>Introduction</strong> <strong>to</strong> Correctness and Robustness . . . . . . . . . . . . . . . . . . . . . 3738.1.1 Horror S<strong>to</strong>ries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3748.1.2 <strong>Java</strong> <strong>to</strong> the Rescue . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3758.1.3 Problems Remain in <strong>Java</strong> . . . . . . . . . . . . . . . . . . . . . . . . . . . 3778.2 Writing Correct Programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3788.2.1 Provably Correct Programs . . . . . . . . . . . . . . . . . . . . . . . . . . 3788.2.2 Robust Handling <strong>of</strong> Input . . . . . . . . . . . . . . . . . . . . . . . . . . . 3818.3 Exceptions and try..catch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3858.3.1 Exceptions and Exception Classes . . . . . . . . . . . . . . . . . . . . . . 3868.3.2 The try Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3888.3.3 Throwing Exceptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3908.3.4 Manda<strong>to</strong>ry Exception Handling . . . . . . . . . . . . . . . . . . . . . . . . 3928.3.5 <strong>Programming</strong> with Exceptions . . . . . . . . . . . . . . . . . . . . . . . . 3938.4 Assertions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3968.5 <strong>Introduction</strong> <strong>to</strong> Threads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3998.5.1 Creating and Running Threads . . . . . . . . . . . . . . . . . . . . . . . . 4008.5.2 Operations on Threads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4048.5.3 Mutual Exclusion with “synchronized” . . . . . . . . . . . . . . . . . . . . 4058.5.4 Wait and Notify . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4088.5.5 Volatile Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4128.6 Analysis <strong>of</strong> Algorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 413Exercises for Chapter 8 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 419Quiz on Chapter 8 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4249 Linked Data Structures and Recursion 4279.1 Recursion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4279.1.1 Recursive Binary Search . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4289.1.2 Towers <strong>of</strong> Hanoi . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4309.1.3 A Recursive Sorting Algorithm . . . . . . . . . . . . . . . . . . . . . . . . 4329.1.4 Blob Counting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4359.2 Linked Data Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4399.2.1 Recursive Linking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4399.2.2 Linked Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4419.2.3 Basic Linked List Processing . . . . . . . . . . . . . . . . . . . . . . . . . 4419.2.4 Inserting in<strong>to</strong> a Linked List . . . . . . . . . . . . . . . . . . . . . . . . . . 4459.2.5 Deleting from a Linked List . . . . . . . . . . . . . . . . . . . . . . . . . . 4479.3 Stacks, Queues, and ADTs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4489.3.1 Stacks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4499.3.2 Queues . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4529.3.3 Postfix Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 456

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!