INFO3136 EXAM Flashcards

1
Q

What is a process?

A

The entire program

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is a thread?

A

Small part of a process

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is process based multi-tasking controlled by?

A

OS (Kernel)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is thread based multi-tasking controlled by?

A

JVM

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Each thread gets its own what? (2)

A
  1. Call Stack
  2. Program counter
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What happens if a thread cannot complete its task in the allotted time?

A

The thread is suspended

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What happens when a thread is suspended?

A

State data is stored in CPU cache memory until text turn

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are the 2 ways to create threads in Java?

A
  1. Implement Runnable interface
  2. Extend Thread class
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What method is in the Runnable interface?

A

run()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Why should you never call the run() method?

A

Method is automatically invoked by JVM. If you call it explicitly then a new thread is never made

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What method is used to signal to the JVM that a thread is ready?

A

start()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What method is used to give up a thread’s remaining time?

A

yield()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What method is used to temporarily stop a thread?

A

sleep(long milliseconds)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What kind of exception can the sleep() method throw?

A

InterruptedException

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is the normal priority of a thread?

A

5

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What kind of scheduling involves threads of equal priorities?

A

round-robin scheduling

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What is it called when a low-priority thread never gets to run due to higher priority threads?

A

thread contention or thread starvation

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What is the concurrency problem encountered in the 70’s called?

A

Lost Update Scenario

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What were created to fix concurrency issues?

A

Transaction Rules

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

What is an example of a synchronized data structure in Java?

A

Vector

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

What kind of data structure is an ArrayList when considering threads?

A

Unsynchronized

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

Which is faster, a synchronized data structure or an unsynchronized?

A

Unsynchronized

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

What is it called when an unsynchronized program component allows data corruption?

A

Race Condition

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

What is it called when a class or data structure does not allow data corruption?

A

Thread-safe

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

What is the portion of the program holding the variable or data structure that can cause race conditions?

A

Critical Region

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q

What keyword is used to prevent multiple threads from affecting the critical region?

A

synchronized

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
27
Q

What does the keyword synchronized do?

A

Gives the method a lock on the data structure to guarantee exclusive access

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
28
Q

What state are threads placed in when waiting for a thread with a lock to finish processing?

A

wait

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
29
Q

What 3 methods are part of the Lock interface?

A
  1. lock()
  2. unlock()
  3. newCondition()
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
30
Q

What is meant by atomic in the atomic classes?

A

The whole operation is completed as a unit and cannot be interrupted

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
31
Q

What is the keyword volatile attached to?

A

A Variable

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
32
Q

What does the keyword volatile do?

A

Tells the JVM that the variable will be accessed by multiple threads, so the value should be read from main memory every time

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
33
Q

Do volatile variables have locks on them?

A

No

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
34
Q

What are the 5 states of a thread?

A
  1. new
  2. runnable/ready
  3. running
  4. blocked
  5. terminated/dead
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
35
Q

What class holds the sleep() method?

A

Thread

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
36
Q

If a thread is put to sleep with a lock on a data structure, what happens to the lock?

A

Nothing

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
37
Q

What does a thread that has yield() invoked on it do?

A

Signals to the OS that it is willing to step aside

38
Q

What class holds the yield() method?

A

Thread

39
Q

What class holds the wait( ) method?

A

Object

40
Q

How many public methods are in the Object class?

A

7

41
Q

What conditions must be met to use the wait() method?

A

Has an explicitly acquired lock on an object inside a synchronized method or block of code

42
Q

What class holds the notify() and notifyAll() methods?

A

Object

43
Q

What does notify() do?

A

Randomly selects a thread waiting for the object that is locked to get ready

44
Q

What is the difference between notify( )and notifyAll()?

A

notifyAll() wakes all threads waiting up and allows the OS scheduler to choose which is next

45
Q

What does the join() method do?

A

Stops other threads from executing until the thread that called join() is finished

46
Q

What is the problem with calling stop( ) on a thread?

A

Terminated thread immediately releases its lock on any data members possibly corrupting the data

47
Q

What method is used in place of stop()?

A

interrupt()

48
Q

How does interrupt() work?

A

