Final Flashcards

(231 cards)

1
Q

What buzzwords can be used to describe the Java language?

A

simple, objected-oriented, portable, secure

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

What is the Java platform?

A

the hardware or software environment in which a program runs

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

How does the Java API support many kinds of programs?

A

The API offers many ready-to-use classes that are popular in many programs ie. Math class

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

What are the advantages of Java?

A

easy to learn, write once and run everywhere

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

What is the skeleton for any Java program?

A

comments, class definition, the main method

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

What is the entry point for any Java application?

A

the main method invokes all the other methods

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

What is the function of the import statement?

A

allows you to use public packages inside of your package, tells the compiler where to find the package

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

What are the five characteristics of an object-oriented approach to programming?

A
  1. everything is an object
  2. a program is a bunch of objects that communicate by sending messages
  3. each object has its own memory
  4. every object has a type
  5. objects of a particular type can receive the same messages
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What are two reasons for controlling access to members of objects and how does Java implement control?

A
  1. keeps client programmer hands off portions they shouldn’t touch
  2. allows you to change the internal workings of a program with out it affecting the client programmer

Control is implemented through access specifiers

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

What are two ways of re-using classes?

A

composition and inheritance

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

How does late binding enable upcasting and polymorphism?

A

late binding enables upcasting and polymorphism because the method to call is determined at runtime instead of compile time

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

What is a container? What is an advantage of using a container?

A

container- an object that holds references to other objects (ie. ArrayList)

has the advantage of expanding whenever necessary to to hold what you want to put inside

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

What is ‘parameterized types/generics’? Explain how it eliminates the need for downcasting.

A

parameterized types are a class that can be used to customize a container to only work with a particular object type (ie. ArrayList will only accept String objects)

eliminates downcasting because the specific type is known when created

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

Where in memory does Java create objects?

A

the heap

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

What is function of exception handling and how does Java reinforce consistent use of handling exceptions?

A

exception handling is done so when a problem arises in your code instead of terminating the program an exception can be handled so something else will occur instead

exceptions are hard wired into Java so that you must handle exceptions properly or a compile-time error will be given

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

What are the functions of threads in single-processor and multi-processor environments?

A

in a single-processor, threads can allocate the time in a program

in a multi-processor threads can be assigned a different processor and run in parallel

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

What is the primary idea of a client/server system?

A

you have a central repository of information that you want to distribute to a set of people or machines

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

How did Web serving lead to client-side programming?

A

with web serving to accomplish a task everything had to be first sent to the server which can be slow

client-side programming allows programs to run under the browser without needed to send everything first to the server

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

What is CGI programming and what is its major shortcoming?

A

a way for web servers to interface with programs installed on the server

can be complicated to maintain and can be slow

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

Why is client-side programming efficient for the Web?

A

it allows the browser to do a lot of the work making it faster and more interactive for the user

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

What is a plugin?

A

a piece of software (code) that is downloaded to a browser to add functionality

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

What is a scripting language?

A

a language where the source code is embedded directly into the HTML page

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

Compare scripting languages to Java for Web page needs.

A

Java- good for large-scale projects with large volume of traffic, can solve more complicated problems

scripting language- easy to understand, can run without a web browser

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

What are the issues of Intranet versus Internet programming?

A

on the internet you must worry about spreading buggy code and making the code work across different platforms.

