CS 151 ObjectOriented Design December 5 Class Meeting
CS 151: Object-Oriented Design December 5 Class Meeting Department of Computer Science San Jose State University Fall 2013 Instructor: Ron Mak www. cs. sjsu. edu/~mak
Animation Example: Merge Sort o Animate the merge sort algorithm. SJSU Dept. of Computer Science Fall 2013: December 5 CS 151: Object-Oriented Design © R. Mak 2
Animation Example: Merge Sort, cont’d o Two threads n n The main thread for the GUI. The sorting thread. o o Class Sorter implements the Runnable interface. Method Merge. Sort. sort() takes two parameters: n n The Double array to be sorted A Comparator<Double> object interface Comparator<T> { int compare(T object 1, T object 2); } n Method compare() returns -1, 0, or +1 depending on whether object 1 is less than, equal to, or greater than object 2. _ SJSU Dept. of Computer Science Fall 2013: December 5 CS 151: Object-Oriented Design © R. Mak 3
Animation Example: Merge Sort, cont’d o The run() method of class Sorter: public void run() { Merge. Sorter. sort(values, new Comparator<Double>() { public int compare(Double d 1, Double d 2) { Update the display panel. set. Values(values, d 1, d 2); before each compare. try { Thread. sleep(DELAY); Sleep } catch (Interrupted. Exception exception) { Thread. current. Thread(). interrupt(); } return d 1. compare. To(d 2); Then compare } }); panel. set. Values(values, null); } SJSU Dept. of Computer Science Fall 2013: December 5 CS 151: Object-Oriented Design © R. Mak Demo 4
Animation Challenge o Spawn (create and start) a thread for each merge. n n Do the merges in parallel! Will the sort be faster or slower? SJSU Dept. of Computer Science Fall 2013: December 5 CS 151: Object-Oriented Design © R. Mak 5
Unofficial Field Trip o Computer History Museum in Mt. View n o http: //www. computerhistory. org/ Saturday, December 7, 11: 30 – closing time n n Special free admission. Schedule o o o n 11: 30 -12: 00 11: 45 -1: 00 -1: 30 -closing 3: 00 -3: 30 } – PDP-1 plays Christmas carols three – Live demonstration of the IBM 1401 groups – Live demonstration of the Babbage Difference Engine – Self-guided tours of the Revolution exhibits – Spacewar! demo on the PDP-1 by one of its authors Extra credit – A multiple-choice quiz based on the Revolution exhibits o o The quiz will be distributed before you arrive at the museum. Please enter your answers into Canvas. SJSU Dept. of Computer Science Fall 2013: December 5 CS 151: Object-Oriented Design © R. Mak 6
Unofficial Field Trip, cont’d o Babbage Difference Engine, fully operational n n n Hand-cranked mechanical computer. Computed polynomial functions. Designed by Charles Babbage in the early to mid 1800 s. o n o Arguably the world’s first computer scientist, lived 1791 -1871. He wasn’t able to build it because he lost his funding. Live demo at 1: 00 PM o http: //www. computerhistory. org/babbage/ SJSU Dept. of Computer Science Fall 2013: December 5 His plans survived and this working model was built. n CS 151: Object-Oriented Design © R. Mak Includes a working printer! 7
Unofficial Field Trip, cont’d o The new Revolution exhibit is now open! Walk through a timeline of the First 2000 Years of Computing History. Historic computer systems, data processing equipment, and other artifacts. Small theater presentations. n n n Hollerith Census Machine SJSU Dept. of Computer Science Fall 2013: December 5 Atanasoff-Berry Computer CS 151: Object-Oriented Design © R. Mak 8
What was the PDP-1? o o o Commercial computer produced in 1959 by the Digital Equipment Corporation (DEC). 18 -bit word size 4 K words of memory n o o o Steve Russell, who programmed the original Spacewar! video game while at MIT in 1961. SJSU Dept. of Computer Science Fall 2013: December 5 o Upgradable to 64 K 2700 transistors 3000 diodes Paper tape CRT display CS 151: Object-Oriented Design © R. Mak 9
What was the IBM 1401? o IBM 1401 computer, fully restored and operational n n A small transistor-based mainframe computer. Extremely popular with small businesses in the late 1950 s through the mid 1960 s o o Maximum of 16 K bytes of memory. 800 card/minute card reader (wire brushes). 600 line/minute line printer (impact). 6 magnetic tape drives, no disk drives. 1402 Card Reader Punch SJSU Dept. of Computer Science Fall 2013: December 5 1407 Console 1401 CPU 729 Tape Drives CS 151: Object-Oriented Design © R. Mak 1403 Line Printer 10
What was Computing Like Before the 1401? o Data was stored in punched cards called “IBM cards” or “Hollerith cards” n o 80 columns per card, one character per column. n o SJSU Dept. of Computer Science Fall 2013: December 5 CS 151: Object-Oriented Design © R. Mak Named after Herman Hollerith. Up to 12 punched holes per column. Alphanumeric data, often grouped into fields. _ 11
Data Processing o Data processing was all about punched cards. o My school compiler project: n n SJSU Dept. of Computer Science Fall 2013: December 5 3½ boxes of punched cards Each box = 2000 cards, 10 lbs. CS 151: Object-Oriented Design © R. Mak 12
Data Processing SJSU Dept. of Computer Science Fall 2013: December 5 CS 151: Object-Oriented Design © R. Mak 13
Data Processing o Cards were punched manually at a keypunch machine. n SJSU Dept. of Computer Science Fall 2013: December 5 Or they were punched automatically by unit-record equipment under program control. _ CS 151: Object-Oriented Design © R. Mak 14
The 1403 Line Printer o Each print line can contain up to 132 characters. n n o Outstanding print quality. n o Mechanically (impact) printed. No lasers! Horizontally straight lines of text. How fast was the 1403 line printer? n 600 lines per minute! Sample print quality. SJSU Dept. of Computer Science Fall 2013: December 5 CS 151: Object-Oriented Design © R. Mak 15
The 1403 Print Mechanism o 132 horizontal print hammers behind the paper, one per print column. n o Inked ribbon in front of the paper. o Horizontally rotating print chain in front of the ribbon. n o The print chain contains type slugs of the characters. As the desired character flies past a print column, the column's hammer fires to press the paper against the ribbon and the type slug. n n SJSU Dept. of Computer Science Fall 2013: December 5 Paper pulled upwards. CS 151: Object-Oriented Design © R. Mak The print chain does not stop. The paper advances as soon as the entire line is printed. 16
1402 Card Read Punch Stack of punched cards to be read Blank cards to be punched Card hoppers SJSU Dept. of Computer Science Fall 2013: December 5 CS 151: Object-Oriented Design © R. Mak 17
How the 1402 Read Punched Cards (cont’d) o It’s all in the timing! n n n o One brush per card column. All 80 columns were read simultaneously. Cards were fed into the 1402 card hopper “ 9 edge face down”. How fast was the 1402 card reader? n Up to 800 cards per minute! _ SJSU Dept. of Computer Science Fall 2013: December 5 CS 151: Object-Oriented Design © R. Mak 18
IBM 729 Magnetic Tape Drive SJSU Dept. of Computer Science Fall 2013: December 5 CS 151: Object-Oriented Design © R. Mak 19
Postmortem Reports o Due Monday, December 9 at 11: 59 PM n A few paragraphs. o n Word document or just an email message Individual and private. o What did you learn in this class? o What were your accomplishments on your project team? o How well did each of your teammates do? _ SJSU Dept. of Computer Science Fall 2013: December 5 CS 151: Object-Oriented Design © R. Mak 20
Final Exam o Thursday, December 12 in Science 311 n o 7: 15 – 9: 30 AM It will be similar to the midterm. n Covers the entire semester. _ SJSU Dept. of Computer Science Fall 2013: December 5 CS 151: Object-Oriented Design © R. Mak 21
Review for the Final Exam o Are you a better programmer today than you were at the start of the semester? o What makes you a better programmer? n It’s more than just writing programs that work. o n Requirements o o n Although that’s important! Functional Non-functional Documentation o o o UML diagrams Use cases CRC cards SJSU Dept. of Computer Science Fall 2013: December 5 n Good design o o Reliable Robust Flexible Maintainable _ CS 151: Object-Oriented Design © R. Mak 22
Review for the Final Exam, cont’d o How do the following make you a better programmer? n n n Loose coupling Encapsulation Coherency Consistency Programming to the interface Design patterns o n factory, strategy, iterator, observer, composite, decorator, template Dynamic class loading _ SJSU Dept. of Computer Science Fall 2013: December 5 CS 151: Object-Oriented Design © R. Mak 23
Review for the Final Exam, cont’d o Understand how each of the following contributes to better design: n n n n n Frameworks Generic types Interfaces Inheritance Polymorphism Abstract classes Type inquiry Reflection Metadata descriptor classes _ SJSU Dept. of Computer Science Fall 2013: December 5 CS 151: Object-Oriented Design © R. Mak 24
Review for the Final Exam, cont’d o Design patterns n n o Graphical User Interface (GUI) programming with Swing n n o Know when to use when designing a program. Recognize their use when reading a program. Event handlers Frames, panels, buttons, text fields, menus, etc. Layout managers Inversion of control Collections framework n n n Interfaces Classes Ability to create your own collection class SJSU Dept. of Computer Science Fall 2013: December 5 CS 151: Object-Oriented Design © R. Mak 25
Review for the Final Exam, cont’d o Multithreading n The Runnable interface The run() method n Synchronization n o o n o race conditions lock conditions synchronized methods Thread-safe code Your Rock-Paper-Scissors project. _ SJSU Dept. of Computer Science Fall 2013: December 5 CS 151: Object-Oriented Design © R. Mak 26
- Slides: 26