Midterm Review - PowerPoint PPT Presentation

1 / 26
About This Presentation
Title:

Midterm Review

Description:

The elements of an array are in adjacent memory locations ... an array, so each node must store the location of node in the structure this ... – PowerPoint PPT presentation

Number of Views:43
Avg rating:3.0/5.0
Slides: 27
Provided by: samirt
Category:
Tags: midterm | review

less

Transcript and Presenter's Notes

Title: Midterm Review


1
Midterm Review
  • Samir Tartir
  • Oct 9, 2008

2
Unix Commands
  • Directory mkdir, rmdir, cd, ls, pwd
  • File cp, mv, rm, cat, less, head, tail
  • Process ps, kill

3
Partial Specification of the Rectangle ADT
getLength() pre-condition none responsibilities
returns this rectangles length post-condition
the rectangle is unchanged returns the length
of the rectangle setLength( newLength
) pre-condition none responsibilities resets
length to newLength if newLength is valid
otherwise does nothing post-condition
rectangles length field is updated if newLength
is valid returns nothing getSurfaceArea() pre-c
ondition none operation compute the surface
area of this rectangle post-condition the
rectangle is unchanged returns the surface area
of the rectangle
4
OO Principles
  • State, behavior
  • Inheritance
  • Overloading
  • Polymorphism

5
Polymorphism a form of code reuse
Polymorphism Allow a block of code to be used
with different types of data
Substitution principle we can Substitute
instances of a subclass for an instance of its
superclass
1 // create N monitor references 2 Monitor
monitor new Monitor N 3 4 //
populate array with Monitor instances 5
monitor0 new PressureMonitor() 6
monitor1 new TemperatureMonitor() 7
monitor2 new RadiationMonitor() 8
monitor3 new HumidityMonitor() 9 // and
so on... 10 11 // now have each one do a
regular checkup 12 for ( i 0 i lt
monitor.length i ) 13
monitori.doSelfCheck() 14
monitori.logStatus() 15
Dynamic binding the runtime system will bind an
object reference to a specific object at the time
of the method call
Monitori is bound to a specific type (e.g.,
PressureMonitor, HumidityMonitor) at runtime,
ensuring that the correct version of the methods
is invoked.
6
UML Diagrams
- Class diagram - Object diagram - Sequence
diagram
7
UML Class and Object Diagrams
UML class diagrams
UML object diagrams
8
OO
  • super()
  • variable and method access declaration

9
Generic Types in Java
Format for a generic (parameterized) type and
instantiation of a generic type
10
Javas Exception Hierarchy
remember, this means extends
11
Try-Catch-Finally Blocks
The first catch block with an ExceptionTypeX that
matches the type of the exception thrown in the
try-block will execute. The other catch-blocks
will be skipped. Then the finally-block executes.
try program statements some of which may
throw an exception catch ( ExceptionType1
exception ) program statements to handle
exceptions of type ExceptionType1 or any of its
subclasses catch ( ExceptionType2 exception )
program statements to handle exceptions of
type ExceptionType2 or any of its subclasses .
. . // other catch clauses catch ( ExceptionTypeN
exception ) program statements to handle
exceptions of type ExceptionTypeN or any of its
subclasses finally this block is optional
program statements that execute after the try
block or a catch block has executed this
block will execute whether or not an exception is
thrown
12
Test Cases
Test Case 2.1 Instantiation of a Rectangle object
using default values for the attributes
13
Two Types
  • Black-box
  • Clear-box

14
JUnit
  • imports, extends
  • fixtures
  • setUp() and tearDown()
  • public void testABC()
  • assertX()
  • assertY()

15
Time Complexity Count Instructions
How many times will each instruction execute?
16
?(g(n)) ?(g(n))
  • A function f(n) is ?(g(n)) if there are positive
    constants c1, c2, and n0 such that 0 ? c1g(n) ?
    f(n) ? c2g(n) for all n ? n0.
  • A function f(n) is ?(g(n)) if there are positive
    constants c and n0 such that f(n) ? cg(n) for all
    n ? n0.

17
Array Characteristics
  • An array is a homogeneous data structure all
    elements must be of the same type this mean each
    cell will be the same size
  • The elements of an array are in adjacent memory
    locations
  • Because each cell has the same size and the cells
    are adjacent in memory, it is possible to compute
    the address of an array cell so an array access
    costs a computation followed by a memory access
  • ? an array is a random (direct) access data
    structure

18
Array Operations
  • Traversing can be bidirectional
  • Resizing can make a new array that is smaller
    or larger than the original array a ?(size of
    new array) operation
  • Replacing an element an O(?) operation
  • Inserting an element an O(?) operation due to
    data movement
  • Deleting an element O(?) or O(?) depending on
    implementation

19
Linked Structure Characteristics
  • Nodes in a linked structure are allocated
    individually, so the number of nodes in the
    linked structure can grow and shrink as needed
  • The nodes of a linked structure are not
    necessarily adjacent in memory
  • Because the nodes of a linked structure are not
    necessarily adjacent in memory, the computer
    cannot calculate the address of a node as it
    could for a cell in an array, so each node must
    store the location of node in the structure
    this reference is the link
  • ? a linked structure is a sequential access data
    structure

20
SLNode Construction
21
A Doubly-Linked List
  • The singly-linked list is unidirectional
  • At the expense of an additional link (and the
    consequent code complexity) we can have a
    bidirectional list

We need to add a second link attribute to the
node definition
22
Circular Linked List
23
Java Collections Framework
  • Required Methods
  • Optional Methods

24
Wildcards
  • Unbounded (?)
  • 20 static void printAnyCollection( Collectionlt?gt
    collection )
  • 21 for ( Object element collection )
  • 22 System.out.println( element )
  • 23
  • Bounded (? Extends )
  • 2 public boolean addAll(Collectionlt? extends Egt
    c)
  • 3 boolean modified false
  • 4 Iteratorlt? extends Egt e c.iterator()
  • 5
  • 6 while ( e.hasNext() )
  • 7 if ( add( e.next() ) )
  • 8 modified true
  • 9
  • 10 return modified
  • 11

25
Iterator Concurrent modifications
  • Detecting concurrent modification
  • Modcount expectedModCount
  • Iterator.remove
  • okToRemove

26
JCF interface/abstract class support for List
Write a Comment
User Comments (0)
About PowerShow.com