1z0-809

1z0-809 practice questions, page 9 of 10, with answer review and explanations.

Question 41

Given the code fragment: List str = Arrays.asList ("my", "pen", "is", "your', "pen"); Predicate 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?

  1. 0 : 0 : pen
  2. 0 : 1 : pen
  3. 0 : 0 : 0 : 0 : 0 : pen
  4. 0 : 1 : 2 : 3 : 4 :
  5. A compilation error occurs.

Question 42

Given the code fragment: List empDetails = Arrays.asList("100, Robin, HR", "200, Mary, AdminServices", "101, Peter, HR"); empDetails.stream() .filter(s-> s.contains("1")) .sorted() .forEach(System.out::println); //line n1 What is the result?

  1. 100, Robin, HR 101, Peter, HR
  2. A compilation error occurs at line n1.
  3. 100, Robin, HR 101, Peter, HR 200, Mary, AdminServices
  4. 100, Robin, HR 200, Mary, AdminServices 101, Peter, HR

Question 43

Given: interface Rideable {Car getCar (String name); } class Car { private String name; public Car (String name) { this.name = name; } } Which code fragment creates an instance of Car?

  1. Car auto = Car ("MyCar"): : new;
  2. Car auto = Car : : new; Car vehicle = auto : : getCar("MyCar");
  3. Rideable rider = Car : : new; Car vehicle = rider.getCar("MyCar");
  4. Car vehicle = Rideable : : new : : getCar("MyCar");

Question 44

Which statement is true about the single abstract method of the java.util.function.Function interface?

  1. It accepts one argument and returns void.
  2. It accepts one argument and returns boolean.
  3. It accepts one argument and always produces a result of the same type as the argument.
  4. It accepts an argument and produces a result of any data type.

Question 45

Which statement is true about the DriverManager class?

  1. It returns an instance of database.
  2. It executes SQL statements against the database.
  3. It loads the database driver class mentioned in the jdbc.drivers property
  4. it is written by different vendors for their specific database.