MOOC Part 10 Flashcards

1
Q

What are the 2 types of stream operators and what are their differences?

A

Intermediate operator and terminal operator.

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

Compare max value of objects using stream.max() using method reference instead of a lambda expression

A

public Item heaviestItem() {

    return items.stream()
    .max(Comparator.comparingInt(Item::getWeight))
    .get();
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How do we use import Collections.sort() method.

A

A class needs to implement the Comparable interface, and use the compareTo(Object object) method.

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

How do you create an input stream from a file?

A

Using ‘lines’ method from Java’s file class.

Files.lines(Paths.get(“file.txt”))

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

What is a stack trace?

A

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.

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

What is the difference between shallow clone and deep clone?

A

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.

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