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

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

Questions 4

Given the code fragment:

public class FileThread implements Runnable {

String fName;

public FileThread(String fName) { this.fName = fName; }

public void run () System.out.println(fName);}

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

ExecutorService executor = Executors.newCachedThreadPool();

Stream listOfFiles = Files.walk(Paths.get(“Java Projects”));

listOfFiles.forEach(line -> {

executor.execute(new FileThread(line.getFileName().toString())); //

line n1

});

executor.shutdown();

executor.awaitTermination(5, TimeUnit.DAYS);//

line n2

}

}

The Java Projects directory exists and contains a list of files.

What is the result?

Options:

A.

The program throws a runtime exception at line n2.

B.

The program prints files names concurrently.

C.

The program prints files names sequentially.

D.

A compilation error occurs at line n1.

Buy Now
Questions 5

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

Buy Now
Questions 6

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 7

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

Buy Now
Questions 8

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.

Buy Now
Questions 9

Given:

Book.java:

public class Book {

private String read(String bname) { return “Read” + bname }

}

EBook.java:

public class EBook extends Book {

public class String read (String url) { return “View” + url }

}

Test.java:

public class Test {

public static void main (String[] args) {

Book b1 = new Book();

b1.read(“Java Programing”);

Book b2 = new EBook();

b2.read(“http://ebook.com/ebook”);

}

}

What is the result?

Options:

A.

Read Java ProgrammingView http:/ ebook.com/ebook

B.

Read Java ProgrammingRead http:/ ebook.com/ebook

C.

The EBook.java file fails to compile.

D.

The Test.java file fails to compile.

Buy Now
Questions 10

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

Buy Now
Questions 11

Given the code fragment:

public void recDelete (String dirName) throws IOException {

File [ ] listOfFiles = new File (dirName) .listFiles();

if (listOfFiles ! = null && listOfFiles.length >0) {

for (File aFile : listOfFiles) {

if (!aFile.isDirectory ()) {

if (aFile.getName ().endsWith (“.class”))

aFile.delete ();

}

}

}

}

Assume that Projects contains subdirectories that contain .class files and is passed as an argument to the recDelete () method when it is invoked.

What is the result?

Options:

A.

The method deletes all the .class files in the Projects directory and its subdirectories.

B.

The method deletes the .class files of the Projects directory only.

C.

The method executes and does not make any changes to the Projects directory.

D.

The method throws an IOException.

Buy Now
Questions 12

Given the code fragment:

class CallerThread implements Callable {

String str;

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

public String call() throws Exception {

return str.concat(“Call”);

}

}

and

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

{

ExecutorService es = Executors.newFixedThreadPool(4); //line n1

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

String str = f1.get().toString();

System.out.println(str);

}

Which statement is true?

Options:

A.

The program prints Call Call and terminates.

B.

The program prints Call Call and does not terminate.

C.

A compilation error occurs at line n1.

D.

An ExecutionException is thrown at run time.

Buy Now
Questions 13

Given the code fragment:

What is the result?

Options:

A.

text1text2

B.

text1text2text2text3

C.

text1

D.

[text1, text2]

Buy Now
Questions 14

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 15

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 16

Given the code fragment:

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

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.

Buy Now
Questions 17

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

Buy Now
Questions 18

Given:

class FuelNotAvailException extends Exception { }

class Vehicle {

void ride() throws FuelNotAvailException {//line n1

System.out.println(“Happy Journey!”);

}

}

class SolarVehicle extends Vehicle {

public void ride () throws FuelNotAvailException {//line n2

super ride ();

}

}

and the code fragment:

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

Vehicle v = new SolarVehicle ();

v.ride();

}

Which modification enables the code fragment to print Happy Journey!?

Options:

A.

