Title: cps161F15 Learning Units
Course: CPS 161: An Intro to Programming with Java - DL MM MASTER

cps161F15 Learning Units
chasselb
 |  | Remove Objectives from Learning Units

Resources

JH1, JH2, ... JH7 Homework definition files
- This link provides you links to all of the Homework assignment files. Note that you can also get to these files through blackboard links.
Java Practice
- This link takes you to the Practice Exercises that are designed to give you extra practice. These should be especially helpful if you find the JH assignments too challenging.
Java 8 API
- This link is to the Java Application Interface (API) documentation. Understanding how to use this will become increasingly important as you learn Java. You will see this link accessed in the videos.
Absolute Java Text
- This link provides the code from the textbook. It is the code used in the video when it is necessary to reference textbook examples. Note that the version of the textbook where this code was uploaded is a bit old (not sure I remember what version).
Topic Tree
- This provides links to the same material found in the "Learning Units", however, in this page the links are ordered by logical topics. In addition to the links, this page provides a brief list of objectives covered in each topic.
- You can control whether the list of objectives shows up or not by clicking on a link near the top of the page.
Startup

Clem Hasselbach Introduction Page
- This is Clem Hasselbach's home page if you want to know more about him.
- Pictures of family are shared and a video is provided where Clem describes his background.
Course Introduction
Syllabus (11.5 min)
- cps161 overview: textbook, relationship to other courses
- topics covered
Class Policy
- General goals of the class
- blackboard class structure: Assignments, Class Participation, Lectures, Getting Help, etc.
- Discussion of Grade issues: tests, Lateness Policy, grade composition
- Note a link named "JH... Homework ..." was added that isn't discussed in the video. This link was added after the video was made because it was discovered to be useful to have one page with all of the homework files in one place.
How to get a good Grade
- Grade calculation and Practice-Bribe calculations(Incentives for showing up to Mixed Mode class sessions and doing the extra Practice)
Video Features
- This link provides a slide to describe the Video Player characteristics
Discussion Board/Class Participation(15m)
- Discussion boards for questions/answers
- Discussion board for Sharings
- "Questions for Teacher" discussion board
Assignments
- Getting Started JH0 Quiz and first post on a discussion board
- How the JH1, JH2, ... JH7 assignments work.
You now know enough to do JH0
1 - Java Fundamentals

