Final Exam Flashcards

1
Q

Process

A

Instance of an application running on a system

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

A process that tries to use memory not allocated to it will generate a ___

A

Segmentation fault

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

Each process can run one or more ___

A

Threads

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

T/F: Cores can run multiple threads at once

A

False

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

Each process is given a ___ to complete its work

A

Time slice (normally a constant)

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

T/F: Two processes cannot read from each other’s memory

A

True

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

All threads in the same process ___

A

Share the same memory space

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

The two ways to have Java execute threads

A

Executing the main thread
Extending the Thread class

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

T/F: A thread initiated with the start method will execute separately from the main method

A

True

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

Calling the run method instead of the start method on a thread

A

Will execute it in the main thread instead of its own

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

Scheduler

A

Controls when, and if, a thread gets to run. Minimal control over it. Like a black box–unpredictable.

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

NEW (thread state)

A

A thread has been created but start not called

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

RUNNABLE (thread state)

A

Start called and nothing is preventing thread from running

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

Running (unofficial thread state)

A

Thread is executing on a processor

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

DEAD (thread state)

A

A thread has finished its execution or has been terminated

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

To check if a thread is not DEAD state

A

isAlive()

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

Threads can be created by ___ Thread or ___ Runnable

A

Extending. Implementing. Runnable instances must be passed into thread constructors

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

Pros and cons of extending Thread

A

Pro:
Less code

Con:
Single inheritance. Run method optional. Can’t be restarted.

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

Pros and cons of implementing Runnable

A

Pros:
Multiple inheritance. Must override run. Can be restarted in new thread.

Cons:
More code

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

When multiple threads are running their output is ___

A

Interleaved. Some may run on same core, others on other cores.

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

Busy Wait

A

Pinging a thread repeatedly to see if it is complete (using isAlive()). Wastes CPU cycles while doing no work.

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

Threads can relinquish their time in a processor by using ___

A

Sleep

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

Sleep can be used to:

A

Simulate passage of time.
Let other processes work while it waits.

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

T/F: Upon awaking, a thread will immediately begin running again

A

False. It must wait to be scheduled.

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

Exception for sleep

A

Interrupted Exception. Checked. Can basically be ignored.

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

Sleep should always be called on ___

A

The Thread class (not an instance)

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

Join

A

Allows threads to queue, running one after the other has finished (used after start)

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

Joining threads stops them from

A

Running concurrently

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

Race condition

A

When two or more threads are trying to access/update the same shared resource

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

Context switch

A

When the active thread changes between retrieving a value and using said value

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

Shared resources are also known as ___

A

Critical regions. Unsafe in multi-threaded environments unless protected

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

A protected critical region is ___

A

Thread Safe

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

Resource contention

A

When two or more threads attempt to manipulate the value of a shared resource at the same time

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

Non-atomic operation

A

An operation that is implemented with at least two separate instructions

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

Synchronized

A

Keyword used with an object key to create a mutually exclusive lock

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

T/F: Primitive types can work as keys to synchronize on

A

False. Must be a reference type/object

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

If a second thread tries to access a synchronized block using the same object key ___

A

It will be locked out and enter a blocked state

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

When a thread exits a critical region, it ___ the lock and a ___ thread will transition to the ___ state

A

Surrenders. Blocked. Runnable.

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

Threads trying to access the critical region must have access to the ___. Because of this, it is common to use the ___ itself as the ___.

A

Object key. Shared resource, key.

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

Synchronizing the entire run method causes threads to run ___ rather than ___

A

Sequentially. Concurrently.

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

To minimize the amount of time threads are blocked, synchronization should be done in a ___ way

A

Surgical

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

If you control the object code for a shared resource, one option is to

A

Synchronize on methods or portions of methods in the object

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

T/F: Synchronized code runs much slower than code that is not synchronized, even if it is only used by one thread

A

True.

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

T/F: Most Java standard libraries are thread-safe

A

False. Too slow. Most code is for single thread.

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

Hashtable

A

Thread-safe version of HashMap. Deprecated. Don’t use.

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

Polling

A

Checking if a thread can proceed at certain time intervals. Can cause delay from when job is added and thread checks

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

