public static void main(String[] args) throws IOException { BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in)); System.out.print ("What is your course id? : "); //n1 } } Which of the below code segment you will use, so that it can read the values entered from keyboard by user? 1. int courseId = Integer.parseInt (bufferedReader.readline());
2. int courseId = bufferedReader.read();
3. int courseId = bufferedReader.nextInt();
4. int courseId = Integer.parseInt (bufferedReader.next());
Reads a line of text. A line is considered to be terminated by any one of a line feed ('\n'), a carriage return ('\r'), or a carriage return followed immediately by a linefeed. Returns: A String containing the contents of the line, not including any line-termination characters, or null if the end of the stream has been reached int java.io.BufferedReader.read() throws IOException
Reads a single character. Overrides: read() in Reader Returns: The character read, as an integer in the range 0 to 65535 (0x00-0xffff), or -1 if the end of the stream has been reached
Question : You have been given below code, what is the behavior expected?
public static void main(String[] args) throws IOException { Path source = Paths.get ("resources\\test\\Message.properties"); Path destination = Paths.get("resources"); Files.copy(source, destination); } } 1. It will create a new file name Message.properties in resources directory.
2. It will create a new file "resources\\resources\\test\\Message.properties"
3. It will throw run time exception, with " FileAlreadyExistsException"
4. It will not do anything , just run and come out.
Correct Answer : Get Lastest Questions and Answer : Explanation: : Path java.nio.file.Files.copy(Path source, Path target, CopyOption... options) throws IOException
Copy a file to a target file. This method copies a file to the target file with the options parameter specifying how the copy is performed. By default, the copy fails if the target file already exists or is a symbolic link, except if the source and target are the same file, in which case the method completes without copying the file. File attributes are not required to be copied to the target file. If symbolic links are supported, and the file is a symbolic link, then the final target of the link is copied. If the file is a directory then it creates an empty directory in the target location (entries in the directory are not copied). This method can be used with the walkFileTree method to copy a directory and all entries in the directory, or an entire file-tree where required. Parameters: source the path to the file to copy target the path to the target file (may be associated with a different provider to the source path) options options specifying how the copy should be done Returns: the path to the target file Throws: UnsupportedOperationException - if the array contains a copy option that is not supported FileAlreadyExistsException - if the target file exists but cannot be replaced because the REPLACE_EXISTING option is not specified (optional specific exception) DirectoryNotEmptyException - the REPLACE_EXISTING option is specified but the file cannot be replaced because it is a non-empty directory (optional specific exception) IOException - if an I/O error occurs SecurityException - In the case of the default provider, and a security manager is installed, the checkRead method is invoked to check read access to the source file, the checkWrite is invoked to check write access to the target file. If a symbolic link is copied the security manager is invoked to check LinkPermission("symbolic").
Question : You have been given below code, what is the expected behavior?
Collector>> java.util.stream.Collectors.groupingBy(Function super Welcome, ? extends String> classifier)
Returns a Collector implementing a "group by" operation on input elements of type T, grouping elements according to a classification function, and returning the results in a Map. The classification function maps elements to some key type K. The collector produces a Map> whose keys are the values resulting from applying the classification function to the input elements, and whose corresponding values are Lists containing the input elements which map to the associated key under the classification function. There are no guarantees on the type, mutability, serializability, or thread-safety of the Map or List objects returned.