CSE 2221

0.0(0)
studied byStudied by 0 people
0.0(0)
full-widthCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/70

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

71 Terms

1
New cards

@requires

Precondition; The caller must ensure this is true.

2
New cards

@ensures

Postcondition

3
New cards

@updates

The method changes (updates) this parameter. The final value may depend on the initial value.

4
New cards

@replaces

The method gives this parameter a completely new value. It does NOT depend on its old value.

5
New cards

@restores

The method leaves this parameter unchanged.

6
New cards

@clears

The parameter is set to its “cleared” or empty state.

7
New cards

#x

Original Value before the method starts

8
New cards

|s|

number of characters in string s

9
New cards

rev(s)

s written backwards

10
New cards

entries(s)

set of characters in s (no duplicates)

11
New cards

{a, b, c}

a set (order doesn’t matter, duplicates removed)

12
New cards

s * n

s repeated n times

13
New cards

x x x * x

x concatenated with itself 4 times

14
New cards

P ∧ Q

both P and Q are true (AND)

15
New cards

P ∨ Q

at least one is true (OR)

16
New cards

¬P

NOT P

17
New cards

P ⇒ Q

if P is true, Q must be true

18
New cards

P ⇔ Q

P and Q mean the same thing (equivalent)

19
New cards

isZero()

NaturalNumber Kernal; checks if is zero

20
New cards

divideBy10()

NaturalNumber(); removes last digit and returns it

21
New cards

multiplyBy10(d)

NaturalNumber(); appends digit d

22
New cards

increment()

NaturalNumber(); adds 1

23
New cards

decrement()

NaturalNumber(); -1

24
New cards

copyFrom(other)

NaturalNumber(); copyFrom

25
New cards

Static Methods

No this parameter; Called without a receiver

26
New cards

Instance Methods

without static; Called with a receiver; Has this parameter

27
New cards

Overriding

new body for same method signature.

28
New cards

Overloading

same name, different parameters

29
New cards

Declared Type (Static Type):

type in variable declaration

30
New cards

Object Type (Dynamic Type)

type from constructor (new)

31
New cards

@Override

Implementing interface method

Overriding superclass method

32
New cards

Polymorphism

Method body used is determined by object type of receiver, NOT declared type.

33
New cards

Primitive

boolean, char, int, double

34
New cards

Reference

String, XMLTree, NaturalNumber, etc.

35
New cards

Assignment with primitives

copies VALUE

36
New cards

Assignment with references

copies REFERENCE VALUE (memory address) (ALIASES)

37
New cards

Aliasing

When two references point to same object:

NaturalNumber n = z;

n.increment(); // Changes BOTH n and z! (same object)

38
New cards

Immutable

(safe to reason like primitive): String, XMLTree

39
New cards

Mutable

(danger with aliases): NaturalNumber, SimpleReader, SimpleWriter

40
New cards

Pass by Value/Call-by-Copy/Call-by-Value

a copy of the actual value is passed to the function.

41
New cards

Pass by Reference

Gives the function access to the memory address of the original variable.

42
New cards

Design-by-Contract

If precondition true → method terminates with postcondition true

43
New cards

Monte Carlo Estimation

Throw darts randomly at known region

Count hits inside shape vs total

Estimated area = (hits / total) × known_area

44
New cards

Java's % is NOT true modulo for negative numbers!

(-67) % 24 = -19 DIFFERENT from mod!

45
New cards

transferFrom

NaturalNumber is a reference type! The method receives a reference and can modify the object.

46
New cards

private static void foo(NaturalNumber x, NaturalNumber y) {

// Ensures: x = #x + 1 and y = #y + 2

}

NaturalNumber a = new NaturalNumber2(10);

foo(a, a);

// REPEATED ARGUMENT!

47
New cards

Height

int maxSubtreeHeight = 0;

if (t.isTag()) {

for (int i = 0; i < t.numberOfChildren(); i++) {

int h = height(t.child(i));

if (h > maxSubtreeHeight) {

maxSubtreeHeight = h;

}

}

}

return maxSubtreeHeight + 1;

48
New cards

Unit Testing

Test individual components (one method/class at a time)

49
New cards

Integration Testing

Test multiple components together

50
New cards

System Testing

Test entire end-user system

51
New cards

Goal of Testing

Show that code has DEFECTS (not prove correctness!)

Testing can show presence of bugs, never their absence"

52
New cards

Test Case Design

Three types:

  1. Boundary cases: smallest, largest, special values

  2. Routine cases: typical/normal inputs

  3. Challenging cases: difficult/error-prone situations

53
New cards

Invalid Test Cases

Don't test with inputs that violate precondition - these reveal nothing!

54
New cards

Queue

FIFO: First-In-First-Out (like a line at a store)

55
New cards

Wrapper Types

Java automatically converts between them

Boolean

Character

Integer

Double

56
New cards

Generics

Generic arguments must be reference types (not primitives)

List<**Integer**> myList = new ArrayList<>();

57
New cards

How does program know when user clicks button, types key, etc.?

  1. Polling(bad ): Program constantly checks each widget: "event? event? event?"

  2. Callbacks(Good):

    1. Observer registers interest with subject

    2. Subject keeps list of observers

    3. When event occurs, subject calls back each observer

58
New cards

Threads

Initial thread: runs main() until complete
Event dispatch thread: runs Swing code and callbacks

59
New cards

Model

Data and business logic (no GUI knowledge)

60
New cards

View

GUI widgets and display (extends JFrame, implements ActionListener)

  1. Create JFrame

  2. Set up widgets

  1. Register observers

  1. Start window

61
New cards

Controller

Mediates between Model and View

62
New cards

Loop Invariant

Property that is true every time you reach the loop condition test.

63
New cards

Loop Invariants to Trace

Don't trace loop body! Use invariant + condition:

Before loop: this = <1,2,3>, q = <4,5,6>

After loop (when test false):

- Invariant says: this * q = <1,2,3,4,5,6>

- Condition false says: |q| = 0, so q = < >

- Therefore: this = <1,2,3,4,5,6>

64
New cards

perms()

perms(s1, s2) checks if strings are permutations (reorderings):

javaperms(<1,2,3>, <3,1,2>) // true

perms(<2,2,1>, <2,1>) // false (different lengths)

65
New cards

entries()

Converts string to set (removes duplicates, ignores order):

javaentries(<2,2,2,1>) = {1, 2}

66
New cards

Class

is a blueprint for creating objects

67
New cards

Interface

contract—a formal declaration of a set of related methods that any implementing class must provide

68
New cards
69
New cards
70
New cards
71
New cards