Lock.wait()

A

Pauses execution of the thread indefinitely. Surrenders the lock.

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

Lock.notify()

A

Notifies a waiting thread that is waiting on the same lock

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

Lock.notify() chooses __ thread and moves it to the __ state

A

One. Blocked.

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

T/F: Notify surrenders the key on the lock

A

False. Key only surrenders when exciting synchronized block or when waiting

51
Q

Parallel processing

A

Divide and conquer technique for handling work that can be divided between multiple threads

52
Q

Lock.notifyAll()

A

Moves all waiting threads into the blocked state. Only one will get the lock when available.

53
Q

Producer

A

Creates jobs that will be put in a queue to be performed by the consumer

54
Q

Consumer

A

Executes jobs from the work queue created by producers

55
Q

Blocked versus Waiting

A

Blocked thread is trying to get into a synchronized block but is prevented. Will immediately transition to Runnable when chosen by thread scheduler. Cannot be interrupted.

Waiting is for some event to occur. Will not transition to Runnable even if object key is available. Can be interrupted.

56
Q

Deadlock

A

When threads try to obtain more than one lock at a time and are blocked by a thread trying to get a lock it holds.

57
Q

T/F: A deadlock can’t be recovered from

A

True

58
Q

Deadlock conditions

A

Mutual exclusion - at least one resource can’t be shared among processes
Hold and wait - process holds lock while waiting for another lock
No preemption - no mechanism to force process to relinquish lock it holds
Circular wait - process must be waiting for a resource held by a process that is waiting on the same thing

59
Q

Starvation

A

Thread getting so little time on processor that it can’t do work

60
Q

Network

A

Hardware and software that provides two or more computers ability to communicate with each other

61
Q

Connection

A

Established when one computer pings another listening one. Can be used to send and receive data.

62
Q

Protocol layering

A

Divides network designs into functional layers, each with its own protocols and specific purpose, independent of the others

63
Q

DoD 4-Layer Model

A

(Department of Defense) aka TCP/IP Model:
Application
Transport
Internet
Network Access

64
Q

OSI 7-Layer Model

A

(Open Systems Interconnection)
Application
Presentation
Session
Transport
Network
Data Link
Physical

65
Q

IP

A

Internet Protocol. Runs in network layer and handles routing and relaying packets of info.

66
Q

TCP

A

Transmission Control Protocol. Establishes connection between two computers and helps ensure packets delivered in order, reliably, and without corruption

67
Q

Every Internet-connected system must have a unique ___

A

IP address

68
Q

IPv4

A

A 32-bit (4-byte) binary number represented as a dotted quad

69
Q

Because of the limit in number of IP addresses under IPv4, many computers on private networks are connected through ___, which gets an IP address

A

Single router or proxy. Computers connected to router use private addresses

70
Q

Hostname

A

Human readable address

71
Q

DHCP

A

Dynamic Host Control Protocol, which changes a computer’s IP address as needed

72
Q

DNS

A

Domain Name Server. Provides service that maps a hostname to real address for the computer

73
Q

InetAddress get hostname and IP address

A

getByName(String host)
getLocalHost()

After creation:
getHostAddress()
getHostName()

74
Q

Loopback address

A

Special address that always refers to the local computer. 127.0.0.1

75
Q

localhost

A

Special hostname that refers to local computer

76
Q

Hypertext document

A

A document that contains links to other documents

77
Q

HTTP

A

Hypertext Transfer Protocol. Client always initiates communication by sending a request. The server always responds.

78
Q

URL

A

Uniform Resource Locator. Defines a unique location of a resource on the web
service://host:port/file and resource details

79
Q

To create a URL in Java

A