on the intranet the above is not so worrisome so you want to find the quickest solution to a problem that uses existing code when possible

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
What is the role of Java in server-side programming?
server-side programming can be done with servlets and JSP
26
What is the difference between an object and its handle?
an object is whats created in memory however you can only reference on object and manipulate it using the handle a handle can be created without an object but an object requires a handle to be created
27
What are the roles of registers, the stack, the heap, constant storage, and non-RAM storage in Java programming?
registers - fastest storage inside the processor but very limited the stack- lives in the RAM, cannot hold objects but can hold the references to them the heap- lives in the RAM and is where objects are held constant storage- where constant values are stored non-RAM storage- for data that lives outside of a program
28
What are the nine primitive types supported by Java?
int, boolean, long, short, byte, char, float, double, void
29
What are two classes of high-precision numbers with no primitive analog?
BigInteger, BigDecimal
30
How does scope differ for primitives and objects?
primitives defined within a scope will live until the end of the scope while objects will exist outside of the scope however the reference to them may not
31
What are classes, fields and methods?
class- describes the type of the object fields- the characteristics of the object (primitives or references to other objects that this object type can talk to) methods- the messages the object can receive
32
What is the difference between default values for primitive types as members of a class and local variables?
members of a class will be given default values of zero for integers, doubles etc. and false for booleans local variables are not given default values and therefore they must be assigned a value or a compile-time error will be given
33
What are the fundamental parts of a Java method?
return value, name, parameters, body
34
What is the naming convention when creating Java libraries for public distribution?
with domain name: mydomain.com and for library: myLibrary the convention would be com.mydomain.mylibrary (all lowercase)
35
What are the functions of the static keyword?
is used when a particular field or method is not tied to an instance of the class
36
Why is main static?
main is invoked on the class before any objects are created
37
In Java, what is the standard coding style for classes and methods?
both are camel-case however with methods the first letter of the method name is always lower-case
38
What is the precedence among arithmetic operators?
BEDMAS
39
What is the difference in assignment between primitives and objects?
primitives are assigned the actual value while with objects the references are what's assigned so an object assigned to another object means the references would then point to the same object
40
What is aliasing?
aliasing occurs when two references point to the same object so whenever one reference is manipulated the affect is the same on the other reference
41
What are the mathematical operators?
+ - * / % =
42
How do auto pre-increment, pre-decrement, post-increment, and post-decrement work?
for "pre" the operation is preformed before the assignment while for "post" the operation is performed after
43
What are the relational operators?
they generate boolean results ie. x > 4
44
How does one test for object equivalence?
for object references o1 and o2, o1 == o2 test whether the references point to the same object, o1.equals(o2) checks whether the contents of the objects are the same
45
What are the logical operators?
and(&&) or(||) not(!)
46
What is short-circuiting?
when an entire expression is not completely read because the trueness or falseness is already determined so there is no need to
47
How are literals used to specify type in Java?
use a trailing uppercase letter after the assigned value ie. long l1 = 0L;
48
What are the bitwise operators?
& | ^
49
What is the shift operator?
<< >>
50
How does the ternary if-else operator work?
ie. int i = 9; return i < 10 ? i * 100 : i * 10 (returns 900)
51
What is the function of the string + operator?
concatenates a string
52
How does explicit casting work in Java?
changes one data type into another
53
What are the two basic forms of if?
if with an else or if without an else
54
How does while differ from do-while?
in a do-while the loop will always be entered at least once
55
What are the purposes of the return keyword?
1. specifies what value a method will return | 2. causes current method to exit
56
How are break and continue used in Java?
break exits a loop without executing the rest of the statements, continue ends the current iteration and goes back to the top of the loop to continue to the next iteration
57
What is the purpose of a constructor?
constructs a new object
58
How are overloaded methods distinguished from each other?
overloaded methods must have different parameters so either the numbers of parameter must be different or the parameter type must be different
59
What is a default constructor?
when a constructor is not specified the default constructor is automatically used the superclass null constructor will be called with an empty body
60
How is the keyword this used in Java?
used to reference the current object
61
What is the purpose of finalize?
used to clean up resources acquired by an object (not memory) once the object is no longer in use
62
Why is finalize not good as a destructor?
finalize is called by the garbage collector but not all objects are garbage collected therefore finalize may not get called
63
Why must one perform clean up?
to free up resources used by objects that are no longer in use
64
What is the advantage of constructor initialization?
allows you to call methods and perform actions at runtime
65
When are variables in an object initialized?
first when a new object is created
66
What is explicit static initialization?
keyword static followed by a block of code, the block is executed only once
67
What is non-static instance initialization?
no keyword static
68
What is the advantage of bounds checking?
an error is given if you are out of bounds
69
What is an array of handles?
an array of references that point to objects
70
What are the four levels of access specification in Java?
1. private 2. public 3. protected 4. default
71
What is a compilation unit in Java?
.java file
72
What is the meaning of a package statement?
says that a compilation unit in java is part of a package`
73
What is the naming convention for packages?
all lowercase letters
74
How does CLASSPATH work with packages?
specifies the location
75
How does Java handle collisions between classes in packages?
an error will be given so you must specify the exact class using the package name
76
How can packages be used to mimic conditional compilation?
you can change the package that is imported in your code without changing the code itself
77
What is the package caveat?
an error given when a class cannot be found
78
What are the constraints on using the public access level?
only one per .java file
79
What is composition?
creating objects of an existing class inside a new class represents a 'has-a' relationship
80
What does the keyword extends accomplish?
you get all the (non-private) fields and methods of the parent class
81
How does the base class get initialized in the case of default constructors?
when a subclass is initialized the base class is initialized and constructed first then process moves downwards
82
What is delegation in relation to composition and inheritance?
when you place a member object in a new class like composition but you also grant access to all the methods and fields of the member object to the new class (like inheritance)
83
How does a method in a derived class affect a method in a base class with the same name but a different signature?
this will not hide the method in the base class
84
When is composition used compared to when inheritance is used?
composition represents a 'has-a' relationship while inheritance represents a 'is-a' relationship
85
What is the advantage of upcasting?
allows a new class to be the type of an existing class where a more general type is beneficial
86
What are two ways of setting a final primitive value?
using final or static final
87
What is the difference between static final versus final?
final cannot change while static final belongs to a particular class
88
What is the effect of final on objects?
makes the reference constant but not the object itself
89
How does a final argument function?
read-only
90
What is the role of late binding in polymorphism?
because it's done at runtime the correct method to call is determined by the current object
91
How is extensibility supported by polymorphism?
new code only needs to be added to the base class and will extend to the subclasses
92
What is the order of finalize for base and derived classes?
reverse order of initialization
93
What is a good rule for using polymorphic methods within a constructor?
don't call any methods that are not final in the base class
94
What is a covariant return type?
subclass return types that are different from the base class return type but are objects of a subclass type
95
What advantage does composition have over inheritance?
not forced into an inheritance hierarchy possible to dynamically choose a type where inheritance requires an exact type at compile time
96
How can upcasting be ineffective with extension?
once upcasted the extended part of the subclass is no longer available
97
How is upcasting safe and downcasting not safe with extension?
upcasting is always safe because the base class cannot contain more methods than the subclass so everything is available
98
What is RTTI and how does it work with downcasting?
runtime type information- will throw an error if it's not the correct type
99
What are abstract classes and abstract methods?
a blue print for the subclasses to show the commonality
100
What is the format of a Java interface?
keyword interface, derived classes use implements keyword
101
Describe an example of how an interface can be applied to multiple different implementations.
``` interface Intrument {... class Wind implements Intrument {... class Brass implements Intrument {... ```
102
How is multiple inheritance dealt with by interfaces?
use commas to separate the multiple interfaces
103
How does extend differ for interfaces?
a class can only extend from one class but can implement multiple interfaces
104
Can an interface be nested within another interface?
yes
105
What is a Factory Method design pattern and how does it relate to interface?
a way to construct objects that fit the interface using a method instead of calling a contructor
106
What is the appropriate guideline for choosing between classes and interfaces?
prefer classes to interfaces
107
What is an inner class?
a class within a class
108
What access do inner classes have to the containing class variables and methods?
can access containing class variables and methods through its own methods
109
What are the meanings of .this and .new> in the context of an inner class?
.this is used to mean this belonging to the outer class .new is used to creates instances of an inner class
110
What is the advantage of upcasting to an interface with inner classes?
convenient for hiding the implementation
111
What is an anonymous class?
inner class defined without a class name
112
How do you initialize fields within an anonymous class?
within the body
113
What are characteristics of static inner classes?
don't need an outer object in order to create an object of a static inner class you can't access a non-static outer object with a static inner class object
114
How can you use static inner classes for testing?
can be used in place of a main
115
What is the one compelling reason for using an inner class?
allows for a window into an outer class because you can manipulate the outer class object
116
How are inner classes identified?
the name of the enclosing class followed by a $ followed by the name of the inner class
117
What is a type-safe container?
ensures only the proper type is added to the container
118
What are the two main concepts underlying the Java 2 collections library?
collection (list, set, queue) and map (key, value pairs)
119
What are the two types of List and what is the difference between them?
ArrayList and LinkedList, former quicker to randomly access elements, latter quicker for adding and removing elements
120
What is the purpose of an Iterator?
an object that can move through a sequence and select each object in the sequence
121
What are the advantages of a ListIterator over an Iterator?
can move forwards and backwards
122
What is a stack?
a container where the last elements to go in are the first to come out
123
What is the distinctive feature of a Set?
will only hold one each value
124
What is the distinctive feature of a Map?
holds key, value pairs
125
What is a Queue and what is a PriorityQueue?
queue- first-in, first-out | priority queue- what goes next in the one with the greatest need
126
What is the argument for having an interface over a Collection?
allows you to create more generic code
127
How does the foreach syntax work with Iterable?
any class that implements Iterable can be used in a foreach statement
128
What are the features that distinguish an array from other types of containers in Java?
can hold primitives
129
What is the use of the Arrays.deepToString() method?
turns multidimensional arrays into strings
130
What are the conditions when Arrays.equals() returns true?
must have the same number of elements and each element must be equal to the corresponding element
131
How do you implement Comparable in sorting an array?
must have a class that implements Comparable and in that class a compareTo method
132
What is the condition of using Arrays.binarySearch()?
can only be used on sorted arrays
133
What are the benefits of using exceptions?
allows you to properly handle runtime errors
134
What happens when you throw an exception?
an exception object is created, the path of execution is stopped, exception handling takes over
135
What is the advantage of a try block?
you can put everything in a try block and catch all the exceptions that may be thrown
136
What is the function of a catch block?
to handle exceptions that may get thrown
137
How do you log the output of an exception?
catch the exception and create a Logger object
138
What happens to Runtime errors that are never caught?
printStackTrace() is called
139
What happens with the finally statement when no exception is thrown?
finally always runs
140
Why is it that a method says it throws an exception but it does not?
when it is abstract, will be forced to catch the exception when an overridden method is created
141
What is the problem with using finally to handle exceptions in constructors?
if the constructor fails partway through the part to be cleaned up by finally may not have been created
142
How does exception-handling work with derived and base exception classes?
when an exception is thrown, the system looks for the nearest handler
143
What is the advantage of making Strings immutable?
helps prevent errors because methods called on a String object won't change the original object
144
In what situation will using an explicit StringBuilder improve efficiency?
when looping because only a single StringBuilder object is created
145
What is the purpose of a Formatter object?
Formatter object can be used to format a String
146
What is a regular expression?
tool that allows you to specify complex string patterns of input strings (ie. email address)
147
How do you use Pattern and Matcher classes with regular expressions?
a Pattern object is a compiled representation of a regular expression, can be used along with a Matcher object to match patterns
148
What method of Scanner would you call to retrieve the next StringTtoken?
next()
149
What is one advantage of Scanner over StringTokenizer?
you can split a string into parts
150
What is the purpose of a Class object?
contains information about the class
151
What is a class loader and how does it load classes?
loads all the classes into the JVM dynamically upon the first use of the class
152
What is the use of Class.forName?
takes a string of the name of that particular class and returns a reference to the class will load a class if it isn't already loaded or will throw an exception if the class does not exist
153
What is the use of a class literal?
can be used to produce a reference to the class without using forName()
154
Why is Class> preferred over plain Class?
it shows that you want a non-specific class reference
155
What is the function of instanceof?
will return a boolean depending on whether an object is or is not a instance of a particular type
156
What is the difference between instanceof and Class objects?
.class doesn't care about inheritance while instanceof will return true if it and instance of the class or one of its subclasses
157
What are two function of reflection?
1. detect available methods 2. produce the method names when the class is not know at compile time
158
What do the methods getMethods and getConstructors return?
returns an array of Method objects and Constructor objects, respectively, representing the methods and constructors available for the specific Class object
159
Do you consider a Null Object useful?
yes because they can provide default behaviour when data is not available
160
What is the general concept of generics or parameterized types?
Allows you to create components of a generic type (ie. can be used with multiple types)
161
What is a tuple? How do a generics implement tuples?
a tuple takes multiple objects and wraps them together inside a single objects
162
What is type argument inference? Why does a generic method look like an indefinite overloaded method?
it is when you don't have to specify a specific type because the compiler can figure it out calls to generic methods look like normal method calls with the specific type passed as a parameter so the method looks to be indefinitely overloaded
163
What is meant by erasure? Does Java consider List and List the same type?
erasure means that the specific type information is erased when using generics
164
What is a bound and how does Java implement a bound in generics? Explain the meanings of ?
a bound tells the compiler to only accept type within the bound. In this example, the compiler would only accept type T2 or its subclasses
165
What are the problems with erasure when using generics?
since the specific type information is erased you cannot use generics in operations that refer to runtime types
166
How do you compensate for erasure by using a type tag?
``` a type tag means you explicitly pass in the Class object for your type so you can use type expressions ie. new ClassCapture(Building.class); ```
167
How does Java implement multiple bounds?
use & for interfaces
168
What is one situation that requires the use of an unbounded wildcard?
during capture conversion when an unspecified wildcard type is captured and converted into an exact type
169
Explain why a class cannot implement two variants of the same generic interface?
because during erasure the specific type is erased so you would be trying to implement from the same interface
170
Describe a way to check type dynamically.
checkedCollection(), checkedList() etc.
171
Explain why a catch clause cannot catch an exception of a generic type.
the exact typeof the exception must be known at compile time and runtime in order for it to be caught
172
What is latent typing? What is its advantage?
in latent typing the suitability of an object for some purpose is determined by its fields and methods and not the type of object itself provides more general code allowing more reusability
173
How to compensate the lack of latent typing by using adapters?
the adapter pattern woks as a bridge between two incompatible interfaces so that code can be applied across boundaries
174
Briefly describe a Flyweight design pattern. How does the use of Abstract class demonstrate the use of Flyweight design pattern?
a Flyweight design pattern externalizes part of an object so not everything is contained in the object and some or all is looked up in an external table you inherit from an abstract class which acts as a read-only container
175
What is the fundamental issue for Maps and what is the advantage of a HashMap?
using a linear search to search for a specific key is very slow a HashMap using a hash code to search for a key which is much faster
176
What is one common pitfall when creating customized classes as keys for HashMaps and how can you avoid it?
you don't override both hashcode() and equals()
177
What are the two factors governing a good hashCode()?
1. it generates a value based on the contents of the object (does not need to be unique) 2. it should result in an even distribution of values
178
What are the performance factors of a HashMap?
(SLIC) 1. size 2. load factor 3. initial capacity 4. capacity
179
How do you make a CollectionMap unmodifiable?
by calling the unmodifiable method
180
What is the use of the values() method in an enum?
produces an array of the enum constants in the order in which they were declared
181
What is an EnumSet?
on/off switch of elements of an enum
182
What is an EnumMap?
a may where the keys are the elements of a single enum
183
What are two ways of using the File object to get a directory listing?
list() with no arguments or the list method with a directory filter
184
What are four other uses of the File class?
1. create a new directory 2. look up the characteristics of a file 3. see whether a File object represents a particular file or directory 4. delete a file
185
What are the six types of InputStream?
1. array of bytes 2. a file 3. a pipe 4. a String 5. sequence of streams 6. other
186
What are the four types of OutputStream?
1. array of bytes 2. a file 3. a pipe 4. Filter-OutStream
187
What is a Decorator?
used when there are so many subclasses that it becomes impractical
188
What is the difference between a PrintWriter and a DataOutputStream?
PrintWriter formats the data so that it can be read by humans, DataOutputStream is byte-oriented
189
How do you redirect I/O in Java?
set methods (setInt(), setOut(), setErr())
190
What is the goal of the Java new I/O library?
speed
191
What are the four indexes of a Buffer?
CLMP 1. capacity 2. limit 3. mark 4. position
192
How to lock and release a file?
call lock() and release(0 on FieChannel
193
What is the primary function of GZIP?
to compress a single file
194
When would you use Zip?
to compress multiple files
195
What is the JAR format?
a way to collect a group of files into a single compress file (like zip) except it is cross-platform
196
What is lightweight persistence?
persistence is when an object exists after a program is executed, lightweight is used because an object must be explicitly serialized then de-serialized
197
What are two functions of serialization?
1. RMI | 2. JavaBeans
198
What is a rule for serializing to save the state of a system?
you have to both write the important data and recover it for serialization to work
199
What is the function of the transient keyword?
transient means "don't serialize this"
200
How do writeObject and readObject function?
you must call these methods to serialize and de-serialize your object
201
What is the limitation of object serialization and what is the advantage of converting data to XML format?
object serialization is for Java only converting data to XML format can be used across different platforms
202
What is the advantage and what is limitation of the Preferences API?
Preferences API can be used to store and retrieve information it is restricted to only hold primitives of a certain length
203
Explains the difference between TCP and UDP.
TCP- ensures a reliable flow of data between two computers (ie. making a phone call) UDP- sends independent packets of information from one computer to another without the guarantee of arrival (ie. mailing a letter)
204
What is the default port number if it is not included in a URL?
80
205
Define a Socket.
an endpoint for the communication between two machines
206
What are the characteristics and advantages of Swing?
uses GUI builders (visual programming environment), portable because it is written in Java, uses JavaBeans for the framework
207
What is the reason applets failed to be the next stage in the evolution in Internet use?
you had to download and install a large package to run applets which people didn't want to do
208
When is it necessary to use a button group?
button groups ensure only one button can be selected at a time
209
What is one fundamental mistake sometime made when programming an application with a GUI interface?
using the event dispatch thread to run a long thread
210
What is a JavaBean?
it is a class that encapsulates many objects into a single object (the bean)
211
Why is it important that the public methods of a Bean be synchronized?
a Bean will likely run in a multithreaded environment
212
What is meant by preemptive threading?
preemptive threading is when a scheduling mechanism assigns each thread a time slice then periodically interrupts a thread to switch to another
213
How do you define a task in Java?
have the class implement Runnable and call the run() method
214
How do you write a program as a Thread? What will happen when making a call to start()?
``` create a new thread using Thread t = new Thread(Object); then t.start() will initialize the thread and call the run() method ```
215
In what way does an Executor simplify the management of asynchronous tasks?
allows you to manage a group of threads without needing to worry about their lifecycle
216
What is the difference between a Runnable interface and a Callable interface?
a Runnable won't return a result while a Callable will
217
What is the effect of calling yield()?
it suggests to the CPU that the task is complete and it should move onto another task of the same priority
218
What is a daemon thread?
a thread that runs in the background and is not part of a program
219
What is the purpose of the synchronized keyword in Java?
synchronized is used to lock a shared resource while it is in use, it is automatically unlocked when not is use
220
Explain how to use a Lock object.
a Lock object must be created locked and unlocked after a call to lock() you must use a try-finally statement with the unlock() in the finally part
221
What is an atomic operation and how do you get atomicity in Java?
an operation that cannot be interrupted by the thread scheduler (goes to completion)
222
What is a critical section and how do you create it?
section of code that you want to prevent multiple threads from accessing at a time, use synchronized keyword
223
What are the four states a Java Thread can be in?
1. new 2. Runnable 3. Blocked 4. Dead
224
What are the four ways a Java Thread can become blocked?
1. calling sleep() 2. calling wait() 3. waiting for I/O 4. waiting for a method that is locked
225
What will happen when the interrupt() method is being called?
sets the thread to interrupted status
226
Why does busy waiting generally considered undesirable? What is the consequences of calling wait() in comparison to sleep() or yield()?
wait() releases the lock on the object
227
What is the difference between notify() and notifyAll()?
notify() wakes up the first thread that called wait(), notifyAll() wakes up all waiting threads
228
What is the purpose of a CountDownLatch object? Give an example.
used to synchronize one or more tasks by forcing them to wait for the completion of a set
229
What is the purpose of a CyclicBarrier object? Give an example.
used when you want a group of tasks to perform work in parallel and then wait until they have all completed before moving on
230
What is a counting semaphore?
allows a set number of tasks to use a resource at one time
231
What is the general strategy behind lock-free containers?
modifications done on the container are done on an invisible copy and only after they are complete can the readers see the modifications