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

1z0-809 Java SE 8 Programmer II Questions and Answers

Questions 4

Given:

and the code fragment:

The threads t1 and t2 execute asynchronously and possibly prints ABCA or AACB.

You have been asked to modify the code to make the threads execute synchronously and prints ABC.

Which modification meets the requirement?

Options:

A.

start the threads t1 and t2 within a synchronized block.

B.

Replace line n1 with:private synchronized int count = 0;

C.

Replace line n2 with:public synchronized void run () {

D.

Replace line n2 with:volatile int count = 0;

Buy Now
Questions 5

Given:

What is the result?

Options:

A.

–catch--finally--dostuff-

B.

–catch-

C.

–finally--catch-

D.

–finally-dostuff--catch-

Buy Now
Questions 6

Given:

class Sum extends RecursiveAction { //line n1

static final int THRESHOLD_SIZE = 3;

int stIndex, lstIndex;

int [ ] data;

public Sum (int [ ]data, int start, int end) {

this.data = data;

this stIndex = start;

this. lstIndex = end;

}

protected void compute ( ) {

int sum = 0;

if (lstIndex – stIndex <= THRESHOLD_SIZE) {

for (int i = stIndex; i < lstIndex; i++) {

sum += data [i];

}

System.out.println(sum);

} else {

new Sum (data, stIndex + THRESHOLD_SIZE, lstIndex).fork( );

new Sum (data, stIndex,

Math.min (lstIndex, stIndex + THRESHOLD_SIZE)

).compute ();

}

}

}

and the code fragment:

ForkJoinPool fjPool = new ForkJoinPool ( );

int data [ ] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}

fjPool.invoke (new Sum (data, 0, data.length));

and given that the sum of all integers from 1 to 10 is 55.

Which statement is true?

Options:

A.

The program prints several values that total 55.

B.

The program prints 55.

C.

A compilation error occurs at line n1.

D.

The program prints several values whose sum exceeds 55.

Buy Now
Questions 7

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.

Buy Now
Questions 8

Given that /green.txt and /colors/yellow.txt are accessible, and the code fragment:

Path source = Paths.get(“/green.txt);

Path target = Paths.get(“/colors/yellow.txt);

Files.move(source, target, StandardCopyOption.ATOMIC_MOVE);

Files.delete(source);

Which statement is true?

Options:

A.

The green.txt file content is replaced by the yellow.txt file content and the yellow.txt file is deleted.

B.

The yellow.txt file content is replaced by the green.txt file content and an exception is thrown.

C.

The file green.txt is moved to the /colors directory.

D.

A FileAlreadyExistsException is thrown at runtime.

Buy Now
Questions 9

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?

Options:

A.

An exception is thrown at run time.

B.

2:MyPic.jpeg: MyPic.jpeg

C.

1:Pics:/Pics/ MyPic.jpeg

D.

2:Pics: MyPic.jpeg

Buy Now
Questions 10

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

Buy Now
Questions 11

Given:

What is the result?

Options:

A.

Hi Interface-2

B.

A compilation error occurs.

C.

Hi Interface-1

D.

Hi MyClass

Buy Now
Questions 12

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

Buy Now
Questions 13

Given the code fragment:

Which statement can be inserted into line n1 to print 1,2; 1,10; 2,20;?

Options:

A.

BiConsumer c = (i, j) -> {System.out.print (i + “,” + j+ “; “);};

B.

BiFunction c = (i, j) –> {System.out.print (i + “,” + j+ “; “)};

C.

BiConsumer c = (i, j) –> {System.out.print (i + “,” + j+ “; “)};

D.

BiConsumer c = (i, j) –> {System.out.print (i + “,” + j+ “; “);};

Buy Now
Questions 14

Given the code fragment:

Which should be inserted into line n1 to print Average = 2.5?

Options:

A.

IntStream str = Stream.of (1, 2, 3, 4);

B.

IntStream str = IntStream.of (1, 2, 3, 4);

C.

DoubleStream str = Stream.of (1.0, 2.0, 3.0, 4.0);

D.

Stream str = Stream.of (1, 2, 3, 4);

Buy Now
Questions 15

Given the code fragment:

What is the result?

Options:

A.

DavidDavid[Susan, Allen]

B.

SusanSusan[Susan, Allen]

C.

SusanAllen[David]

D.

DavidAllen[Susan]

E.

SusanAllen[Susan, David]

Buy Now
Questions 16

Given the code fragment:

What is the result?

Options:

A.

A compilation error occurs at line n1.