Replace line n1 with public void ride() throws FuelNotAvailException {

B.

Replace line n1 with protected void ride() throws Exception {

C.

Replace line n2 with void ride() throws Exception {

D.

Replace line n2 with private void ride() throws FuelNotAvailException {

Buy Now
Questions 19

Given the code fragment:

List nL = Arrays.asList(“Jim”, “John”, “Jeff”);

Function funVal = s -> “Hello : “.concat(s);

nL.Stream()

.map(funVal)

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

What is the result?

Options:

A.

Hello : Jim Hello : John Hello : Jeff

B.

Jim John Jeff

C.

The program prints nothing.

D.

A compilation error occurs.

Buy Now
Questions 20

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 21

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.

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 = Files.readAllLines(file);fc.stream().forEach (s -> System.out.println(s));

D.

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

Buy Now
Questions 23

Given the code fragment:

What is the result?

Options:

A.

[X][X, X][X, X, X][X, X, X, X]

B.

[X, X]

C.

[X][X, X][X, X, X]

D.

[X, X][X, X, X, X]

Buy Now
Questions 24

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

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]

Buy Now
Questions 25

Given the code fragment:

Stream files = Files.list(Paths.get(System.getProperty(“user.home”)));

files.forEach (fName -> {//line n1

try {

Path aPath = fName.toAbsolutePath();//line n2

System.out.println(fName + “:”

+ Files.readAttributes(aPath, Basic.File.Attributes.class).creationTime

());

} catch (IOException ex) {

ex.printStackTrace();

});

What is the result?

Options:

A.

All files and directories under the home directory are listed along with their attributes.

B.

A compilation error occurs at line n1.

C.

The files in the home directory are listed along with their attributes.

D.

A compilation error occurs at line n2.

Buy Now
Questions 26

Given:

interface Doable {

public void doSomething (String s);

}

Which two class definitions compile? (Choose two.)

Options:

A.

public abstract class Task implements Doable {public void doSomethingElse(String s) { }}

B.

public abstract class Work implements Doable {public abstract void doSomething(String s) { }public void doYourThing(Boolean b) { }}

C.

public class Job implements Doable {public void doSomething(Integer i) { }}

D.

public class Action implements Doable {public void doSomething(Integer i) { }public String doThis(Integer j) { }}

E.

public class Do implements Doable {public void doSomething(Integer i) { }public void doSomething(String s) { }public void doThat (String s) { }}

Buy Now
Questions 27

Given the code fragment:

ZonedDateTime depart = ZonedDateTime.of(2015, 1, 15, 1, 0, 0, 0, ZoneID.of(“UTC-7”));

ZonedDateTime arrive = ZonedDateTime.of(2015, 1, 15, 9, 0, 0, 0, ZoneID.of(“UTC-5”));

long hrs = ChronoUnit.HOURS.between(depart, arrive); //line n1

System.out.println(“Travel time is” + hrs + “hours”);

What is the result?

Options:

A.

Travel time is 4 hours

B.

Travel time is 6 hours

C.

Travel time is 8 hours

D.

An exception is thrown at line n1.

Buy Now
Questions 28

Given:

class FuelNotAvailException extends Exception { }

class Vehicle {

void ride() throws FuelNotAvailException {//line n1

System.out.println(“Happy Journey!”);

}

}

class SolarVehicle extends Vehicle {

public void ride () throws Exception {//line n2

super ride ();

}

}

and the code fragment:

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

Vehicle v = new SolarVehicle ();

v.ride();

}

Which modification enables the code fragment to print Happy Journey!?

Options:

A.

Replace line n1 with public void ride() throws FuelNotAvailException {

B.

Replace line n1 with protected void ride() throws Exception {

C.

Replace line n2 with void ride() throws Exception {

D.

Replace line n2 with private void ride() throws FuelNotAvailException {

Buy Now
Questions 29

Given the code fragment:

public class Foo {

public static void main (String [ ] args) {

Map unsortMap = new HashMap< > ( );

unsortMap.put (10, “z”);

unsortMap.put (5, “b”);

unsortMap.put (1, “d”);

unsortMap.put (7, “e”);

unsortMap.put (50, “j”);

Map treeMap = new TreeMap (new

Comparator ( ) {

@Override public int compare (Integer o1, Integer o2) {return o2.compareTo

(o2); } } );

treeMap.putAll (unsortMap);

for (Map.Entry entry : treeMap.entrySet () ) {

System.out.print (entry.getValue () + “ “);

}

}

}

What is the result?

Options:

A.

A compilation error occurs.

B.

d b e z j

C.

j z e b d

D.

z b d e j

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