1z0-809

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

Question 16

Given the code fragment: Map books = new TreeMap (); books.put (1007, "A"); books.put (1002, "C"); books.put (1001, "B"); books.put (1003, "B"); System.out.println (books); What is the result?

  1. {1007 = A, 1002 = C, 1001 = B, 1003 = B}
  2. {1001 = B, 1002 = C, 1003 = B, 1007 = A}
  3. {1002 = C, 1003 = B, 1007 = A}
  4. {1007 = A, 1001 = B, 1003 = B, 1002 = C}

Question 17

Given: class Book { int id; String name; public Book (int id, String name) { this.id = id; this.name = name; } public boolean equals (Object obj) { //line n1 boolean output = false; Book b = (Book) obj; if (this.name.equals(b name))} output = true; } return output; } } and the code fragment: Book b1 = new Book (101, "Java Programing"); Book b2 = new Book (102, "Java Programing"); System.out.println (b1.equals(b2)); //line n2 Which statement is true?

  1. The program prints true.
  2. The program prints false.
  3. A compilation error occurs. To ensure successful compilation, replace line n1 with: boolean equals (Book obj) {
  4. A compilation error occurs. To ensure successful compilation, replace line n2 with: System.out.println (b1.equals((Object) b2));

Question 18

Given the content of /resourses/Message.properties: welcome1="Good day!" and given the code fragment: Properties prop = new Properties (); FileInputStream fis = new FileInputStream ("/resources/Message.properties"); prop.load(fis); System.out.println(prop.getProperty("welcome1")); System.out.println(prop.getProperty("welcome2", "Test"));//line n1 System.out.println(prop.getProperty("welcome3")); What is the result?

  1. Good day! Test followed by an Exception stack trace
  2. Good day! followed by an Exception stack trace
  3. Good day! Test null
  4. A compilation error occurs at line n1.

Question 19

Which action can be used to load a database driver by using JDBC3.0?

  1. Add the driver class to the META-INF/services folder of the JAR file.
  2. Include the JDBC driver class in a jdbc.properties file.
  3. Use the java.lang.Class.forName method to load the driver class.
  4. Use the DriverManager.getDriver method to load the driver class.

Question 20

Given the code fragment: Path p1 = Paths.get("/Pics/MyPic.jpeg"); System.out.println (p1.getNameCount() + ":" + p1.getName(1) + ":" + p1.getFileName()); Assume that the Pics directory does NOT exist. What is the result?

  1. An exception is thrown at run time.
  2. 2:MyPic.jpeg: MyPic.jpeg
  3. 3:.:MyPic.jpeg
  4. 2:Pics: MyPic.jpeg