B.

Logged out at: 2015-01-12T21:58:19.880Z

C.

Can’t logout

D.

Logged out at: 2015-01-12T21:58:00Z

Buy Now
Questions 17

Which two reasons should you use interfaces instead of abstract classes? (Choose two.)

Options:

A.

You expect that classes that implement your interfaces have many common methods or fields, or require access modifiers other than public.

B.

You expect that unrelated classes would implement your interfaces.

C.

You want to share code among several closely related classes.

D.

You want to declare non-static on non-final fields.

E.

You want to take advantage of multiple inheritance of type.

Buy Now
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

Buy Now
Questions 19

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.

Buy Now
Questions 20

Given the code fragment:

Path source = Paths.get (“/data/december/log.txt”);

Path destination = Paths.get(“/data”);

Files.copy (source, destination);

and assuming that the file /data/december/log.txt is accessible and contains:

10-Dec-2014 – Executed successfully

What is the result?

Options:

A.

A file with the name log.txt is created in the /data directory and the content of the /data/december/log.txt file is copied to it.

B.

The program executes successfully and does NOT change the file system.

C.

A FileNotFoundException is thrown at run time.

D.

A FileAlreadyExistsException is thrown at run time.

Buy Now
Questions 21

Given the code fragment:

Which code fragment, when inserted at line 7, enables printing 100?

Options:

A.

Function funRef = e –> e + 10;Integer result = funRef.apply(value);

B.

IntFunction funRef = e –> e + 10;Integer result = funRef.apply (10);

C.

ToIntFunction funRef = e –> e + 10;int result = funRef.applyAsInt (value);

D.

ToIntFunction funRef = e –> e + 10;int result = funRef.apply (value);

Buy Now
Questions 22

Given the code fragment:

Path file = Paths.get (“courses.txt”);

// line n1

Assume the courses.txt is accessible.

Which code fragment can be inserted at line n1 to enable the code to print the content of the courses.txt file?

Options:

A.

List fc = Files.list(file);fc.stream().forEach (s - > System.out.println(s));

B.

Stream fc = Files.readAllLines (file);fc.forEach (s - > System.out.println(s));

C.

List fc = readAllLines(file);fc.stream().forEach (s - > System.out.println(s));

D.

Stream fc = Files.lines (file);fc.forEach (s - > System.out.println(s));

Buy Now
Questions 23

Given:

class Vehicle implements Comparable{

int vno;

String name;

public Vehicle (int vno, String name) {

this.vno = vno,;

this.name = name;

}

public String toString () {

return vno + “:” + name;

}

public int compareTo(Vehicle o) {

return this.name.compareTo(o.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:Ford, 10124:BMW]

B.

[10124:BMW, 10123:Ford]

C.

A compilation error occurs.

D.

A ClassCastException is thrown at run time.

Buy Now
Questions 24

Given the code fragment:

List str = Arrays.asList (“my”, “pen”, “is”, “your’, “pen”);

Predicate test = s -> {

int i = 0;

boolean result = s.contains (“pen”);

System.out.print(i++) + “:”);

return result;

};

str.stream()

.filter(test)

.findFirst()

.ifPresent(System.out ::print);

What is the result?

Options:

A.

0 : 0 : pen

B.

0 : 1 : pen

C.

0 : 0 : 0 : 0 : 0 : pen

D.

0 : 1 : 2 : 3 : 4 :

E.

A compilation error occurs.

Buy Now
Questions 25

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.

Buy Now
Questions 26

You have been asked to create a ResourceBundle which uses a properties file to localize an application.

Which code example specifies valid keys of menu1 and menu2 with values of File Menu and View Menu?

Options:

A.

File MenuView Menu

B.

menu1File Menumenu2View Menu

C.

menu1, File Menu, menu2, View Menu

D.

menu1 = File Menumenu2 = View Menu

Buy Now
Questions 27

Given the code fragments:

and

What is the result?

Options:

A.

null

B.

A compilation error occurs.

C.

DogCatMouse

D.

[Dog, Cat, Mouse]

Buy Now
Questions 28

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.

Buy Now
Questions 29

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

Buy Now
Exam Code: 1z0-809
Exam Name: Java SE 8 Programmer II
Last Update: Jun 15, 2025
Questions: 196
1z0-809 pdf

1z0-809 PDF

$29.75  $84.99
1z0-809 Engine

1z0-809 Testing Engine

$35  $99.99
1z0-809 PDF + Engine

1z0-809 PDF + Testing Engine

$47.25  $134.99