Pass the Oracle Java SE 1z0-809 Questions and answers with CertsForce

Viewing page 6 out of 7 pages
Viewing questions 51-60 out of questions
Questions # 51:

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?

Options:

A.

{1007 = A, 1002 = C, 1001 = B, 1003 = B}


B.

{1001 = B, 1002 = C, 1003 = B, 1007 = A}


C.

{1002 = C, 1003 = B, 1007 = A}


D.

{1007 = A, 1001 = B, 1003 = B, 1002 = C}


Expert Solution
Questions # 52:

Given:

public interface Moveable {

public default void walk (Integer distance) {System.out.println(“Walking”);)

public void run(Integer distance);

}

Which statement is true?

Options:

A.

Moveable can be used as below:Moveable animal = n - > System.out.println(“Running” + n);animal.run(100);animal.walk(20);


B.

Moveable can be used as below:Moveable animal = n - > n + 10;animal.run(100);animal.walk(20);


C.

Moveable can be used as below:Moveable animal = (Integer n) - > System.out.println(n);animal.run(100);Moveable.walk(20);


D.

Movable cannot be used in a lambda expression.


Expert Solution
Questions # 53:

Given this code;

Question # 53

Which two are correct after this class is instantiated and tested?

Options:

A.

If the value of j is set to 15, the value of i could be any integer value.


B.

If the value of j is set to 5, the value of i will be 15.


C.

If the value of i is set to 8, the value of j could be any integer value.


D.

If the value of i is set to 5, the value of j will be 1.


E.

If the value of i is set to 6, the value of j will be 18.


F.

If the value of i remains 3, the value of j will remain 9.


Expert Solution
Questions # 54:

Given the code fragment:

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

BufferedReader brCopy = null;

try (BufferedReader br = new BufferedReader (new FileReader(“employee.txt”))) { //

line n1

br.lines().forEach(c -> System.out.println(c));

brCopy = br;//line n2

}

brCopy.ready(); //line n3;

}

Assume that the ready method of the BufferedReader, when called on a closed BufferedReader, throws an exception, and employee.txt is accessible and contains valid text.

What is the result?

Options:

A.

A compilation error occurs at line n3.


B.

A compilation error occurs at line n1.


C.

A compilation error occurs at line n2.


D.

The code prints the content of the employee.txt file and throws an exception at line n3.


Expert Solution
Questions # 55:

Given:

Question # 55

From what threading problem does the program suffer?

Options:

A.

race condition


B.

deadlock


C.

starvation


D.

livelock


Expert Solution
Questions # 56:

Given the content:

Question # 56

and the code fragment:

Question # 56

What is the result?

Options:

A.

username = Entrez le nom d’utilisateurpassword = Entrez le mot de passe


B.

username = Enter User Namepassword = Enter Password


C.

A compilation error occurs.


D.

The program prints nothing.


Expert Solution
Questions # 57:

Given the definition of the Book class:

Question # 57

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.


Expert Solution
Questions # 58:

Given:

Question # 58

and the code fragment:

Question # 58

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 ())


Expert Solution
Questions # 59:

Given that course.txt is accessible and contains:

Course : : Java

and given the code fragment:

public static void main (String[ ] args) {

int i;

char c;

try (FileInputStream fis = new FileInputStream (“course.txt”);

InputStreamReader isr = new InputStreamReader(fis);) {

while (!isr.close()) { //line n1

isr.skip(2);

i = isr.read ();

c = (char) i;

System.out.print(c);

}

} catch (Exception e) {

e.printStackTrace();

}

}

What is the result?

Options:

A.

ur :: va


B.

ueJa


C.

The program prints nothing.


D.

A compilation error occurs at line n1.


Expert Solution
Questions # 60:

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.


Expert Solution
Viewing page 6 out of 7 pages
Viewing questions 51-60 out of questions