Concepts for the Final 0145-172
Class types: Inheritance, Interface, Abstract
· sub-class extends regular or abstract class & implements interface
· sub-class must contain all abstract methods from interfaces and abstract classes
· concrete sub-class (non-abstract) can make an object and must implement all abstract methods from above it
· interface: no instance variables and no method definitions
o (though in java 8 there is a way to add method definitions)
Polymorphic variables:
· can hold any lower type;
· will execute from lowest to highest (so overridden methods take effect)
· can only execute method names available (abstract or not) for the variable type
File Processing:
· Input: Scanner: Screen, String, File
· Output: PrintStream
· Create and Throw Exceptions
References
· all objects pass to methods by reference; (but Strings are immutable)
o Object variables hold a the object starting address
· all primitives pass to methods by value
· shallow copy - copy structure but leave references inside pointing to the old objects
· deep or complete copy – copy both structure and objects inside the structure
Primitive Arrays
· Multidimensional
· Arrays static class
Class Creation and Use
· Object Class:
o Create from scratch or modify existing)
o Instance variables; private/ public accessor
o methods
§ know whether you need static;
§ access instance variables with this.
§ can override with different parm types
§ can override superclass methods
§ add methods to an existing class
o constructors as special method types
· Object User Class:
o Create objects with new keyword
o Use object methods with object name . method name
§ follow input/output contract of the method
Collections:
· Lists (LinkedList and ArrayList) and Iterators
· Sets (HashSet and TreeSet) and Iterators
· Maps (HashMap and TreeMap) and KeySets
· Stacks and Queues (classic methods: add/push, remove/pop, isEmtpy, peek, size)
· Collections can hold objects as well as their own type
· Collections and Arrays static classes for its tools
· Comparators (outside class, compare) and Comparable (inside object class, compareTo) Interface
o negative lower, positive higher, 0 equal
Sorting and Searching
· Sort methods (Selection, Bubble, MergeSort)
· Search methods (Linear, Binary)
· Big O notation to indicate algorithm growth rates
Recursion
· How to code a simple recursive method
· How to trace recursion
Not testing:
· Create a linked list from scratch (meaning code the node)
· Design patterns
· Binary Tree Traversals
· Tester
-------------------------------------------
Some charts:
What you are
bringing in |
Filled Contain |
Shorthand Contain |
Keyword when using
it |
Create an object |
Create a variable |
|
Interface |
Method contracts |
Nothing but contracts |
implements |
No |
Yes |
|
Class |
Methods and variables |
Tons |
Extends |
Yes |
Yes |
|
Abstract Class |
Methods and variables and method contracts |
Somewhere between tons and contracts |
extends |
No |
Yes |
|
Compare and Sort Words
Words |
Type |
Implemented inside Item class |
Group |
Sort Type |
Use by Collection Sort |
TreeMap and TreeSet |
Comparable |
Interface |
Y |
Comparable |
Natural |
Default |
Default |
compareTo |
method |
Y |
Comparable |
Natural |
If
no parm |
If
no parm |
Comparator |
Interface |
N |
Comparator |
Alternate |
Added parm new
Comparator() |
Added parm new
Comparator() |
compare |
Method |
N |
Comparator |
Alternate |
If parm |
If parm |
Confusing names
Name |
meaning |
Throw |
Throw a new exception |
Throws |
Passes the exception it receives back to the
caller |
Collections |
A static class with tons of good methods |
Collection |
An Interface that is implemented by List
and Set |
Coding process helps:
-
Sketch a UML diagram
o
Choose instance variables:
§
if private: only the class can
see it, no other classes
§
can use it as a parameter inside all the class's methods; it is shared by all
methods in the class.
§
it is a minibox
of data within the object when it is created
§
Point p = new
Point(1,2); p.x
as 1 and p.y as 2
-
Write available variables at the top of each hard
method; don't forget your instance variables with this.
-
Verify method contracts are met after coding
o
Caller:
§
Call with correct number of
variables
§
Take in returned input
o
Method:
§
return correct variable type