CS180 FINAL

0.0(0)
studied byStudied by 0 people
0.0(0)
call with kaiCall with Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/81

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 7:39 AM on 12/16/25
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

82 Terms

1
New cards

What is meant by recursion?

  1. A self reference

  2. Methods can call themselves

  3. Data structures can reference themselves

2
New cards

Why does recursion work?

  1. The method doesn’t always call itself

  2. Data structure doesn’t always link to another copy of itself

  3. Always at least 1 base case of itself

  4. Base case and recursive case

3
New cards

Key tasks of recursion

  • Base: what can be done w/o recursive call

  • Recursive: Same but “smaller”

4
New cards

How is recursion implemented?

  • (stack handles method calls)

  • When method called, params & local vars “pushed” onto call stack

  • Each recursive method call has own params & local vars

  • When method returns, previously executing method (below it on the stack) picks up where it left off

5
New cards

LinkedList brief overview

  • outer class has head and tail nodes

  • private nested Node class has String value and Node link

  • isEmpty is when head and tail are null

  • add appends to tail of list

6
New cards

What are Trees and why are they used?

  • hierarchal w/ one-to-many links

  • good for efficient searching and sorting

7
New cards

root node

no parents

8
New cards

leaf node

no children

9
New cards

interior node

neither root or leaf

10
New cards

Trees are either or

empty (root == null) OR node with links to 0+ trees

11
New cards

binary tree

  • each node references at MOST/MAX 2 other trees

12
New cards

How to conduct binary search

  • key at each node

  1. key in left child of root is smaller than root

  2. key in right child of root is bigger than root

  3. each child is also a binary search tree

13
New cards

inorder traversal

left subtree, root, right

14
New cards

preorder traversal

root, left subtree, right subtree

15
New cards

postorder traversal

root, right subtree, left subtree

16
New cards

Difference between regular data structure vs dynamic

  • organizes, stores and retrieves info in a program

  • memory use grows/shrinks to store info

17
New cards

ArrayList

  • array that grows as elements are added

18
New cards

allocate new instances of ArrayList

ArrayList a = new ArrayList();

19
New cards

add __ to end of ArrayList

a.add(“__”);

20
New cards

replace ArrayList element at index x with __

a.set(x, “__”);

21
New cards

get ith index of ArrayList and print it

System.out.println(a.get(i));

22
New cards

What types can ArrayList hold? What about LinkedList?

single; 2+

23
New cards

components of LinkedList class

  • outer LL class

    • implements getters/setters

    • keeps “head pointer” to head of LL

    • keeps “size” variable to track the size

  • inner LL class

    • implements individual nodes

    • each node linked to another, except last

24
New cards

adding to LL

  • create backwards

  • variable head points to “head node”

  • create new node with link field pointing to current “head node”

  • update head with new node just created

25
New cards

adds String _ to LL

void add(String _)

26
New cards

creates and returns array with all elements

String[] to Array()

27
New cards

ADT

  • abstract data type

  • description of behavior of data type (class) w/o specifying implementation of behavior

  • user of data type unaware, cannot assume implementation details

  • ADT implementer has max flexibility

28
New cards

LIFO

  • Last In First Out, stack

    • push element on

    • pop element off

    • isEmpty to check

29
New cards

FIFO

  • First In First Out, queue

    • put element at end

    • get next from front

    • isEmpty to check

30
New cards

What can you use stack for?

  • undo operations

  • manage storage of local variables for methods being executed

  • RPN

31
New cards

What can you use queue for?

  • file sent to printer

  • threads/processes waiting for access to CPU or core

  • network packets waiting for transmission

32
New cards

HashMap

  • stores values referenced by a key

  • “dictionary” data structure: maps keys to values

  • HashMap<K,V>

    • K: type of key, V: type of value

33
New cards

abstract classes

  • can’t be instantiated

  • methods can be unimplemented (like interface) or for default behavior

  • can be extended from/to smth else, can contain fields

34
New cards

dynamic binding

methods selected at runtime based on class of object referenced, not class of variable that holds object reference

35
New cards

abstract methods

  • provide only header (no body), class also declared abstract

  • methods in interface implicitly declared abstract

  • when subclassing

    • generally provide method bodies for abstract methods

    • if abstract methods remain, subclass still abstract and must be declared so

36
New cards

time-slicing

run each program around a few hundred millisecs

37
New cards

benefit of multiple cores

  • running 2 cores at ½ speed is equivalent to running 1 core at 1/full speed

  • slower cores consume less energy and generate less heat

38
New cards

threads

  • multiple cores can speed up one program

    • can have multiple parts/threads running simultaneously

    • if database spread over 3 files, run 3 threads on 3 cores to run 3x faster

39
New cards

sequential vs concurrent execution

sequential:

  • single thread of execution weaves through program

  • simple PC(program counter) identifies current instruction being executed

