Java 7 Changes Flashcards
Creating a DateFormat Instance
DateFormat df = DateFormat.getDateInstance(DateFormat.LONG);
DateFormat df = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL);
SimpleDateFormat new Instance
SimpleDateFormat sdf = new SimpleDateFormat(“YYYY-MM-dd”);
ReentrantLock instantiation
ReentrantLock rl = new ReentrantLock(); rl.lock();
ReentrantReadWriteLock Instantiation
ReentrantReadWriteLock rrwl = new ReentrantReadWriteLock(); Lock lock = rrwl.readLock();
Directory Stream Instantiation
DirectoryStream ds = Files.newDirectoryStream(Path p);
Single level only and each path should be iterated againsts.
FileVisitor methods
visitFile(Path, BasicFileAttributes)
visitFileFailed(Path, IOException)
preVisitDirectory(Path, BasicFileAttributes)
postVistDirectory(Path, IOException)
What is the difference between Files.walk() and Files.walkFileTree() method
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)
FileVisitor should return FileVisitResult. Enumerate the FileVisitResult enums
CONTINUE;
TERMINATE;
SKIP_SUBTREE;
SKIP_SIBLINGS
FileVisitOption value to allow links be followed
FileVisitOption.FOLLOW_LINKS
How to get the Instance of WatchService
FileSystems.getDefault().newWatchService()
How to register a watch service
path.register(watchService, StandardWatchEventKinds …)
Enumerate the StandardWatchEventKinds
StandardWatchEvent.ENTRY_CREATE;
StandardWatchEvent.ENTRY_DELETE;
StandardWatchEvent.ENTRY_MODIFY;
Difference between key.poll() and key.take()
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.