Weekend Sale Special Limited Time 65% Discount Offer - Ends in 0d 00h 00m 00s - Coupon code: suredis

Oracle 1z0-809 Java SE 8 Programmer II Exam Practice Test

Page: 1 / 20
Total 196 questions

Java SE 8 Programmer II Questions and Answers

Testing Engine

  • Product Type: Testing Engine
$42  $119.99

PDF Study Guide

  • Product Type: PDF Study Guide
$36.75  $104.99
Question 1

Given:

and the code fragment:

What is the result?

Options:

A.

A compilation error occurs at line n2.

B.

A compilation error occurs because the try block doesn’t have a catch or finally block.

C.

A compilation error occurs at line n1.

D.

The program compiles successfully.

Question 2

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.id = = b.id) {

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?

Options:

A.

The program prints true.

B.

The program prints false.

C.

A compilation error occurs. To ensure successful compilation, replace line n1 with:boolean equals (Book obj) {

D.

A compilation error occurs. To ensure successful compilation, replace line n2 with:System.out.println (b1.equals((Object) b2));

Question 3

Given the code fragment:

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

LocalDate nextYear = valentinesDay.plusYears(1);

nextYear.plusDays(15); //line n1

System.out.println(nextYear);

What is the result?

Options:

A.

2016-02-14

B.

A DateTimeException is thrown.

C.

2016-02-29

D.

A compilation error occurs at line n1.

Question 4

Given that these files exist and are accessible:

/sports/info.txt

/sports/cricket/players.txt

/sports/cricket/data/ODI.txt

and given the code fragment:

int maxDepth =2;

Stream paths = Files.find(Paths.get(“/sports”),

maxDepth,

(p, a) -> p.getFileName().toString().endsWith (“txt”),

FileVisitOption.FOLLOW_LINKS);

Long fCount = paths.count();

System.out.println(fCount);

Assuming that there are NO soft-link/symbolic links to any of the files in the directory structure, what is the result?

Options:

A.

1

B.

2

C.

3

D.

An Exception is thrown at runtime.

Question 5

Given the code fragments:

interface CourseFilter extends Predicate {

public default boolean test (String str) {

return str.equals (“Java”);

}

}

and

List strs = Arrays.asList(“Java”, “Java EE”, “Java ME”);

Predicate 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?

Options:

A.

2

B.

3

C.

A compilation error occurs at line n1.

D.

A compilation error occurs at line n2.

Question 6

Given the content of the employee.txt file:

Every worker is a master.

Given that the employee.txt file is accessible and the file allemp.txt does NOT exist, and the code fragment:

What is the result?

Options:

A.

Exception 1

B.

Exception 2

C.

The program executes, does NOT affect the system, and produces NO output.

D.

allemp.txt is created and the content of employee.txt is copied to it.

Question 7

Given the code fragment:

BiFunction val = (t1, t2) -> t1 + t2; //line n1

//line n2

System.out.println(val.apply(10, 10.5));

What is the result?

Options:

A.

20

B.

20.5

C.

A compilation error occurs at line n1.

D.

A compilation error occurs at line n2.

Question 8

Given the code fragment:

Stream> iStr= Stream.of (

Arrays.asList (“1”, “John”),

Arrays.asList (“2”, null)0;

Stream< nInSt = iStr.flatMapToInt ((x) -> x.stream ());

nInSt.forEach (System.out :: print);

What is the result?

Options:

A.

1John2null

B.

12

C.

A NullPointerException is thrown at run time.

D.

A compilation error occurs.

Question 9

Given:

class Vehicle {

int vno;

String name;

public Vehicle (int vno, String name) {

this.vno = vno,;

this.name = name;

}

public String toString () {

return vno + “:” + name;

}

}

and this code fragment:

Set vehicles = new TreeSet <> ();

vehicles.add(new Vehicle (10123, “Ford”));

vehicles.add(new Vehicle (10124, “BMW”));

System.out.println(vehicles);

What is the result?

Options:

A.

10123 Ford10124 BMW

B.

10124 BMW10123 Ford

C.

A compilation error occurs.

D.

A ClassCastException is thrown at run time.

Question 10

Given the code fragment:

List values = Arrays.asList (1, 2, 3);

values.stream ()

.map(n -> n*2)//line n1

.peek(System.out::print)//line n2

.count();

What is the result?

Options:

A.

246

B.

The code produces no output.

C.

A compilation error occurs at line n1.

D.

A compilation error occurs at line n2.

Question 11

Given the code fragment:

What is the result?

Options:

A.

A compilation error occurs.

B.

[Java, J2EE, J2ME, JSTL, JSP]

C.

null

D.

[Java, J2EE, J2ME, JSTL]

Question 12

Given:

Item table

• ID, INTEGER: PK

• DESCRIP, VARCHAR(100)

• PRICE, REAL

• QUANTITY< INTEGER

And given the code fragment:

9. try {

10.Connection conn = DriveManager.getConnection(dbURL, username, password);

11. String query = “Select * FROM Item WHERE ID = 110”;

12. Statement stmt = conn.createStatement();

13. ResultSet rs = stmt.executeQuery(query);

14.while(rs.next()) {

15.System.out.println(“ID:“ + rs.getInt(“Id”));

16.System.out.println(“Description:“ + rs.getString(“Descrip”));

17.System.out.println(“Price:“ + rs.getDouble(“Price”));

18. System.out.println(Quantity:“ + rs.getInt(“Quantity”));

19.}

20. } catch (SQLException se) {

21. System.out.println(“Error”);

22. }

Assume that:

The required database driver is configured in the classpath.

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

The SQL query is valid.

What is the result?

Options:

A.

An exception is thrown at runtime.

B.

Compilation fails.

C.

The code prints Error.

D.

The code prints information about Item 110.

Question 13

Given the code fragments:

and

What is the result?

Options:

A.

Video played.Game played.

B.

A compilation error occurs.

C.

class java.lang.Exception

D.

class java.io.IOException

Question 14

Given the code fragment:

and the information:

  • The required database driver is configured in the classpath.
  • The appropriate database is accessible with the dbURL, username, and passWord exists.

What is the result?

Options:

A.

A ClassNotFoundException is thrown at runtime.

B.

The program prints nothing.

C.

The program prints Connection Established.

D.

A SQLException is thrown at runtime.

Question 15

Given:

final class Folder {//line n1

//line n2

public void open () {

System.out.print(“Open”);

}

}

public class Test {

public static void main (String [] args) throws Exception {

try (Folder f = new Folder()) {

f.open();

}

}

}

Which two modifications enable the code to print Open Close? (Choose two.)

Options:

A.

Replace line n1 with:class Folder implements AutoCloseable {

B.

Replace line n1 with:class Folder extends Closeable {

C.

Replace line n1 with:class Folder extends Exception {

D.

At line n2, insert:final void close () {System.out.print(“Close”);}

E.

At line n2, insert:public void close () throws IOException {System.out.print(“Close”);}

Question 16

Given the code fragment:

List list1 = Arrays.asList(10, 20);

List list2 = Arrays.asList(15, 30);

//line n1

Which code fragment, when inserted at line n1, prints 10 20 15 30?

Options:

A.

Stream.of(list1, list2).flatMap(list -> list.stream()).forEach(s -> System.out.print(s + “ “));

B.

Stream.of(list1, list2).flatMap(list -> list.intStream()).forEach(s -> System.out.print(s + “ “));

C.

list1.stream().flatMap(list2.stream().flatMap(e1 -> e1.stream()).forEach(s -> System.out.println(s + “ “));

D.

Stream.of(list1, list2).flatMapToInt(list -> list.stream()).forEach(s -> System.out.print(s + “ “));

Question 17

Given the structure of the Student table:

Student (id INTEGER, name VARCHAR)

Given the records from the STUDENT table:

Given the code fragment:

Assume that:

What is the result?

Options:

A.

The program prints Status: true and two records are deleted from the Student table.

B.

The program prints Status: false and two records are deleted from the Student table.

C.

A SQLException is thrown at runtime.

D.

The program prints Status: false but the records from the Student table are not deleted.

Question 18

Given the code fragments:

class MyThread implements Runnable {

private static AtomicInteger count = new AtomicInteger (0);

public void run () {

int x = count.incrementAndGet();

System.out.print (x+” “);

}

}

and

Thread thread1 = new Thread(new MyThread());

Thread thread2 = new Thread(new MyThread());

Thread thread3 = new Thread(new MyThread());

Thread [] ta = {thread1, thread2, thread3};

for (int x= 0; x < 3; x++) {

ta[x].start();

}

Which statement is true?

Options:

A.

The program prints 1 2 3 and the order is unpredictable.

B.

The program prints 1 2 3.

C.

The program prints 1 1 1.

D.

A compilation error occurs.

Question 19

Given the code fragments:

and

What is the result?

Options:

A.

The program prints Run… and throws an exception.

B.

A compilation error occurs at line n1.

C.

Run…Call…

D.

A compilation error occurs at line n2.

Question 20

Given the code fragment:

Which modification enables the code to print Price 5 New Price 4?

Options:

A.

Replace line n2 with .map (n -> System.out.println (“New Price” + n –1)) and remove line n3

B.

Replace line n2 with .mapToInt (n -> n – 1);

C.

Replace line n1 with .forEach (e -> System.out.print (“Price” + e))

D.

Replace line n3 with .forEach (n -> System.out.println (“New Price” + n));

Question 21

Given the content:

and given the code fragment:

Which two code fragments, when inserted at line 1 independently, enable the code to print “Wie geht’s?”

Options:

A.

currentLocale = new Locale (“de”, “DE”);

B.

currentLocale = new Locale.Builder ().setLanguage (“de”).setRegion (“DE”).build();

C.

currentLocale = Locale.GERMAN;

D.

currentlocale = new Locale();currentLocale.setLanguage (“de”);currentLocale.setRegion (“DE”);

E.

currentLocale = Locale.getInstance(Locale.GERMAN,Locale.GERMANY);

Question 22

Given the code fragment:

Which code fragment, when inserted at line n1, ensures false is printed?

Options:

A.

boolean b = cs.stream() .findAny() .get() .equals(“Java”);

B.

boolean b = cs.stream() .anyMatch (w -> w.equals (“Java”));

C.

boolean b = cs.stream() .findFirst() .get() .equals(“Java”);

D.

boolean b = cs.stream() .allMatch(w -> w.equals(“Java”));

Question 23

Given:

IntStream stream = IntStream.of (1,2,3);

IntFunction inFu= x -> y -> x*y;//line n1

IntStream newStream = stream.map(inFu.apply(10));//line n2

newStream.forEach(System.out::print);

Which modification enables the code fragment to compile?

Options:

A.

Replace line n1 with:IntFunction inFu = x -> y -> x*y;

B.

Replace line n1 with:IntFunction inFu = x -> y -> x*y;

C.

Replace line n1 with:BiFunction inFu = x -> y -> x*y;

D.

Replace line n2 with:IntStream newStream = stream.map(inFu.applyAsInt (10));

Question 24

Given the structure of the STUDENT table:

Student (id INTEGER, name VARCHAR)

Given:

public class Test {

static Connection newConnection =null;

public static Connection get DBConnection () throws SQLException {

try (Connection con = DriveManager.getConnection(URL, username, password)) {

newConnection = con;

}

return newConnection;

}

public static void main (String [] args) throws SQLException {

get DBConnection ();

Statement st = newConnection.createStatement();

st.executeUpdate(“INSERT INTO student VALUES (102, ‘Kelvin’)”);

}

}

Assume that:

The required database driver is configured in the classpath.

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

The SQL query is valid.

What is the result?

Options:

A.

The program executes successfully and the STUDENT table is updated with one record.

B.

The program executes successfully and the STUDENT table is NOT updated with any record.

C.

A SQLException is thrown as runtime.

D.

A NullPointerException is thrown as runtime.

Question 25

Given:

public class Counter {

public static void main (String[ ] args) {

int a = 10;

int b = -1;

assert (b >=1) : “Invalid Denominator”;

int с = a / b;

System.out.println (c);

}

}

What is the result of running the code with the –ea option?

Options:

A.

-10

B.

0

C.

An AssertionError is thrown.

D.

A compilation error occurs.

Question 26

Given:

and the code fragment:

What is the result?

Options:

A.

0

B.

A compilation error occurs at line n1.

C.

An Exception is thrown at run time.

D.

2

Question 27

Given the code fragment:

UnaryOperator uo1 = s -> s*2;line n1

List loanValues = Arrays.asList(1000.0, 2000.0);

loanValues.stream()

.filter(lv -> lv >= 1500)

.map(lv -> uo1.apply(lv))

.forEach(s -> System.out.print(s + “ “));

What is the result?

Options:

A.

4000.0

B.

4000

C.

A compilation error occurs at line n1.

D.

A compilation error occurs at line n2.

Question 28

Given:

From what threading problem does the program suffer?

Options:

A.

race condition

B.

deadlock

C.

starvation

D.

livelock

Question 29

Given the definition of the Book class:

Which statement is true about the Book class?

Options:

A.

It demonstrates encapsulation.

B.

It is defined using the factory design pattern.

C.

It is defined using the singleton design pattern.

D.

It demonstrates polymorphism.

E.

It is an immutable class.

Page: 1 / 20
Total 196 questions