1Z0-809 Exam - Java SE 8 Programmer II

certleader.com

Q1. Given the code fragment: 

Path source = Paths.get (“/data/december/log.txt”); 

Path destination = Paths.get(“/data”); 

Files.copy (source, destination); 

and assuming that the file /data/december/log.txt is accessible and contains: 

10-Dec-2014 – Executed successfully 

What is the result? 

A. A file with the name log.txt is created in the /data directory and the content of the /data/december/log.txt file is copied to it. 

B. The program executes successfully and does NOT change the file system. 

C. A FileNotFoundException is thrown at run time. 

D. A FileAlreadyExistsException is thrown at run time. 

Answer:

Q2. Which two code blocks correctly initialize a Locale variable? 

A. Locale loc1 = “UK”; 

B. Locale loc2 = Locale.getInstance(“ru”); 

C. Locale loc3 = Locale.getLocaleFactory(“RU”); 

D. Locale loc4 = Locale.UK; 

E. Locale loc5 = new Locale (“ru”, “RU”); 

Answer: D,E 

Q3. Given the code fragment: 

Which code fragment prints blue, cyan, ? A. Option A 

B. Option B 

C. Option C 

D. Option D 

Answer:

Q4. Given the code fragments: 

class Employee { 

Optional<Address> address; 

Employee (Optional<Address> address) { 

this.address = address; 

public Optional<Address> getAddress() { return address; } 

class Address { 

String city = “New York”; 

public String getCity { return city: } 

public String toString() { 

return city; 

and 

Address address = null; 

Optional<Address> addrs1 = Optional.ofNullable (address); 

Employee e1 = new Employee (addrs1); 

String eAddress = (addrs1.isPresent()) ? addrs1.get().getCity() : “City Not 

available”; 

What is the result? 

A. New York 

B. City Not available 

C. null 

D. A NoSuchElementException is thrown at run time. 

Answer:

Q5. Given the code fragment: 

ZonedDateTime depart = ZonedDateTime.of(2015, 1, 15, 3, 0, 0, 0, ZoneID.of(“UTC-7”)); ZonedDateTime arrive = ZonedDateTime.of(2015, 1, 15, 9, 0, 0, 0, ZoneID.of(“UTC-5”)); long hrs = ChronoUnit.HOURS.between(depart, arrive); //line n1 System.out.println(“Travel time is” + hrs + “hours”); 

What is the result? 

A. Travel time is 4 hours 

B. Travel time is 6 hours 

C. Travel time is 8 hours 

D. An exception is thrown at line n1. 

Answer:

Q6. Given: A. ns = 50 S = 125 ns = 125 S = 125 ns = 100 S = 125 

B. ns = 50 S = 125 ns = 125 S = 125 ns = 0 S = 125 

C. ns = 50 S = 50 ns = 125 S = 125 ns = 100 S = 100 

D. ns = 50 S = 50 ns = 125 S = 125 ns = 0 S = 125 

Answer:

Q7. 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? 

A. At line n2, insert CyclicBarrier cb = new CyclicBarrier(2, master); 

B. Replace line n1 with class Master extends Thread { 

C. At line n2, insert CyclicBarrier cb = new CyclicBarrier(1, master); 

D. At line n2, insert CyclicBarrier cb = new CyclicBarrier(master); 

Answer:

Q8. Given the code fragment: 

List<String> str = Arrays.asList (“my”, “pen”, “is”, “your’, “pen”); Predicate<String> test = s -> { 

int i = 0; 

boolean result = s.contains (“pen”); 

System.out.print(i++) + “:”); 

return result; 

}; 

str.stream() 

.filter(test) 

.findFirst() 

.ifPresent(System.out ::print); 

What is the result? 

A. 0 : 0 : pen 

B. 0 : 1 : pen 

C. 0 : 0 : 0 : 0 : 0 : pen 

D. 0 : 1 : 2 : 3 : 4 : 

E. A compilation error occurs. 

Answer:

Q9. Given: 

Which two classes use the shape class correctly? 

A. Option A 

B. Option B 

C. Option C 

D. Option D 

E. Option E 

F. Option F 

Answer: B,E 

Explanation: When an abstract class is subclassed, the subclass usually provides implementations for all of the abstract methods in its parent class (E). However, if it does not, then the subclass must also be declared abstract (B). Note: An abstract class is a class that is declared abstract—it may or may not include abstract methods. Abstract classes cannot be instantiated, but they can be subclassed. 

Q10. Given: 

public class Customer { 

private String fName; 

private String lName; 

private static int count; 

public customer (String first, String last) {fName = first, lName = last; 

++count;} 

static { count = 0; } 

public static int getCount() {return count; } 

public class App { 

public static void main (String [] args) { 

Customer c1 = new Customer(“Larry”, “Smith”); 

Customer c2 = new Customer(“Pedro”, “Gonzales”); 

Customer c3 = new Customer(“Penny”, “Jones”); 

Customer c4 = new Customer(“Lars”, “Svenson”); 

c4 = null; 

c3 = c2; 

System.out.println (Customer.getCount()); 

What is the result? 

A. 0 

B. 2 

C. 3 

D. 4 

E. 5 

Answer: