Premium

Oracle Advacned Java Advanced Certification Questions and Answers (Dumps and Practice Questions)



Question : You have been given below code, what is expected behavior?

package com.hadoopexam;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;

public class Welcome {

public static void main(String[] args) throws IOException {
Path sourceFile = Paths.get("resources\\Message.xml");
Path destinition = Paths.get("resources\\sub\\Message.xml");
Files.move(sourceFile, destinition, StandardCopyOption.ATOMIC_MOVE);
Files.delete(sourceFile);
}
}
 : You have been given below code, what is expected behavior?
1. The Messaage.xml file content is replaced by the sub\Message.xml file content and the sub\Message.xml file is deleted.

2. The sub\Message.xml file content is replaced by the Message.xml file content and an exception is thrown.

3. Access Mostly Uused Products by 50000+ Subscribers

4. A FileAlreadyExistsException is thrown at runtime.


Correct Answer : Get Lastest Questions and Answer :
Explanation: Path java.nio.file.Files.move(Path source, Path target, CopyOption... options) throws IOException

Move or rename a file to a target file.
By default, this method attempts to move the file to the target file, failing if the target file exists except if the source and target are the same file, in which case this method
has no effect. If the file is a symbolic link then the symbolic link itself, not the target of the link, is moved. This method may be invoked to move an empty directory. In some
implementations a directory has entries for special files or links that are created when the directory is created. In such implementations a directory is considered empty when only
the special entries exist. When invoked to move a directory that is not empty then the directory is moved if it does not require moving the entries in the directory. For example,
renaming a directory on the same FileStore will usually not require moving the entries in the directory. When moving a directory requires that its entries be moved then this method
fails (by throwing an IOException). To move a file tree may involve copying rather than moving directories and this can be done using the copy method in conjunction with the
Files.walkFileTree utility method.
The options parameter may include any of the following:
Option Description
REPLACE_EXISTING
If the target file exists, then the target file is replaced if it is not a non-empty directory. If the target file exists and is a symbolic link, then the symbolic link itself, not
the target of the link, is replaced.
ATOMIC_MOVE
The move is performed as an atomic file system operation and all other options are ignored. If the target file exists then it is implementation specific if the existing file is
replaced or this method fails by throwing an IOException. If the move cannot be performed as an atomic file system operation then AtomicMoveNotSupportedException is thrown. This can
arise, for example, when the target location is on a different FileStore and would require that the file be copied, or target location is associated with a different provider to this
object.
An implementation of this interface may support additional implementation specific options.
Moving a file will copy the last-modified-time to the target file if supported by both source and target file stores. Copying of file timestamps may result in precision loss. An
implementation may also attempt to copy other file attributes but is not required to fail if the file attributes cannot be copied. When the move is performed as a non-atomic
operation, and an IOException is thrown, then the state of the files is not defined. The original file and the target file may both exist, the target file may be incomplete or some
of its file attributes may not been copied from the original file.
Usage Examples: Suppose we want to rename a file to "newname", keeping the file in the same directory:
Path source = ...
Files.move(source, source.resolveSibling("newname"));

Alternatively, suppose we want to move a file to new directory, keeping the same file name, and replacing any existing file of that name in the directory:
Path source = ...
Path newdir = ...
Files.move(source, newdir.resolve(source.getFileName()), REPLACE_EXISTING);

Parameters:
source the path to the file to move
target the path to the target file (may be associated with a different provider to the source path)
options options specifying how the move 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)
AtomicMoveNotSupportedException - if the options array contains the ATOMIC_MOVE option but the file cannot be moved as an atomic file system operation.
IOException - if an I/O error occurs
SecurityException - In the case of the default provider, and a security manager is installed, the checkWrite method is invoked to check write access to both the source and target file.





Question : You have been given below interface, which of the below two will compile successfully.

public interface Welcome {
}


A. abstract class ChildA implements Welcome {
public void call(String s) {
}
}
B. abstract class ChildB implements Welcome {
public abstract void call(String s) { }
public void callB(Boolean b) { }
}

C. class ChildC implements Welcome {
public void call(Integer i) {
}
}
D. class ChildD implements Welcome {
public void callA(Integer i) {
}

public String callB(Integer j) {
}
}


 : You have been given below interface, which of the below two will compile successfully.
