Question : You have been given below code, what is the expected behavior ? package com.hadoopexam;
import java.nio.file.*;
public class Welcome { public static void main(String[] args) { Path hePath = Paths.get("C:\\HadoopExam\\he1.txt"); while (hePath.iterator().hasNext()) { System.out.println("Next Path: " + hePath.iterator().next()); } } } 1. It will give compile time error
4. It will print only once "Next Path: C:\HadoopExam\he1.txt"
5. It will go in infinite loop.
Correct Answer : Get Lastest Questions and Answer : Explanation: When you call hePath.iterator() , it will return a temporary iterator variable. And once you call next() method on it. This temporary variable will be lost and goes in infinite loop.
Returns a path that is this path with redundant name elements eliminated. The precise definition of this method is implementation dependent but in general it derives from this path, a path that does not contain redundant name elements. In many file systems, the "." and ".." are special names used to indicate the current directory and parent directory. In such file systems all occurrences of "." are considered redundant. If a ".." is preceded by a non-".." name then both names are considered redundant (the process to identify such names is repeated until it is no longer applicable).
After normalize path will be : D:\HadoopExam\HE2\com\Welcome.java Path starts with "HadoopExam" and also its indexing start with 0, 1, 2,3 ect.
Tells whether or not this path is absolute. An absolute path is complete in that it doesn't need to be combined with other path information in order to locate a file. Returns: true if, and only if, this path is absolute To use methods such as isAbsolute(), the actual file need not exist. Because the path represents an absolute path (and not a relative path), this program prints true