Java 7 Flashcards

1
Q

What is the use of diamond operator (added in Java 7)?

A

The diamond operator simplifies the declaration of generic classes.

Example:
// before the diamond operator
Map String<String, List<Double>> = new HashMap<String, List<Double>> ();

// after the diamond operator
`Map String<String, List<Double>> = new Hashmap <> ();</Double>

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

What is automatic resource management (added in Java 7)?

A

The new automatic resource management feature makes dealing with resources much easier, such as files. Before Java 7, we needed to close all open streams explicitly, causing some very verbose code.

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

What is improved exception handling in Java 7?

A

Improved exception handling means that we can catch more than one exception in one catch statement. Previously, we had to write a different catch block for each statement.

Example of the new style:

try { // code } catch (NullPointerException | NumberFormatException | IOException e) { return null; }

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

What are numbers with underscores (added in Java 7)?

A

Humans have difficulty reading long streams of numbers, so Java 7 allows us to put an underscore in numeric literals to make them easier to understand.

For example, 3 million would be written as follows:

int number = 3_000_000;
System.out.print(number);
// This would print (3000000)

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

What is the fork-join framework?

A

There are new Java concurrency APIs (JSR 166y) referred to as the fork-join framework designed for tasks that can be broken down and takes advantage of multiple processors. The core classes located in java.util.concurrent are ForkJoinPull, ForkJoinTask, RecursiveTask, and RecursiveAction.

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

What is the NIO API (added in Java 7)?

A

The NIO API allows developers to access many low-level OS operations that were not available in the Java API before, such as the WatchService and the ability to create links (in Nix operating systems).

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