URL u = new URL(“http://nasa.gov/”);

80
Q

If Java does not understand a protocol, a ___ will be thrown

A

Checked MalformedURLException

81
Q

T/F: URLConnection is an abstract class because each protocol defines its own message format

A

True. Subclasses provide specific implementations (e.g. HTTPURLConnection)

82
Q

To connect to a resource.
To read data from a resource.
To write to a resource.

A

connect()
getInpurStream()
getOutputStream()

83
Q

T/F: URL and URLConnection only work with established Internet protocols like Http

A

True

84
Q

Class for establishing TCP/IP connection using specific hostname/IP and port

A

Socket

85
Q

T/F: Trying to connect to a port not being used to listen for connections will NOT cause an error

A

False. Will throw a checked exception.

86
Q

All exceptions regarding socket use are

A

IOException

87
Q

Once a TCP/IP connection is established, both sides are represented as ___

A

Sockets

88
Q

To send text data instead of binary data, it must be wrapped in an instance of ___

A

The PrintWriter class
PrintWriter writer = new PrintWriter(stream);

89
Q

PrintWriter methods

A

println(String) - writes string of text terminated with a newline
write(char[]) - writes a character buffer
flush() - sends any buffered data to the other side

90
Q

To received text data instead of binary, it should be wrapped in an instance of

A

Scanner
Scanner SC = new Scanner(stream);

91
Q

A port is a __ number between __ and __

A

Positive. 1 and 65,535. Most of the ports below 1500 are reserved for computer operations

92
Q

The accept() method will __ until a client establishes a connection

A

Block

93
Q

TCP/IP is __. Client and server must ___ before they can communicate

A

Connection-oriented. Established a connection.

94
Q

T/F: TCP/IP guarantees that packets are delivered in order and without corruption.

A

True. With a lot of overhead cost.

95
Q

UDP

A

User Datagram Protocol. Connectionless alternative to TCP/IP. Messages are addressed and delivered, but may be lost.

96
Q

T/F: UDP is slower than TCP/IP.

A

False. UDP is much faster and potentially less reliable.

97
Q

A DatagramPacket is constructed with __ and __

A

Byte[] data (getData()) and length (getLength ()) of bytes. And, optionally, the InetAddress and port of the recipient.

98
Q

DatagramSocket

A

Constructed with a port to send and receive UDP messages
send(DatagramPacket)
receive(DatagramPacket)

99
Q

If the buffer for an incoming Datagram message isn’t large enough

A

It will be truncated to fit

100
Q

Convert data in byte array to string

A

String message = new String(incoming.getData(), 0, incoming.getLength());

101
Q

Error - Bind Exception

A

Port already in use

102
Q

Error - Connection Refused

A

Server is not listening on port

103
Q

Error - Connection Closed

A

Tried to read/write using a closed socket

104
Q

Error - Unknown Host

A

The hostname or IP is not found on the network

105
Q

Error - IOException

A

General IO problem

106
Q

Duplexer

A

Self-created class that can both send and receive data

107
Q

Protocol

A

Specification of the format of the messages and rules governing those messages that two computers must follow to communicate

108
Q

Two forms of protocols

A

Textual specification for humans to read and understand.

Coded implementation for computers to use and understand

109
Q

Proxy Pattern Design

A

A client uses an interface called the subject. Proxy is a class that stands in for a real subject on a different computer. When a method is called on the proxy, it makes a network request to the real subject.

110
Q

T/F: When multi-threading a server, typically each client will receive its own thread

A

True. Main thread on the server spends its time waiting for incoming connections

111
Q

Thread

A

A task being executed in an application

112
Q

Old thread-safe libraries

A

Vector and Hashtable

113
Q

T/F: You should only synchronize critical regions of code

A

True

114
Q

T/F: Networking devices never know anything about hostnames. They’re only used by humans to identify connected devices.

A

False

115
Q

Proxy function

A

Allows a program to access a remote client’s functions by pretending to be the client

116
Q

A sequence of data; may be binary data or character data

A

Stream

117
Q

Used to read a sequence of binary data

A

InputStream

118
Q

Used to write a sequence of binary data

A

OutputStream

119
Q

Used to read a sequence of character data

A

Reader

120
Q

Used to write a sequence of character data

A

Writer

121
Q

Reading from it writing to physical media is slow. This technique is used to improve performance.

A

Buffering

122
Q

Used to send any data temporarily stored in memory out to the destination

A

Flush

123
Q

Used to clean up a resource once reading from and/or writing to is complete to ensure other processes can use the resource

A

Close