Thread that calls interrupt() sets the interrupt status boolean flag of the running thread to true.

49
Q

When should you use a thread pool?

A

If you have a lot of short-lived threads that don’t require a lot of I/O operations

50
Q

What method is held in the Executor interface?

A

execute(Runnable r)

51
Q

What is ExecutorService?

A

A sub-interface for Executor

52
Q

What is the purpose of ExecutorService objects?

A

Manage threads in a pool

53
Q

How do you create a thread pool?

A

ExecutorService lifeguard = Executors.newFixedThreadPool(int i);

54
Q

What class implements Executor and ExecutorService?

A

Executors

55
Q

How does a newCachedThreadPool work?

A

New threads are created as needed if more tasks are created, idle threads stay in pool for a maximum of 60 seconds

56
Q

What are the 2 ways to end a thread pool operation?

A
  1. shutdown()
  2. shutdownNow()
57
Q

What is the difference between shutdown() and shutdownNow()?

A

shutdown() allows all remaining threads in the pool to complete their run() code, shutdownNow() only allows the currently running threads to finish and terminate the rest

58
Q

What is the Swing thread called?

A

Event Dispatch Thread

59
Q

What is the JavaFX thread called?

A

JavaFX Application Thread

60
Q

What is it called when only one thread is allowed to access components?

A

Thread Confinement

61
Q

Considering single GUI thread, when is it a good idea to use a different thread?

A

When there are lengthy calculations

62
Q

What listener is used to alert the event dispatch thread that a worker thread is complete?

A

PropertyChangeListeners

63
Q

What are the 2 constraints for Java GUI apps?

A
  1. Time consuming tasks should not run on the event dispatch thread
  2. Swing components should only be accessed by the event dispatch thread
64
Q

What class is used for offloading tasks from the event dispatch thread?

A

SwingWorker

65
Q

What interface does SwingWorker implement?

A

Future< T >

66
Q

What method is used to return the value gotten through a class that extends SwingWorker?

A

get()

67
Q

What are the T and V in SwingWorker<T, V>?

A

T - return type
V - type used for intermediate results

68
Q

What 2 methods use the V in SwingWorker<T,V>?

A
  1. publish()
  2. process()
69
Q

What SwingWorker method is analogous to the run() method of Thread and Runnable?

A

doInBackground()

70
Q

What is the Model in MVC pattern?

A

Maintains the data to be displayed. Holds the state

71
Q

What is the View in the MVC pattern?

A

Displays the data in the model

72
Q

What is the Controller in the MVC pattern?

A

Handles user inputs and can update the model

73
Q

What kind of design pattern is MVC?

A

Compound Design Pattern

74
Q

Why is MVC considered a compound design pattern?

A

It is a composite of several simpler design patterns

75
Q

What has to happen for the View in MVC to update automatically when the Model changes?

A

View has to be registered as a listener

76
Q

What does JDBC stand for?

A

Java Database Connectivity

77
Q

What 3 objects do we make when setting up a JDBC connection?

A
  1. Connection
  2. Statement
  3. ResultSet
78
Q

What changed about methods in interfaces after JDK 1.8?

A

Used to only be abstract (no body), but now can contain default methods

79
Q

What does adding the “static” keyword to a default method in an interface do?

A

Stops it from being overridden

80
Q

What is a SAM?

A

Single Abstract Method interface

81
Q

What is an interface with only one abstract method called?

A

Functional Interface, or SAM

82
Q

Can a functional interface have default methods?

A

Yes, but only one abstract method

83
Q

What is a lambda expression?

A

Coding short-hand that can be used to represent an anonymous method

84
Q

What is the syntax of a lambda expression?

A

(parameter list) -> { one or more statements to be run }

85
Q

What is an exception?

A

An object that signals an error has occurred

86
Q

What is the parent of all exception classes?

A

Throwable

87
Q

What is the parent of the Runtime class?

A

Exception

88
Q

Which class defines exceptions that you don’t have to deal with?

A

Error

89
Q

What kind of exceptions are Runtime exceptions?

A

Unchecked

90
Q

What class describes checked exceptions?

A

Exception

91
Q
A