Summer Special - Limited Time 65% Discount Offer - Ends in 0d 00h 00m 00s - Coupon code: top65certs

Java SE 1z0-809 Reddit Questions

Page: 2 / 16
Total 208 questions

Java SE 8 Programmer II Questions and Answers

Question 5

Given:

public class Product {

int id; int price;

public Product (int id, int price) {

this.id = id;

this.price = price;

}

Public String toString () { return id + “:” + price;)

}

and the code fragment:

List products = new ArrayList <> (Arrays.asList(new Product(1, 10),

new Product (2, 30),

new Product (3, 20));

Product p = products.stream().reduce(new Product (4, 0), (p1, p2) -> {

p1.price+=p2.price;

return new Product (p1.id, p1.price);});

products.add(p);

products.stream().parallel()

.reduce((p1, p2) - > p1.price > p2.price ? p1 : p2)

.ifPresent(System.out: :println);

What is the result?

Options:

A.

4:60

B.

2:30

C.

4:602:303:201:10

D.

4:0

E.

The program prints nothing

Question 6

Given the records from the Employee table:

and given the code fragment:

try {

Connection conn = DriverManager.getConnection (URL, userName, passWord);

Statement st = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,

ResultSet.CONCUR_UPDATABLE);

st.execute(“SELECT*FROM Employee”);

ResultSet rs = st.getResultSet();

while (rs.next()) {

if (rs.getInt(1) ==112) {

rs.updateString(2, “Jack”);

}

}

rs.absolute(2);

System.out.println(rs.getInt(1) + “ “ + rs.getString(2));

} catch (SQLException ex) {

System.out.println(“Exception is raised”);

}

Assume that:

The required database driver is configured in the classpath.

The appropriate database accessible with the URL, userName, and passWord exists.

What is the result?

Options:

A.

The Employee table is updated with the row:112 Jackand the program prints:112 Jerry

B.

The Employee table is updated with the row:112 Jackand the program prints:112 Jack

C.

The Employee table is not updated and the program prints:112 Jerry

D.

The program prints Exception is raised.

Question 7

Given the code fragment:

LocalDate valentinesDay =LocalDate.of(2015, Month.FEBRUARY, 14);

LocalDate next15days = valentinesDay.plusDays (15);

LocalDate nextYear = next15days.plusYears(1); // line n1

System.out.println(nextYear);

What is the result?

Options:

A.

2016-03-01

B.

A DateTimeException is thrown.

C.

2016-02-29

D.

A compilation error occurs at line n1.

Question 8

Given:

and the code fragment:

Which modification enables the code fragment to print Speaker?

Options:

A.

Implement Predicate in the Product.ProductFilter class and replace line n2 with .filter (p -> p.ProductFilter.test (p))

B.

Replace line n1 with:public static boolean isAvailable (Product p) {

C.

Replace line n2 with:.filter (p -> p.ProductFilter: :isAvailable (p))

D.

Replace line n2 with:.filter (p -> Product: :ProductFilter: :isAvailable ())

Page: 2 / 16
Total 208 questions