Final Exam Flashcards

(123 cards)

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
Exception for sleep
Interrupted Exception. Checked. Can basically be ignored.
26
Sleep should always be called on ___
The Thread class (not an instance)
27
Join
Allows threads to queue, running one after the other has finished (used after start)
28
Joining threads stops them from
Running concurrently
29
Race condition
When two or more threads are trying to access/update the same shared resource
30
Context switch
When the active thread changes between retrieving a value and using said value
31
Shared resources are also known as ___
Critical regions. Unsafe in multi-threaded environments unless protected
32
A protected critical region is ___
Thread Safe
33
Resource contention
When two or more threads attempt to manipulate the value of a shared resource at the same time
34
Non-atomic operation
An operation that is implemented with at least two separate instructions
35
Synchronized
Keyword used with an object key to create a mutually exclusive lock
36
T/F: Primitive types can work as keys to synchronize on
False. Must be a reference type/object
37
If a second thread tries to access a synchronized block using the same object key ___
It will be locked out and enter a blocked state
38
When a thread exits a critical region, it ___ the lock and a ___ thread will transition to the ___ state
Surrenders. Blocked. Runnable.
39
Threads trying to access the critical region must have access to the ___. Because of this, it is common to use the ___ itself as the ___.
Object key. Shared resource, key.
40
Synchronizing the entire run method causes threads to run ___ rather than ___
Sequentially. Concurrently.
41
To minimize the amount of time threads are blocked, synchronization should be done in a ___ way
Surgical
42
If you control the object code for a shared resource, one option is to
Synchronize on methods or portions of methods in the object
43
T/F: Synchronized code runs much slower than code that is not synchronized, even if it is only used by one thread
True.
44
T/F: Most Java standard libraries are thread-safe
False. Too slow. Most code is for single thread.
45
Hashtable
Thread-safe version of HashMap. Deprecated. Don't use.
46
Polling
Checking if a thread can proceed at certain time intervals. Can cause delay from when job is added and thread checks
47
Lock.wait()
Pauses execution of the thread indefinitely. Surrenders the lock.
48
Lock.notify()
Notifies a waiting thread that is waiting on the same lock
49
Lock.notify() chooses __ thread and moves it to the __ state
One. Blocked.
50
T/F: Notify surrenders the key on the lock
False. Key only surrenders when exciting synchronized block or when waiting
51
Parallel processing
Divide and conquer technique for handling work that can be divided between multiple threads
52
Lock.notifyAll()
Moves all waiting threads into the blocked state. Only one will get the lock when available.
53
Producer
Creates jobs that will be put in a queue to be performed by the consumer
54
Consumer
Executes jobs from the work queue created by producers
55
Blocked versus Waiting
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
Deadlock
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
T/F: A deadlock can't be recovered from
True
58
Deadlock conditions
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
Starvation
Thread getting so little time on processor that it can't do work
60
Network
Hardware and software that provides two or more computers ability to communicate with each other
61
Connection
Established when one computer pings another listening one. Can be used to send and receive data.
62
Protocol layering
Divides network designs into functional layers, each with its own protocols and specific purpose, independent of the others
63
DoD 4-Layer Model
(Department of Defense) aka TCP/IP Model: Application Transport Internet Network Access
64
OSI 7-Layer Model
(Open Systems Interconnection) Application Presentation Session Transport Network Data Link Physical
65
IP
Internet Protocol. Runs in network layer and handles routing and relaying packets of info.
66
TCP
Transmission Control Protocol. Establishes connection between two computers and helps ensure packets delivered in order, reliably, and without corruption
67
Every Internet-connected system must have a unique ___
IP address
68
IPv4
A 32-bit (4-byte) binary number represented as a dotted quad
69
Because of the limit in number of IP addresses under IPv4, many computers on private networks are connected through ___, which gets an IP address
Single router or proxy. Computers connected to router use private addresses
70
Hostname
Human readable address
71
DHCP
Dynamic Host Control Protocol, which changes a computer's IP address as needed
72
DNS
Domain Name Server. Provides service that maps a hostname to real address for the computer
73
InetAddress get hostname and IP address
getByName(String host) getLocalHost() After creation: getHostAddress() getHostName()
74
Loopback address
Special address that always refers to the local computer. 127.0.0.1
75
localhost
Special hostname that refers to local computer
76
Hypertext document
A document that contains links to other documents
77
HTTP
Hypertext Transfer Protocol. Client always initiates communication by sending a request. The server always responds.
78
URL
Uniform Resource Locator. Defines a unique location of a resource on the web service://host:port/file and resource details
79
To create a URL in Java
URL u = new URL("http://nasa.gov/");
80
If Java does not understand a protocol, a ___ will be thrown
Checked MalformedURLException
81
T/F: URLConnection is an abstract class because each protocol defines its own message format
True. Subclasses provide specific implementations (e.g. HTTPURLConnection)
82
To connect to a resource. To read data from a resource. To write to a resource.
connect() getInpurStream() getOutputStream()
83
T/F: URL and URLConnection only work with established Internet protocols like Http
True
84
Class for establishing TCP/IP connection using specific hostname/IP and port
Socket
85
T/F: Trying to connect to a port not being used to listen for connections will NOT cause an error
False. Will throw a checked exception.
86
All exceptions regarding socket use are
IOException
87
Once a TCP/IP connection is established, both sides are represented as ___
Sockets
88
To send text data instead of binary data, it must be wrapped in an instance of ___
The PrintWriter class PrintWriter writer = new PrintWriter(stream);
89
PrintWriter methods
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
To received text data instead of binary, it should be wrapped in an instance of
Scanner Scanner SC = new Scanner(stream);
91
A port is a __ number between __ and __
Positive. 1 and 65,535. Most of the ports below 1500 are reserved for computer operations
92
The accept() method will __ until a client establishes a connection
Block
93
TCP/IP is __. Client and server must ___ before they can communicate
Connection-oriented. Established a connection.
94
T/F: TCP/IP guarantees that packets are delivered in order and without corruption.
True. With a lot of overhead cost.
95
UDP
User Datagram Protocol. Connectionless alternative to TCP/IP. Messages are addressed and delivered, but may be lost.
96
T/F: UDP is slower than TCP/IP.
False. UDP is much faster and potentially less reliable.
97
A DatagramPacket is constructed with __ and __
Byte[] data (getData()) and length (getLength ()) of bytes. And, optionally, the InetAddress and port of the recipient.
98
DatagramSocket
Constructed with a port to send and receive UDP messages send(DatagramPacket) receive(DatagramPacket)
99
If the buffer for an incoming Datagram message isn't large enough
It will be truncated to fit
100
Convert data in byte array to string
String message = new String(incoming.getData(), 0, incoming.getLength());
101
Error - Bind Exception
Port already in use
102
Error - Connection Refused
Server is not listening on port
103
Error - Connection Closed
Tried to read/write using a closed socket
104
Error - Unknown Host
The hostname or IP is not found on the network
105
Error - IOException
General IO problem
106
Duplexer
Self-created class that can both send and receive data
107
Protocol
Specification of the format of the messages and rules governing those messages that two computers must follow to communicate
108
Two forms of protocols
Textual specification for humans to read and understand. Coded implementation for computers to use and understand
109
Proxy Pattern Design
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
T/F: When multi-threading a server, typically each client will receive its own thread
True. Main thread on the server spends its time waiting for incoming connections
111
Thread
A task being executed in an application
112
Old thread-safe libraries
Vector and Hashtable
113
T/F: You should only synchronize critical regions of code
True
114
T/F: Networking devices never know anything about hostnames. They're only used by humans to identify connected devices.
False
115
Proxy function
Allows a program to access a remote client's functions by pretending to be the client
116
A sequence of data; may be binary data or character data
Stream
117
Used to read a sequence of binary data
InputStream
118
Used to write a sequence of binary data
OutputStream
119
Used to read a sequence of character data
Reader
120
Used to write a sequence of character data
Writer
121
Reading from it writing to physical media is slow. This technique is used to improve performance.
Buffering
122
Used to send any data temporarily stored in memory out to the destination
Flush
123
Used to clean up a resource once reading from and/or writing to is complete to ensure other processes can use the resource
Close