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

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

Questions 4

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.

Buy Now
Questions 5

Given the records from the STUDENT table:

Given the code fragment:

Assume that the URL, username, and password are valid.

What is the result?

Options:

A.

The STUDENT table is not updated and the program prints:114 : John : john@uni.com

B.

The STUDENT table is updated with the record:113 : Jannet : jannet@uni.comand the program prints:114 : John : john@uni.com

C.

The STUDENT table is updated with the record:113 : Jannet : jannet@uni.comand the program prints:113 : Jannet : jannet@uni.com

D.

A SQLException is thrown at run time.

Buy Now
Questions 6

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 7

Given:

What is the result?

Options:

A.

Bar HelloFoo Hello

B.

Bar HelloBaz Hello

C.

Baz Hello

D.

A compilation error occurs in the Daze class.

Buy Now
Questions 8

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?

Buy Now
Questions 9

Given the code fragments:

and

What is the result?

Options:

A.

FranceOptional[NotFound]

B.

Optional [France]Optional [NotFound]

C.

Optional[France]Not Found

D.

FranceNot Found

Buy Now
Questions 10

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

Buy Now
Questions 11

Given the code fragments:

4. void doStuff() throws ArithmeticException, NumberFormatException, Exception {

5. if (Math.random() >-1 throw new Exception (“Try again”);

6. }

and

24. try {

25. doStuff ( ):

26. } catch (ArithmeticException | NumberFormatException | Exception e) {

27. System.out.println (e.getMessage()); }

28. catch (Exception e) {

29. System.out.println (e.getMessage()); }

30. }

Which modification enables the code to print Try again?

Options:

A.

Comment the lines 28, 29 and 30.

B.

Replace line 26 with:} catch (Exception | ArithmeticException | NumberFormatException e) {

C.

Replace line 26 with:} catch (ArithmeticException | NumberFormatException e) {

D.

Replace line 27 with:throw e;

Buy Now
Questions 12

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.

Buy Now
Questions 13

Given:

class CheckClass {

public static int checkValue (String s1, String s2) {

return s1 length() – s2.length();

}

}

and the code fragment:

String[] strArray = new String [] {“Tiger”, “Rat”, “Cat”, “Lion”}

//line n1

for (String s : strArray) {

System.out.print (s + “ “);

}

Which code fragment should be inserted at line n1 to enable the code to print Rat Cat Lion Tiger?

Options:

A.

Arrays.sort(strArray, CheckClass : : checkValue);

B.

Arrays.sort(strArray, (CheckClass : : new) : : checkValue);

C.

Arrays.sort(strArray, (CheckClass : : new).checkValue);

D.

Arrays.sort(strArray, CheckClass : : new : : checkValue);

Buy Now
Questions 14

Given the code fragment:

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

LocalDate next15days = valentinesDay.plusDays (15);

LocalDate nextYear = next15days.plusYears(1); // line n1

System.out.println(nextYear);

What is the result?

Options:

A.

2016-03-01

B.

A DateTimeException is thrown.

C.

2016-02-29

D.

A compilation error occurs at line n1.

Buy Now
Questions 15

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]

Buy Now
Questions 16

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 17

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.getString(1));

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

17.System.out.println(“Price:“ + rs.getString(3));

18. System.out.println(Quantity:“ + rs.getString(4));

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.

Buy Now
Questions 18

Given:

public final class IceCream {

public void prepare() {}

}

public class Cake {

public final void bake(int min, int temp) {}

public void mix() {}

}

public class Shop {

private Cake c = new Cake ();

private final double discount = 0.25;

public void makeReady () { c.bake(10, 120); }

}

public class Bread extends Cake {

public void bake(int minutes, int temperature) {}

public void addToppings() {}

}

Which statement is true?

Options:

A.

A compilation error occurs in IceCream.

B.

A compilation error occurs in Cake.

C.

A compilation error occurs in Shop.

D.

A compilation error occurs in Bread

E.

All classes compile successfully.

Buy Now
Questions 19

Given the code fragment:

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

BufferedReader br = new BufferedReader (new InputStremReader (System.in));

System.out.print (“Enter GDP: “);

//line 1

}

Which code fragment, when inserted at line 1, enables the code to read the GDP from the user?

Options:

A.

int GDP = Integer.parseInt (br.readline());

B.

int GDP = br.read();

C.

int GDP = br.nextInt();

D.

int GDP = Integer.parseInt (br.next());

Buy Now
Questions 20

Which two methods from the java.util.stream.Stream interface perform a reduction operation? (Choose two.)

Options:

A.

count ()

B.

collect ()

C.

distinct ()

D.

peek ()

E.

filter ()

Buy Now
Questions 21

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 22

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.

Buy Now
Questions 23

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 24

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 25

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.

Buy Now
Questions 26

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.

Buy Now
Questions 27

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 28

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) throws 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.

Buy Now
Questions 29

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.

Buy Now
Exam Code: 1z0-809
Exam Name: Java SE 8 Programmer II
Last Update: Nov 21, 2024
Questions: 196

PDF + Testing Engine

$140

Testing Engine

$105

PDF (Q&A)

$90