Free Oracle 1Z0-809 Exam Questions (page: 13)

Given the code fragments:
interface CourseFilter extends Predicate<String> {
public default boolean test (String str) {
return str.equals (“Java”);
}
}

and

List<String> strs = Arrays.asList(“Java”, “Java EE”, “Java ME”);
Predicate<String> cf1 = s - > s.length() > 3;
Predicate cf2 = new CourseFilter() { //line n1
public boolean test (String s) {
return s.contains (“Java”);
}
};
long c = strs.stream()
.filter(cf1)
.filter(cf2 //line n2
.count();
System.out.println(c);

What is the result?

  1. 2
  2. 3
  3. A compilation error occurs at line n1.
  4. A compilation error occurs at line n2.

Answer(s): B



Given:
public class Emp {
String fName;
String lName;
public Emp (String fn, String ln) {
fName = fn;
lName = ln;
}
public String getfName() { return fName; }
public String getlName() { return lName; }
}

and the code fragment:

List<Emp> emp = Arrays.asList (
new Emp (“John”, “Smith”),
new Emp (“Peter”, “Sam”),
new Emp (“Thomas”, “Wale”));
emp.stream()
//line n1
.collect(Collectors.toList());

Which code fragment, when inserted at line n1, sorts the employees list in descending order of fName and then ascending order of lName?

  1. .sorted (Comparator.comparing(Emp::getfName).reserved().thenComparing (Emp::getlName))
  2. .sorted (Comparator.comparing(Emp::getfName).thenComparing(Emp::getlName))
  3. .map(Emp::getfName).sorted(Comparator.reserveOrder())
  4. .map(Emp::getfName).sorted(Comparator.reserveOrder().map (Emp::getlName).reserved

Answer(s): B



Given:
public enum USCurrency {
PENNY (1),
NICKLE(5),
DIME (10),
QUARTER(25);

private int value;

public USCurrency(int value) {
this.value = value;
}
public int getValue() {return value;}
}
public class Coin {
public static void main (String[] args) {
USCurrency usCoin =new USCurrency.DIME;
System.out.println(usCoin.getValue()):
}
}

Which two modifications enable the given code to compile? (Choose two.)

  1. Nest the USCurrency enumeration declaration within the Coin class.
  2. Make the USCurrency enumeration constructor private.
  3. Remove the new keyword from the instantion of usCoin.
  4. Make the getter method of value as a static method.
  5. Add the final keyword in the declaration of value.

Answer(s): B,C



Given:
class ImageScanner implements AutoCloseable {
public void close () throws Exception {
System.out.print (“Scanner closed.”);
}
public void scanImage () throws Exception {
System.out.print (“Scan.”);
throw new Exception(“Unable to scan.”);
}
}
class ImagePrinter implements AutoCloseable {
public void close () throws Exception {
System.out.print (“Printer closed.”);
}
public void printImage () {System.out.print(“Print.”); }
}

and this code fragment:

try (ImageScanner ir = new ImageScanner();
ImagePrinter iw = new ImagePrinter()) {
ir.scanImage();
iw.printImage();
} catch (Exception e) {
System.out.print(e.getMessage());
}

What is the result?

  1. Scan.Printer closed. Scanner closed. Unable to scan.
  2. Scan.Scanner closed. Unable to scan.
  3. Scan. Unable to scan.
  4. Scan. Unable to scan. Printer closed.

Answer(s): A



Viewing page 13 of 42



Post your Comments and Discuss Oracle 1Z0-809 exam prep with other Community members:

1Z0-809 Exam Discussions & Posts