Java Historical Roots(25:34)
- Machine Language Stage
- First Languages: Fortran and Cobol
- Languages providing some structure: Pascal and "C"
- Object Oriented languages and their relationships: C++, Java, C#, Objective C
- Java Programming Model: "Write once in Java and run it on any platform that has a JVM program"
- Microsoft Model: "You can program in any language you want as long as you run on a Microsoft platform"
Java Characteristics (22.5 min)
- Open-source, and portable
- Environments: Web Servers (J2EE), Android, Browsers(Applets), and many other environments
- Execution Environment is protected (Java doesn't allow error prone things)
- Java is very Object Oriented, and contains many already built packages of powerful classes.
- When is Java a good choice and when would it be better to consider a non-interpreted language like C/C++.
Simple Development Environment (20.5 min)
- Installing Java
- Installing Eclipse and the fundamentals of using Eclipse
Basics Hello World Comments (18 min)
- Best to have class name and the file name match(pay attention to case)
- Program execution requires:
  - public static void main(String[]args)
- System.out.println and System.out.print
- Keyboard input requires something like:
  - Scanner keyboard = new Scanner(System.in);
- Importing packages like the Scanner require something like:
  - import java.util.Scanner;
- User's input can be returned from the Scanner keyboard with calls to:
  - keyboard.nextLine(), keyboard.nextInt(), etc.
Basics Simple Arithmetic (JPHA)
- Java is case sensitive, and white space insensitive.
- Comment rules (// and /* ... */ approaches)
- Variable declarations
- In Java the "=" sign means: store the contents of the right hand side into the variable on the left hand side
- Java supports most normal algebraic expressions (note that "*" is needed to signify multiply)
Basics Other Primitives (14.5 min)
- Characteristics of the integer-like primitives: byte, short, int, and long
- Characteristics of the floating point primitives: float, and double
- Characteristics of the primitive char for text
- Characteristics of the primitive boolean
Basics Variables (20 min)
- Rules for defining variables
- Naming conventions for "multi-word" variable names
- Naming conventions for Classes and Constants
You now know enough to do JH1
JH1 Jar/MakeChange Help
- Try doing JH1 on your own first, but if you want more hints, see the following:
- "Jar" assignment help
- "Making Change" help
2 - Arithmetic, Strings

Arithmetic Precedence Mixed Arithmetic (16.5 min)
- Integer arithmetic using the basic operators +, -, *, /, %
- Floating Point arithmetic
- Operator precedence rules and using parentheses to change the order of operations
- Arithmetic using a mix of integers and floating point values
Arithmetic Primitive Sizes, Casting, Shortcuts (JPHB)
- Primitive size ordering: byte, short, int, long, float, double
- Storing smaller primitives into larger primitives
- Storing larger primitives into smaller primitives using casting operations
- The "=" shortcuts: +=, -=, *=, /=, %=
- More shortcuts(++, --): Post Increment, pre increment, post decrement, pre decrement
Strings Scanners Classes Objects (JPHC)
- Classes, objects and the "new" operator
- Creating String objects and the Scanner object
- String methods: length and charAt
- String concatenation
Scanning & Formatting
- The printf method: Formatting String followed by a variable number of parameters
- Looking for the "%" field character followed by a conversion characters: d, f, e, g, s, c, n
- Other field designators: field width, precision, justification (right, left)
Optional Video: Command Line Java Development Environment
- This is an optional video that demonstrates how to do Java workoutside of Eclipse using javac and java programs from the command line.
- There is also a fun little game demo'ed in this video called "planetoid".
3 - Simple Logic Part 1

If Statement Basics
- Simple if statements
- if-then-else statements
- Using { ... } to create compound statements
- boolean expressions using the operators ==, !=,<,>,<=,>=
- if-then-else if- .... else statements
If Statement Examples (JPHD)
- Examples to demonstrate "if" statement concepts
  - IncomeTax.java
  - MinOfThree.java
  - Grades.java
While Loops
- while(boolean_expression) statement;
- executes 0 or more times depending on the "boolean_expression"
- Using { ... } to create compound statements
- boolean expressions are identical to those used in "if" statements
- do statement; while(boolean_expression);
- executes 1 or more times depending on the "boolean_expression"
- Examples: WhileExamples.java, Averager.java, WhileDemo.java
While Loop Examples (JPHE)
- More Meaningful Examples:
  - Power.java (uses while loop)
  - GuessingGame.java (using a while loop)
  - GuessingGame.java (using a do-while loop)
  - Multiplication.java (uses nested while loops to create a multiplication table)
String Equals Comparison (JPHG)
- Operators that we used for numbers like ==,<,>, etc. don't work as you would expect with Strings
- Use the equals method for Strings, or the other methods: equalsIgnoreCase, compareToIgnoreCase
- Examples: StringCompare.java, StringComparisonDemo.java
Switch Examples (JPHF)
- SwitchDemo.java - comparison of the "if" statement approach to a switch statement approach with months of the year
- switch statement is normally used for integer like primitives: byte, int, short, long, char, or enumerated types(covered later)
- switch statements don't work with floats or doubles
- As of release 1.7, java now supports switch statements with the String class.
You now know enough to do JH2
JH2 Help on Factorial
- "Factorial" help if you need it
4 - Simple Logic Part 2

For Loops
- for (initialization statement(s) ; boolean_condition ; end of loop statement(s)) statement;
- executes 0 or more times depending on the "boolean_expression"
- Using { ... } to create compound statements
- Counter declared in "for" loop versus declaring before the "for" loop
- Unusual versions: leaving blank entries, and multiple initializations, or multiple increments
- Common Pitfall: Misplaced ";" ... can happen in a "while" loop or "if" statement as well
- Example: ForLoops.java
For Loop Examples (JPHH)
- Multiplication Tables using nested "for" loops
- Miscellaneous.java to demonstrate "continue" and "break" key words.
- GuessingGame.java with a "for" loop limit on the number of guesses
More Boolean Concepts (JPHI)
- Review of String issues with == and using the method equals, or possibly the methods equalsIgnoreCase, or compareTo
- New boolean operators:&&, ||, and !
- How to evaluate ranges like: 5
- Using the operator precedence table to evaluate expressions ... Parentheses can change the order or clarify the existing evaluation order
- Short circuit logic with&&and || and taking advantage of this to write robust code
String Methods (JPHJ)
- String methods: toLowerCase, toUpperCase, trim, substring, indexOf, etc.
- String escape characters: \n, \t, \", \\, etc.
- Memory view of String method operators: eventually we will discover that Strings are immutable
Learning Enrichment: How Do I Approach Writing a Program?
- This is an Interactive Learning Enrichment that demonstrates how to address the issue of How to approach writing a program.
- The first step is to thoroughly understand the problem to be solved.
- It is also necessary to break a problem down into manageable pieces.
- The 2 people in this Learning Enrichment material provide some insight into this process.
Defining Classes 1 (JPHK)
- instance variables - definition and access
- methods - definition and access
- formal parameters, actual parameters
- Examples: simple MyDate, and VendingMachine
You now know enough to do JH3
JH3 Newton Help and the Fibonacci problem
- "Fibonocci" help if needed
- Help if needed for Newton's Algorithm for Square roots
Learning Enrichment: Debugging with Print Statements
- If you are having trouble figuring out why your program doesn't work, then it is possible that simply placing a strategic print statement will tell you a lot. It is good to have a meaningful output and it is also useful to incrementally add the print statements until it becomes clear what is really happening.
- In this Learning Enrichment you will see some interactive discussions between several characters in an attempt to use the print statement approach to figuring out what is wrong with a program.
JH3 String Methods Help
- "MyStringMethods" class help if needed
5 - Basics of Classes Part 1

Defining Classes 2: Rectangle(42.5m)
- Rectangle Example
- Point class - small utility class
- Passing classes as method parameters: equals, and overlap
- "this" keyword
Author's Date Sixth Try(31m)
- private instance variables
- "getters" - methods that start with "get" such as getDay, getMonth, getYear
- "setters" - methods that start with "set" such as setDate, setMonth, setDay, setYear
- method overloading
Classes_3: Summary, Constructors (JPHM)
- methods can return any primitive or any class
- local variables versus instance variables
- Default Constructors
- Constructor concepts - purpose is to initialize class
- Overloading constructors is very common
- keyword "this" can be used to have a constructor call another constructor
- Constructors are associated with calls with "new" keyword and memory is allocated from the "memory heap"
Defining Classes 4: Miscellaneous (JPHN)
- buzz words: Information hiding, Abstraction, Encapsulation, API (Application Programming Interface), ADT (Abstract Data Type), Accessor methods, Mutator methods
- Overloading rules and method signatures (note return type is not part of the signature)
- Initialization of Variables
- StringTokenizer example
6 - Basics of Classes Part 2

Static Things (45m)
- static instance variables and static methods
- 3 kinds of memory: local variables (stored on stack), instance variables (stored on heap using "new"), static variables (global memory)
- static method limitations and static examples
- static things in the System class
- static things in the Math class
Eclipse Debugger - This will help you debug your programs
- Debugger basic features: Break Points, Single Step, Resume, Step Into, Step Return, Terminate
- Additional information in windows: Variables, Break points
- Step Filters need to be set to avoid the Deadly Eclipse "Source Not Found Error"
Learning Enrichment: How to use the Eclipse debugger
- If you have difficulty figuring out what is wrong with your program, a previous Learning exercise worked through the idea of adding strategic print statements. Using print statements is a good way to go, but you will find it worth your while to learn how to use the Eclipse debugger. This optional unit goes through some of the key Eclipse debugger features.
Jing: Tool for making a video (needed for a question on JH4)
- Jing allows you to make a short video of what you are doing on your PC screen. Jing is an optional tool for cps161 and could be useful for you to post questions or answers on the discussion board. Jing will be required in the more advanced classes (cps261, cps278, cps251).
- When you want to describe a problem that you are having, you will find JING is a valuable tool to show your problem. With JING you will get a URL to any video you create and this URL can be placed on the discussion board to assist you in creating a Question, or an Answer to a Question.
- The associated video discusses JING installation and demos creating a video.
You now know enough to do JH4
Help for JH4: Hex Calculator Example which is similar to JH4 Roman Calculator problem(38m)
- Hex Calculator is solved in the video which has some commonality with the Roman Calculator
JH4 Help - Hangman(7m)
- Try doing JH4 on your own first, but if you want more hints, see the following:
- Hangman class homework is discussed
7 Midterm Hints, Miscellaneous Entries

Wrapper classes (JPHO)
- Wrapper classes associated with primitives: Byte, Character, Short, Integer, Long, Float, Double
- Wrapper classes are Immutable with no default constructor
- Compiler provides "Boxing" and "UnBoxing"
- Useful methods in the Number Wrapper classes: parseInt, parseDouble, etc.
- Useful methods in the Character class: isLetter, isDigit, isWhitespace, isUpperCase, etc.
Parameters References (JPHP)
- References (addresses) are used for classes
- Parameter passing to methods
  - primitives (int, char, double, etc.) are passed as a copy
  - Mutable classes(Most normal classes) passed by reference and can be changed
  - Immutable classes (String, Integer, Double, other wrapper classes) passed by reference but can't be changed
- null - the keyword for the special "undefined" reference
- Side effects of passing Mutable classes and the use of "Copy-Constructors"
Packages, Access Levels(18m)
- Package is similar to a folder ... default package
- public, private access level and file naming rules for public classes
- default, friendly access method (i.e. no public or private)
- import statements and package statements
- Sample mytools package example with "P" and "In" classes
Learning Enrichment: static versus object-oriented approach
- In JH4, you had a chance to write a program using 2 different approaches (Object-Oriented Programming (OOP) versus using static). Although this particular assignment didn't show the advantages of OOP approachs, you should normally use the OOP approach. This Learning explores the advantages of Object-Oriented programming.
- Object-Oriented Programming (OOP) techniques are the modern way to go with programming. Using static methods and data is the old-fashion "Fortran/Cobol" approach. Using OOP techniques provides the following advantages over older more traditional techniques:
  - OOP techniques create more modular programs that can be expanded to very large projects with many people working on the same project.
  - OOP techniques will usually provide a simpler way to understand the created project
  - OOP code is easier to expand and update.
- Unfortunately first time Java programmers often struggle with and resist using OOP techniques. Common problems include:
  - Putting all code in main
  - Creating too much static (i.e. global) data
  - Not breaking the logic down to simple classes and methods that capture the concepts of the project.
Midterm Procedures and Hints
- Procedures for taking the midterm
- Hints about what you need to know for the midterm
Please take the Midterm ... See the schedule in Blackboard
Eclipse Goodies - Eclipse features that will be useful to you
- Indentation: Eclipse will indent your code automatically
- Refactoring: If you want to rename a variable, Eclipse will automatically update all instances where the variable.
- Packages: Using packages is like having folders to organize your Java code into modules.
Advanced Web Features - Very Useful, but Optional video
- The Learning Units web site has search capabilities that are demonstrated in this video. The Learning Units is organized by the order the videos should be watched. There is a companion web site that is organized by Topics which has more search capabilities.
How to be a good Programmer
- Quick video to encourage you to:
  - Programming Philosopy: Practice, Pay attention to Code readability style issues
  - Tracking down why your program doesn't work: Print statements, Debugger
  - Get to the bottom of your real problem and avoid kludges to cover up symptoms
  - Robust style issues
  - Using the Compiler to assist you
8 Arrays Part 1

Array Fundamentals1(42.5m)
- Allocating and initializing arrays
- Using the length attribute to know the size of the array
- Legal indices and what happens when you access illegal indices
- Arrays of classes
Array Initialization & Method Parameters(33.5m)
- Default array initializations
- Classes stored in an array need to be constructed
- Short cuts for allocating and initializing arrays
- Parameter passing to methods:
  - Primitives
  - Arrays of Primitives
  - Mutable classes
  - Immutable classes (String, Wrapper classes like Integer, Double, etc.)
Array Miscellaneous (JPHQ)
- Multiple references (or names) for the same array
- main(String[]args) - command line parameters
- Methods returning arrays
- Misconceptions and errors with arrays
Array Example: Standard Deviation(7.5m)
- Example: Calculate Standard Deviation calculation from an array of values.
Array Example: Common Birthday(integer date) (15.5m)
- Example: Given a room of N people what is the probability of at least 2 people having the same birthday. In this example we represent birthdays as random integers between 1 and 365.
ArraysExample: Common Birthday (using Date class) (12m)
- Example: Change the previous problem such that we represent birthdays as random "Date" classes.
Array Example: Unique Numbers(20m)
- Example: Given an array of numbers, remove the duplicate numbers and create a new array with just the remaining unique numbers.
JH5 Fraction Help
- "Fraction" Problem help if needed
Most of JH5 should be doable now
9 Arrays Part 2

Select Sort(12.3m)
- Example: Selection Sort algorithm for sorting arrays of doubles from the textbook
Arrays Part2 Miscellaneous(29.5m)
- Enumerated Types:
  - Purpose- to make your code more readable
  - Features: valueOf, valueOf, ordinal, compareTo, values, works with == and switch statements
  - Examples: WorkDay, Flavor, Months, Chess: ColorType and PieceType
- For-each loop
- Variable numbers of parameters
  - System.out.printf
  - Examples: UtilityClass.java, Utility2.java
Array Multi-Dimensions(18m)
- Examples: ticTacToe, battleShip, testScores
- Proper way to go through a 2 dimensional array named page using page.length and page[row].length.
- Demonstrating how memory is organized in a 2 dimensional array called testScores.
- Ragged arrays - flexibility we normally don't need.
- Passing 2 dimensional arrays as parameters
- Returning 2 dimensional arrays from a method
GradeBook and Fantasy Football (JPHR)
- Example: Textbook GradeBook example and its relationship to the Fantasy Football homework
You now know enough to do All of JH5
Bubble Sort(34.5m)
- Example: Sorting arrays using a bubble sort algorithm approach
Matching Game(36m)
- Example: A game consisting of a 2 dimensional grid of pairs that need to be matched. Inspired by a TV show.
Game of Life(45.5m)
- Example: Simulating a primitive community of Ants. Ants live in a 2 dimensional grid. They die if they are too crowed or too isolated. They also can reproduce under certain conditions.
10 - Inheritance

Inheritance: Introduction(46m)
- Inheritance provides a way to eliminate duplication of code when supporting multiple variations of the same code
- Inheritance provides a way to conveniently make use of Building Blocks of code.
- Inheritance implies an "IS_A" relationship
- Examples: World of Living things(Life/Animals/Mammals/etc.), Game of Chess, Textbook Employee/SalariedEmployee
- Constructing Inherited classes using super(Using the textbook Employee, SalariedEmployee, etc example). Note the house construction model for how this operates.
- Calling methods in the parent class. For example super.toString().
- Note that sometimes the relationship between 2 classes should be "HAS A" instead of "IS A". If you get this wrong, the compiler won't know the difference.
Inheritance Odds and Ends(41.5m)
- Review of the usage of super in the previous video with Employee/SalariedEmployee/etc.
- Using the keyword "this" to have one constructor call another constructor to eliminate duplicated code
- IsADemo.java textbook example ... Note that SalariedEmployee "IS A" Employee
- EnhancedStringTokenizer.java to demonstrate adding features to an existing class.
- Overridden methods cannot become less accessable
- Overloading versus Overriding
- Protected access level
JH6 Inheritance Exercise(24.5m)
- Try doing JH6 on your own first, but if you want more hints, see the following:
- Help for the Person, Student, Family problem. In the video we work a similar problem: Employee, HourlyEmployee, Company.
Inheritance More Examples(28m)
- Example: TitledEmployee extends SalariedEmployee
- Example: Squareextends Rectangle - Note the problems that need to be solved with setWidth and setHeight.
- Note that boundingRectangle and intersectingRectangle still get defined as Rectangle even though we may passing Squares.
11 - Inheritance/Polymorphism

Inheritance Object Class(35m)
- Object class - the mother of all classes
- The Object class contains a number of methods including: equals, toString and getClass.
- The behavior of the default equals and toString methods in the Object class.
- Overriding toString and equals in Person.java to provide useful toString and equals methods.
- Overloading "equals" versus overriding "equals". Note the compiler will pick the version that is the closest fit. However, for the long haul in Java, we want to override the "equals" method.
- Writing a proper "equals" method: boolean equals(Object obj)
  - Check for obj being null
  - Check to make sure that obj is a compatible class that can be appropriately cast
    - Using the getClass approach - recommended by the textbook
    - Using "instanceof"
- Keyword "final"
  - Making a variable constant: final int num_rows =10;
  - Making a class so it can't be extended: final class MyFinalClass
  - Making a method so it can be overriden: final void finalMethod()
Polymorphism: Shapes (JPHS)
- Polymorphic (Late Binding) definition - when overriden methods are involved, the decision of which of several methods to call is made at Run-Time and the Java environment knows what kind of object it is really working with. For normal methods (i.e. non-static methods), Java always makes its decisions in a polymorphic manner.
- Early Binding -This technique is used for static methods in Java. In the case of overriden static methods, the compiler will make the decision as to which method to call.
  - The preferred way to call static methods is by specifying the name of the class rather than the object. Using this approach eliminates the need for Early Binding.
- Example: Shape and its derived classes: Rectangle, Square, Circle, Triangle, RegularPoygon
- DemoShapes.java
  - Note the polymorphic decisions made on getArea, getPerimeter
  - Note the approaches used at the end on the static getCount method. Using the class name is preferred.
- Abstract class - a base class that we don't want constructed (like Shape). Often abstract classes have abstract methods (but not necessarily). The Shape example is reworked to make Shape abstract.
  - Classes which extend an abstract class and implement any required abstract methods are constructable.
- Interfaces specify a list of methods which a class needs to implement. The Shape example is also recast to use a Shape interface.
More Polymorphic Examples(24m)
- Example: Shape example again, but this time we create a simple drawing program for ovals and rectangles. We make the Shape class abstract.
- Example: MakeMusic.java an example using an abstract class. Note that we can specify an array of abstract classes even though we cannot construct the abstract class MakeMusic
- Example: MakeMusic.java recast to use interfaces. Note that we now have a Singer class derived from Person which also implements the MakeMusic interface. Note that we can specify an array of objects which implement MakeMusic
Polymorphism Book Examples(22m)
- Textbook Example: LateBindingDemo.java uses Sale.java and Discount.java and demonstrates polymorphism(i.e. Late binding).
- Textbook Example: StaticMethodsDemo.java uses Sale.java and Discount.java demonstrates early binding used with static methods(i.e. the Compiler makes the decisions).
- Textbook Example: CopyingDemo.java - demonstrates 2 approaches to making a copy of an array. The better approach illustrates the usage of a clone routine.
- Textbook Example: reworking the Employee class to be an abstract class with an abstract method called getPay.
You now know enough to do ALL of JH6
12 - Polymorphism/Basics of Drawing and Exceptions

Inheritance/polymorphism Chess Game(45m)
- Example Dumb Chess game: A more realistic example of polymorphsim. In this example, a generic piece class and a generic board class is constructed. Then the generic classes get extended with more specific classes like Rook, Queen, Bishop, etc. There are no new concepts here, but the example provides a better picture of how class inheritance and polymorphism can provide a more intuitive solution.
Drawing Basics(32.5m)
- A simple JFrame based program is built, making use of setSize, setVisible, etc. in the constructor.
- In the paint method, the Graphics class can be used to draw objects on the screen. Methods demonstrated include: setColor, fillRect, drawRect, fillOval, drawLine, fillRoundRect, drawString.
- The basic coordinate system is described. Using getSize, you can always discover the size of your screen.
- The Color class is necessary to change the colors used for drawing on the screen. There are several constructors for creating the desired colors needed.
Exceptions Basics(49.5m)
- Programming without Exceptions (in languages that don't have exceptions like C)
- Demonstrating the occurence of an ArithmeticException (Divide by 0), and catching it
- Demonstrating getting an exception from bad user inputs to the Scanner nextInt method. Also showing how to use the exception to recover from the problem by letting the user enter the number in again.
- Exceptions can be caught locally or globally.
- Comparing exception handling strategies: "readCarefully", or "readAtYourRisk" and catch the errors globally.
You now know enough to do All of JH7
13 - Exceptions, Interfaces

Exception Heirarchy and Strategy(47.5m)
- Class Heirarchy: Throwable, Exception, RuntimeException, etc.
- Unchecked Exceptions (those derived from RuntimeException), versus Checked Exception (not derived from RuntimeException).
- Example to demonstrate 3 Exception handling philosophies (there are other approaches as well)
  - "Evel Knievel" programming style (ignore Exceptions)
  - Global Handling of Exceptions
  - Local Handling of Exceptions to collect more information, but pass the error on to more global routines
  - Local Handling of Exceptions to try to recover from the error locally in order to continue excecuting
- Methods available in the Throwable class (and availabe to all Exceptions classes)
  - getMessage, toString - to print out the error
  - printStackTrace(), printStackTrace(System.out) - to dump the program locations to the standard error stream or the standard system out stream
Checked Exceptions, Input/Output (37m)
- Using the Scanner class to read a file using FileInputStream ( it's similar to reading from the keyboard).
- Using the PrintStream class to produce output using FileOutputStream( it's similar to writing to System.out).
- Checked exceptions occur with most file input/output. Checked exceptions need to be caught or else a compiler occurs.
- Instead of catching an exception, you can "pass the buck" and pass the exception back to the caller with a statement like: throws FileNotFoundException
- The "finally" clause can be used to make sure that something happens before exitting a "try" block.
- Writing code that throws an Exception to prevent user's from improperly using your program. This is demonstrated in the Game-of-Life program. Note that the type of exception you choose can be checked or not-checked. You can even create and throw your own unique Exception class in order to store extra information.
Mouse Interfaces: Spots Painting(38.5m)
- Interfaces are very important in java. In this section, 2 Java interfaces are demonstrated that provide a way to detect mouse clicking, and mouse movement.
- Important things to remember:
  - Have some class implement the desired interface such as MouseListener
  - Add all of the methods required to properly implement the interface (i.e. MouseListener)
  - In the added methods, you can find out information about the mouse through the parameter MouseEvent.
  - Call addMouseListener to inform the system about the class which can be called for mouse activity.
  - A call to repaint will cause the system to call your paint routine again.
- Several examples are created: Spots.java, SpotsSave.java.
- A brief introduction is made of the flexible array approach using the class ArrayList.
- To detect Mouse Motion and dragging, we add one more interface called MouseMotionListener to create the example SpotsArt.java
Mouse Interfaces: Drawing Program(41m)
- Example Simple Drawing Program: In this example we create a simple drawing program by taking the previous Shape/Rectangle/Oval drawing program and combining it with the previous work on detecting Mouse Motion.
Please take the Final
Final Hints
14 - Miscellaneous Fun Extras(not on Final)

Optional Video: Word Search - Problem Solving(42.5m)
- In this video we take a "Top-Down" approach to solving a "Word Search" problem (you often find these on the back of cereal boxes). The program uses Enumerated types and illustrates how to break a problem down into methods starting from the "Top Level" and breaking the problem down into successively lower level modules.
Optional Video: Simple GUI Components(24m)
- In this video you will get a preview of some of the GUI concepts you will see if you continue into cps261. In particular, you will see GUI concepts that will be useful in the next video to construct a Tic-Tac-Toe GUI.
Optional Video: Tic Tac Toe GUI(35m)
- In this video a Tic-Tac-Toe GUI will be constructed from the previous GUI concepts. Notice we don't provide any Tic-Tac-Toe logic in this example. So if you want to have some fun take the JH assignment that covers Tic-Tac-Toe using a keyboard and the console and convert it to using the GUI interface recommended in this video.
Optional Video: Polymorphic Game of Life: Ants and Predators(33.5m)
- When Arrays were covered we created a "game of Life" that just had Ants. In this video we construct a "game of Life" that includes Predators along with the ants. Predators need to eat Ants to stay alive.
- This program will use an abstract class called Organism. The Ants and Predators will be represented as classes which extend Organism. The overall grid will be represented as a 2 dimensional array of Organism. Polymorphism makes all of this work.