Java 7 Changes Flashcards

1
Q

Creating a DateFormat Instance

A

DateFormat df = DateFormat.getDateInstance(DateFormat.LONG);

DateFormat df = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL);

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

SimpleDateFormat new Instance

A

SimpleDateFormat sdf = new SimpleDateFormat(“YYYY-MM-dd”);

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

ReentrantLock instantiation

A
ReentrantLock rl = new ReentrantLock();
rl.lock();
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

ReentrantReadWriteLock Instantiation

A
ReentrantReadWriteLock rrwl = new ReentrantReadWriteLock();
Lock lock = rrwl.readLock();
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Directory Stream Instantiation

A

DirectoryStream ds = Files.newDirectoryStream(Path p);

Single level only and each path should be iterated againsts.

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

FileVisitor methods

A

visitFile(Path, BasicFileAttributes)
visitFileFailed(Path, IOException)
preVisitDirectory(Path, BasicFileAttributes)
postVistDirectory(Path, IOException)

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

What is the difference between Files.walk() and Files.walkFileTree() method

A

Files.walk() accepts a Path, depth and FileVisitOption then returns a Stream of Path Object.
Files.walk(Path, depth, FileVisitOption

Files.walkFileTree() accepts Path and FileVisitor. It executes the fileVisitor on each of the object encountered.
NIO2 provides - walkFileTree(Path, FileVisitOption, int, FileVisitor)

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

FileVisitor should return FileVisitResult. Enumerate the FileVisitResult enums

A

CONTINUE;
TERMINATE;
SKIP_SUBTREE;
SKIP_SIBLINGS

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

FileVisitOption value to allow links be followed

A

FileVisitOption.FOLLOW_LINKS

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

How to get the Instance of WatchService

A

FileSystems.getDefault().newWatchService()

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

How to register a watch service

A

path.register(watchService, StandardWatchEventKinds …)

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

Enumerate the StandardWatchEventKinds

A

StandardWatchEvent.ENTRY_CREATE;
StandardWatchEvent.ENTRY_DELETE;
StandardWatchEvent.ENTRY_MODIFY;

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

Difference between key.poll() and key.take()

A

poll() returns null if no key event is present. It can also wait for a definite time using poll(int,TimeUnit)
take() waits indefinitely until an event is present.

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