MOOC Part 10 Flashcards
What are the 2 types of stream operators and what are their differences?
Intermediate operator and terminal operator.
Compare max value of objects using stream.max() using method reference instead of a lambda expression
public Item heaviestItem() {
return items.stream() .max(Comparator.comparingInt(Item::getWeight)) .get(); }
How do we use import Collections.sort() method.
A class needs to implement the Comparable interface, and use the compareTo(Object object) method.
How do you create an input stream from a file?
Using ‘lines’ method from Java’s file class.
Files.lines(Paths.get(“file.txt”))
What is a stack trace?
Information displayed when an exception occurs and isn’t handled.
It includes the name of the exception indicating the problem, and method-call stack at the time it occured, revealing the path of execution that let to the exception.
What is the difference between shallow clone and deep clone?
Shallow clone stores the reference of the orignal object whereas deep clone copies the objects values.
Shallow clone reflects changes made on the original as it is referenced, whereas deep clone does not.
Shallow copy is faster.