1. A,B
2. B,C
3. Access Mostly Uused Products by 50000+ Subscribers
4. A,D
5. B,D

Correct Answer : Get Lastest Questions and Answer :
Explanation: A. Abstract class can have non-abstract method.
B. Abstract class can not have method implemented. It should not have body part.
C. Nothing wrong with definition
D. Method callB should have return statement.





Question : You have been given below code, which code snippet should be replaced at line n , so that it can print
 : You have been given below code, which code snippet should be replaced at line n , so that it can print
1. Stream.of(dataSet1, dataSet2)
.flatMap(data -> data.stream())
.forEach(s -> System.out.print(s + " "));

2. Stream.of(dataSet1, dataSet2)
.flatMap(data -> data.intStream())
.forEach(s -> System.out.print(s + " "));

3. Access Mostly Uused Products by 50000+ Subscribers
.flatMap(dataSet2.stream().flatMap(e1 -> e1.stream()).forEach(s -> System.out.println(s + " ")));

4. Stream.of(dataSet1, dataSet2)
.flatMapToInt(data -> data.stream())
.forEach(s -> System.out.print(s + " "));


Correct Answer : Get Lastest Questions and Answer :
Explanation:


Related Questions


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());
}
}
}
 : You have  been given below code, what is the expected behavior ?
1. It will give compile time error

2. It will give runtime error

3. Access Mostly Uused Products by 50000+ Subscribers

4. It will print only once "Next Path: C:\HadoopExam\he1.txt"

5. It will go in infinite loop.



Question : You have been given below path, what is the expected code behavior?

package com.hadoopexam;

import java.nio.file.Path;
import java.nio.file.Paths;

public class Welcome {
public static void main(String []args) {
Path path = Paths.get("D:\\HadoopExam\\HE\\..\\HE2\\com\\.\\Welcome.java");
path = path.normalize();
System.out.println(path.subpath(2, 3));
}
}
 : You have been given below path, what is the expected code behavior?
1. It gives compile time error

2. It will give runtime error

3. Access Mostly Uused Products by 50000+ Subscribers

4. It will print "HadoopExam"

5. It will print "com"



Question : You have been given below code, what is the expected behavior?

package com.hadoopexam;

import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;

public class Welcome {
public static void main(String[] args) throws IOException {
Path path = Paths.get("C:\\HadoopExam\\he.txt");
System.out.println(path.isAbsolute());
}
}
 : You have been given below code, what is the expected behavior?
1. Compile time error

2. Runtime exception

3. Access Mostly Uused Products by 50000+ Subscribers

4. It will print true

5. Depend on file exist or not



Question : You have been given below code.
package com.hadoopexam;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.stream.Stream;

public class Welcome {
public static void main(String[] args) throws IOException {
Stream lines = Files.lines(Paths.get("C:\\Welcome.java"));
//n1
}
}
Which of the following line will print first line from Welcome.java file
 : You have been given below code.
1. lines.limit(1).forEach(System.out::println);

2. lines.limit(0).forEach(System.out::println);

3. Access Mostly Uused Products by 50000+ Subscribers

4. lines[0]

5. C and D



Question : You have been given below code, what is expected behavior?

package com.hadoopexam;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.function.BiPredicate;
import java.util.stream.Stream;

public class Welcome {
public static void main(String[] args) throws IOException {
BiPredicate biPredicate = (path, attrs) -> true;
try(Stream entries = Files.find(Paths.get("."), 1, biPredicate)) {
entries.forEach(System.out::println);
}
}
}
 : You have been given below code, what is expected behavior?
1. It will give compile time error.

2. It will give runtime error

3. Access Mostly Uused Products by 50000+ Subscribers

4. It will run, and print one level file information.



Question : You have been given below code. What is the expected behavior ?

package com.hadoopexam;

import java.io.IOException;

public class Welcome extends Thread {

@Override
public void run() {
System.out.print("HadoopExam");
}

public static void main(String[] args) throws IOException {
Welcome wel = new Welcome();
System.out.println(".com");
}
}
 : You have been given below code. What is the expected behavior ?
1. It will give compile time error

2. It will give run time error

3. Access Mostly Uused Products by 50000+ Subscribers

4. It will print "HadoopExam"

5. It will print "HadoopExam.com"