Exam Name: | Java SE 8 Programmer II | ||
Exam Code: | 1z0-809 Dumps | ||
Vendor: | Oracle | Certification: | Java SE |
Questions: | 196 Q&A's | Shared By: | juliette |
Given the code fragment:
public class FileThread implements Runnable {
String fName;
public FileThread(String fName) { this.fName = fName; }
public void run () System.out.println(fName);}
public static void main (String[] args) throws IOException, InterruptedException {
ExecutorService executor = Executors.newCachedThreadPool();
Stream
listOfFiles.forEach(line -> {
executor.execute(new FileThread(line.getFileName().toString())); //
line n1
});
executor.shutdown();
executor.awaitTermination(5, TimeUnit.DAYS);//
line n2
}
}
The Java Projects directory exists and contains a list of files.
What is the result?
Given the code fragment:
Path file = Paths.get (“courses.txt”);
// line n1
Assume the courses.txt is accessible.
Which code fragment can be inserted at line n1 to enable the code to print the content of the courses.txt file?
Given the code fragment:
Stream> iStr= Stream.of (
Arrays.asList (“1”, “John”),
Arrays.asList (“2”, null)0;
Stream<
nInSt.forEach (System.out :: print);
What is the result?
Given:
class Worker extends Thread {
CyclicBarrier cb;
public Worker(CyclicBarrier cb) { this.cb = cb; }
public void run () {
try {
cb.await();
System.out.println(“Worker…”);
} catch (Exception ex) { }
}
}
class Master implements Runnable { //line n1
public void run () {
System.out.println(“Master…”);
}
}
and the code fragment:
Master master = new Master();
//line n2
Worker worker = new Worker(cb);
worker.start();
You have been asked to ensure that the run methods of both the Worker and Master classes are executed.
Which modification meets the requirement?