concurrent:

  • multiple threads running simultaneously

  • multiple PCs active (1 per thread)

40
New cards

imports Thread class with run() method

import java.lang.*;

41
New cards

allows creation/manipulation of threads

Thread t = new Thread();

42
New cards

starts thread referenced by t

t.start();

43
New cards

join with/wait for running thread t

t.join();

44
New cards

called by start() in different thread

t.run();

45
New cards

How does start() method interact with run() method for Threads?

Code doesn’t call run directly. Start() calls run() as part of new thread sequence

46
New cards

how to create threads

  • make sure class implements Runnable interface

  • implement void run()

  • create new thread

47
New cards

How can threads be unpredictable

  • can be interrupted

    • time slicing threads prevents one from hogging CPU

    • high-priority activities (I/O) can interrupt

  • threads don’t proceed at same rate

  • coordinating threads is challenging

48
New cards

synchronized

  • keyword, allows 2+ threads to use common object to avoid race conditions

  • only 1 thread can be inside statement block at a time

49
New cards

Thread states

  • new thread: created but not yet started

  • runnable: started and available to run

  • not runnable: sleeping or waiting for I/O

  • terminated: returned from run(0

    • t.sleep(n): current thread sleeps for n milliseconds

    • t.yield(): gives up CPU to let another run

50
New cards

IP/internet protocol

identifies hosts (servers, workstations, laptops) w/ unique address

51
New cards

DNS/domain name system

maps domain names (ex. email address) to IP addresses

52
New cards

TCP/transmission control protocol

identifies ports on hosts for network connection

53
New cards

socket

  • IP address + TCP port

  • 2 sockets make a network connection

54
New cards

client-server connection

  • server is process waiting for connection

  • client is process that connects to server

    • process can be both at different times

    • once connected, they can both read/write data to each other

    • communicate thru socket

55
New cards

objects and networking

  • uses ObjectOutputStream and ObjectInputStream

    • OOS generates “header” of info that must be read

    • requires flush to make sure OIS not blocked

56
New cards

models TCP/IP socket

new Socket(“email_address”, __)

57
New cards

getOutputStream and getInputStream

used by Server to identify connected client

58
New cards

Exception Class hierarchy

Exception; IO (FileNotFound); Your; Runtime (Arithmetic, IndexOutOfBounds, NullPointer)

59
New cards

Unchecked definition and classes

  • Program/Java Virtual Machine error, no recovery so crashes

  • Runtime and subclasses

60
New cards

Checked definition and classes

  • user error, must encapsulate in try catch or throw, recoverable

  • all other classes

61
New cards

how many classes and interfaces can a class extend/implement

classes can extend 1 other class, but implement 1+ interfaces

62
New cards

object class methods

  • clone() //make copy

  • equals(Object e) //compares for equality

  • toString() //returns String, called by print

63
New cards

what is constructor chaining

all constructors up inheritance chain can initialize object under construction

64
New cards

what does default constructor have and why

super() calls 0-arg constructor in superclass

65
New cards

overloading

  • same class

  • two methods with same name

  • different signatures

66
New cards

overriding

  • superclass and subclass

  • two methods with same name

  • same signatures

67
New cards

how to check equality for objects

s1.equals(s2)

  • NOT == (only addresses)

68
New cards

keywords that change control flow

if, switch, while, for

69
New cards

A || B vs A && B vs A ^ B

  • A or B

  • A and B

  • A xor B (combo)

70
New cards

generally, what should be access mods for methods, fields, and constants

  • methods: public

  • fields: private

  • constants (final): public

71
New cards

arraylist syntax (non empty)

ArrayList<String> list = new ArrayList<String>()

72
New cards

arraylist syntax (empty)

ArrayList<String> list = new ArrayList<>();

73
New cards

buffer

  • holds info for speed/efficiency

  • remember to close file/flush buffers when done

  • write and read order must be the same

74
New cards

static vs transient

  • for the class

  • for instance variables, good if need to be regenerated anyways

75
New cards

what classes can you use to write/read to file

  • PrintWriter

  • FileReader, BufferedReader, Scanner

76
New cards

exception messages

  • e.getMessage() //gets associated text message

  • e.printStackTrace() //prints current call stack

77
New cards

finally keyword

executed after all try-catches, guaranteed to execute

78
New cards

import for JOptionPane class and other imports

import javax.swing.*;

79
New cards

simple GUI methods

  • showMessageDialog()

  • showInputDialog()

  • showConfirmDialog()

  • showOptionDialog

80
New cards

gui message types

plain, error, information, warning, question

81
New cards

what other import is needed for complex guis

import java.awt;

82
New cards

EDT and what import do you need

  • event dispatch thread

  • own thread for Java GUI

  • SwingUtilities.invokeLater(Runnable method);