Labour Day Special 65% Discount Offer - Ends in 0d 00h 00m 00s - Coupon code: exams65

Java SE 8 Programmer II Question and Answers

Java SE 8 Programmer II

Last Update May 1, 2024
Total Questions : 196

We are offering FREE 1z0-809 Oracle exam questions. All you do is to just go and sign up. Give your details, prepare 1z0-809 free exam questions and then go for complete pool of Java SE 8 Programmer II test questions that will help you more.

1z0-809 pdf

1z0-809 PDF

$35  $99.99
1z0-809 Engine

1z0-809 Testing Engine

$42  $119.99
1z0-809 PDF + Engine

1z0-809 PDF + Testing Engine

$56  $159.99
Questions 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.

Discussion 0
Questions 2

Given:

class Worker extends Thread {

CyclicBarrier cb;

public Worker(CyclicBarrier cb) { this.cb = cb; }

public void run () {

try {

cb.await();

System.out.println(“Worker…”);

} catch (Exception ex) { }

}

}

class Master implements Runnable { //line n1

public void run () {

System.out.println(“Master…”);

}

}

and the code fragment:

Master master = new Master();

//line n2

Worker worker = new Worker(cb);

worker.start();

You have been asked to ensure that the run methods of both the Worker and Master classes are executed.

Which modification meets the requirement?

Options:

A.  

At line n2, insert CyclicBarrier cb = new CyclicBarrier(2, master);

B.  

Replace line n1 with class Master extends Thread {

C.  

At line n2, insert CyclicBarrier cb = new CyclicBarrier(1, master);

D.  

At line n2, insert CyclicBarrier cb = new CyclicBarrier(master);

Discussion 0
Questions 3

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

Discussion 0
Questions 4

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.

Discussion 0
Questions 5

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.

Discussion 0
Questions 6

Given the code fragment:

List empDetails = Arrays.asList(“100, Robin, HR”,

“200, Mary, AdminServices”,

“101, Peter, HR”);

empDetails.stream()

.filter(s-> s.contains(“1”))

.sorted()

.forEach(System.out::println); //line n1

What is the result?

Options:

A.  

100, Robin, HR101, Peter, HR

B.  

E. A compilation error occurs at line n1.

C.  

100, Robin, HR101, Peter, HR200, Mary, AdminServices

D.  

100, Robin, HR200, Mary, AdminServices101, Peter, HR

Discussion 0
Questions 7

Which statement is true about the DriverManager class?

Options:

A.  

It returns an instance of Connection.

B.  

It executes SQL statements against the database.

C.  

It only queries metadata of the database.

D.  

it is written by different vendors for their specific database.

Discussion 0
Questions 8

Which statement is true about java.util.stream.Stream?

Options:

A.  

A stream cannot be consumed more than once.

B.  

The execution mode of streams can be changed during processing.

C.  

Streams are intended to modify the source data.

D.  

A parallel stream is always faster than an equivalent sequential stream.

Discussion 0
Questions 9

Given:

class Student {

String course, name, city;

public Student (String name, String course, String city) {

this.course = course; this.name = name; this.city = city;

}

public String toString() {

return course + “:” + name + “:” + city;

}

public String getCourse() {return course;}

public String getName() {return name;}

public String getCity() {return city;}

and the code fragment:

List stds = Arrays.asList(

new Student (“Jessy”, “Java ME”, “Chicago”),

new Student (“Helen”, “Java EE”, “Houston”),

new Student (“Mark”, “Java ME”, “Chicago”));

stds.stream()

.collect(Collectors.groupingBy(Student::getCourse))

.forEach(src, res) -> System.out.println(scr));

What is the result?

Options:

A.  

A compilation error occurs.

B.  

Java EEJava ME

C.  

[Java EE: Helen:Houston][Java ME: Jessy:Chicago, Java ME: Mark:Chicago]

D.  

[Java ME: Jessy:Chicago, Java ME: Mark:Chicago][Java EE: Helen:Houston]

Discussion 0
Questions 10

Given the code fragment:

What is the result?

Options:

A.  

text1text2

B.  

text1text2text2text3

C.  

text1

D.  

[text1, text2]

Discussion 0
Questions 11

Assume customers.txt is accessible and contains multiple lines.

Which code fragment prints the contents of the customers.txt file?

Options:

A.  

Stream stream = Files.find (Paths.get (“customers.txt”));stream.forEach((String c) -> System.out.println(c));

B.  

Stream stream = Files.find (Paths.get (“customers.txt”));stream.forEach( c) -> System.out.println(c));

C.  

Stream stream = Files.list (Paths.get (“customers.txt”));stream.forEach( c) -> System.out.println(c));

D.  

Stream lines = Files.lines (Paths.get (“customers.txt”));lines.forEach( c) -> System.out.println(c));

Discussion 0
Questions 12

Given the code fragment:

You have been asked to define the ProductCode class. The definition of the ProductCode class must allow c1 instantiation to succeed and cause a compilation error on c2 instantiation.

Which definition of ProductCode meets the requirement?

Options:

A.  

B.  

C.  

D.  

Discussion 0
Questions 13

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.

Discussion 0
Questions 14

Given the code fragment:

List<Double> doubles = Arrays.asList (100.12, 200.32);

DoubleFunction funD = d –> d + 100.0;

doubles.stream (). forEach (funD); // line n1

doubles.stream(). forEach(e –> System.out.println(e)); // line n2

What is the result?

Options:

A.  

A compilation error occurs at line n2.

B.  

200.12300.32

C.  

100.12200.32

D.  

A compilation error occurs at line n1.

Discussion 0
Questions 15

Given the code fragment:

