The life cycle of threads
T/F: Streams do not support aggregate operations.
False. They support aggregate operations like filter, map, limit, reduce, find, match, etc.
T/F: Java supports functional programming
True
Syntax for Lambda expressions
parameter -> expression body
Syntax for annotations
What is the "@" symbol followed by the annotation's name?
Keyword to synchronize a thread
What is the synchronized keyword?
Difference between stream() and parallelStream()
In the output of a stream(), the contents are in an ordered sequence. The output of a parallelStream() is unordered, and the sequence changes each time the program is run.
What makes Fold different from Reduce?
Fold requires an initial value.
Integer sum = integers.reduce(Integer::sum); //REDUCE
Integer sum = integers.reduce(0, Integer::sum); //FOLD
T/F: Lambda expressions with multiple parameters require parentheses.
True. Parentheses are option if it only contains one parameter.
What package is LocalDateTime and ZonedDateTime imported from?
java.time
Two ways to create a thread
What is by extending the Thread class or implementing Runnable interface
Two ways to create a parallel stream
Using parallelStream() on a collection, or using the parallel() method on a stream.
T/F: Filtering a collection changes the original collection.
False. Filtering makes a new collection and returns that.
T/F: Lambda expressions are treated as a function, so the compiler does not create a .class file
True
Difference between shallow clone and deep clone?
Shallow clone only copies the fields. Deep clone copies the fields and what they reference.
Difference between notify() and notifyAll()
notify() releases one thread that is waiting. notifyAll() releases all threads that are waiting.
A stream is considered consumed when what type of operation is invoked?
Terminal operation. No other operation can be applied to the stream elements afterward.
T/F: A logic can't be packed as a variable.
False
What are the three components of a lambda expression?
Argument list, arrow token, body
What interface do you implement to use clone()?
Cloneable interface
How do you prevent deadlock?
Synchronize threads
What are the conditions for a concurrent reduction?
The stream is parallel. The stream is unordered or has characteristic of Collector.Characteristics.UNORDERED. The parameter of the collector has characteristic of Collector.Characteristics.CONCURRENT.
Difference between compose() and andThen()
compose() executes the caller last and parameter first.
andThen() executes the caller first and parameter last.
True or False: Lambda expressions always require curly braces.
False. Curly braces aren't needed if the expression body only contains a single statement.
What does the peek() operation do?
Return a stream consisting of the elements of the stream and performs provided action of each element from the resulting stream. Used to support debugging.