Which two code fragments, when inserted at line n1 independently, result in the output PEEK: Unix?

Options:

A.  

.anyMatch ();

B.  

.allMatch ();

C.  

.findAny ();

D.  

.noneMatch ();

E.  

.findFirst ();

Discussion 0
Questions 16

What is the result?

Options:

A.  

A compilation error occurs at line 7.

B.  

100

C.  

A compilation error occurs at line 8.

D.  

A compilation error occurs at line 15.

Discussion 0
Questions 17

Given the code fragments:

and

Which two modifications enable to sort the elements of the emps list? (Choose two.)

Options:

A.  

Replace line n1 withclass Person extends Comparator

B.  

At line n2 insertpublic int compareTo (Person p) {return this.name.compareTo (p.name);}

C.  

Replace line n1 withclass Person implements Comparable

D.  

At line n2 insertpublic int compare (Person p1, Person p2) {return p1.name.compareTo (p2.name);}

E.  

At line n2 insert:public int compareTo (Person p, Person p2) {return p1.name.compareTo (p2.name);}

F.  

Replace line n1 withclass Person implements Comparator

Discussion 0
Questions 18

Which two are elements of a singleton class? (Choose two.)

Options:

A.  

a transient reference to point to the single instance

B.  

a public method to instantiate the single instance

C.  

a public static method to return a copy of the singleton reference

D.  

a private constructor to the class

E.  

a public reference to point to the single instance

Discussion 0
Questions 19

Given:

and the code fragment:

What is the result?

Options:

A.  

[Java EE: Helen:Houston][Java ME: Jessy:Chicago, Java ME: Mark:Chicago]

B.  

Java EEJava ME

C.  

[Java ME: Jessy:Chicago, Java ME: Mark:Chicago][Java EE: Helen:Houston]

D.  

A compilation error occurs.

Discussion 0
Questions 20

Given the code fragment:

What is the result?

Options:

A.  

A compilation error occurs at line n1.

B.  

A compilation error occurs at line n2.

C.  

The code reads the password without echoing characters on the console.

D.  

A compilation error occurs because the IOException isn’t declared to be thrown or caught?

Discussion 0
Questions 21

Given the code fragments:

class Caller implements Callable {

String str;

public Caller (String s) {this.str=s;}

public String call()throws Exception { return str.concat (“Caller”);}

}

class Runner implements Runnable {

String str;

public Runner (String s) {this.str=s;}

public void run () { System.out.println (str.concat (“Runner”));}

}

and

public static void main (String[] args) InterruptedException, ExecutionException {

ExecutorService es = Executors.newFixedThreadPool(2);

Future f1 = es.submit (new Caller (“Call”));

Future f2 = es.submit (new Runner (“Run”));

String str1 = (String) f1.get();

String str2 = (String) f2.get();//line n1

System.out.println(str1+ “:” + str2);

}

What is the result?

Options:

A.  

The program prints:Run RunnerCall Caller : nullAnd the program does not terminate.

B.  

The program terminates after printing:Run RunnerCall Caller : Run

C.  

A compilation error occurs at line n1.

D.  

An Execution is thrown at run time.

Discussion 0
Questions 22

Given:

class Bird {

public void fly () { System.out.print(“Can fly”); }

}

class Penguin extends Bird {

public void fly () { System.out.print(“Cannot fly”); }

}

and the code fragment:

class Birdie {

public static void main (String [ ] args) {

fly( ( ) -> new Bird ( ));

fly (Penguin : : new);

}

/* line n1 */

}

Which code fragment, when inserted at line n1, enables the Birdie class to compile?

Options:

A.  

static void fly (Consumer bird) {bird :: fly ();}

B.  

static void fly (Consumer bird) {bird.accept( ) fly ();}

C.  

static void fly (Supplier bird) {bird.get( ) fly ();}

D.  

static void fly (Supplier bird) {LOST

Discussion 0
Questions 23

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

Discussion 0
Questions 24

Given the code fragment:

Assume that the value of now is 6:30 in the morning.

What is the result?

Options:

A.  

An exception is thrown at run time.

B.  

0

C.  

60

D.  

1

Discussion 0
Questions 25

Given that these files exist and are accessible:

and given the code fragment:

Which code fragment can be inserted at line n1 to enable the code to print only /company/emp?

Options:

A.  

Stream stream = Files.list (Paths.get (“/company”));

B.  

Stream stream = Files.find(Paths.get (“/company”), 1,(p,b) –> b.isDirectory (), FileVisitOption.FOLLOW_LINKS);

C.  

Stream stream = Files.walk (Paths.get (“/company”));

D.  

Stream stream = Files.list (Paths.get (“/company/emp”));

Discussion 0
Questions 26

Given the code fragment:

List colors = Arrays.asList(“red”, “green”, “yellow”);

Predicate test = n - > {

System.out.println(“Searching…”);

return n.contains(“red”);

};

colors.stream()

.filter(c -> c.length() > 3)

.allMatch(test);

What is the result?

Options:

A.  

Searching…

B.  

Searching…Searching…

C.  

Searching…Searching…Searching…

D.  

A compilation error occurs.

Discussion 0
Questions 27

Given the code fragments :

and

What is the result?

Options:

A.  

TV Price :110 Refrigerator Price :2100

B.  

A compilation error occurs.

C.  

TV Price :1000 Refrigerator Price :2000

D.  

The program prints nothing.

Discussion 0
Questions 28

Given the code fragment:

What is the result?

Options:

A.  

A compilation error occurs at line n2.

B.  

3

C.  

2

D.  

A compilation error occurs at line n1.

Discussion 0
Questions 29

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 + “ “));

Discussion 0