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:

UnaryOperator uo1 = s -> s*2;line n1

List loanValues = Arrays.asList(1000.0, 2000.0);

loanValues.stream()

.filter(lv -> lv >= 1500)

.map(lv -> uo1.apply(lv))

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

What is the result?

Options:

A.

4000.0

B.

4000

C.

A compilation error occurs at line n1.

D.

A compilation error occurs at line n2.

Buy Now
Questions 5

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 6

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.ready()) { //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 7

Given:

and the code fragment:

What is the result?

Options:

A.

An exception is thrown at line n2.

B.

100

C.

A compilation error occurs because the try block is declared without a catch or finally block.

D.

A compilation error occurs at line n1.

Buy Now
Questions 8

Given the definition of the Emp class:

public class Emp

private String eName;

private Integer eAge;

Emp(String eN, Integer eA) {

this.eName = eN;

this.eAge = eA;

}

public Integer getEAge () {return eAge;}

public String getEName () {return eName;}

}

and code fragment:

Listli = Arrays.asList(new Emp(“Sam”, 20), New Emp(“John”, 60), New Emp(“Jim”, 51));

Predicate agVal = s -> s.getEAge() <= 60;//line n1

li = li.stream().filter(agVal).collect(Collectors.toList());

Stream names = li.stream()map.(Emp::getEName);//line n2

names.forEach(n -> System.out.print(n + “ “));

What is the result?

Options:

A.

Sam John Jim

B.

John Jim

C.

A compilation error occurs at line n1.

D.

A compilation error occurs at line n2.

Buy Now
Questions 9

Given:

class ImageScanner implements AutoCloseable {

public void close () throws Exception {

System.out.print (“Scanner closed.”);

}

public void scanImage () throws Exception {

System.out.print (“Scan.”);

throw new Exception(“Unable to scan.”);

}

}

class ImagePrinter implements AutoCloseable {

public void close () throws Exception {

System.out.print (“Printer closed.”);

}

public void printImage () {System.out.print(“Print.”); }

}

and this code fragment:

try (ImageScanner ir = new ImageScanner();

ImagePrinter iw = new ImagePrinter()) {

ir.scanImage();

iw.printImage();

} catch (Exception e) {

System.out.print(e.getMessage());

}

What is the result?

Options:

A.

Scan.Printer closed. Scanner closed. Unable to scan.

B.

Scan.Scanner closed. Unable to scan.

C.

Scan. Unable to scan.

D.

Scan. Unable to scan. Printer closed.

Buy Now
Questions 10

Given:

and

Which interface from the java.util.function package should you use to refactor the class Txt?

Options:

A.

Consumer

B.

Predicate

C.

Supplier

D.

Function

Buy Now
Questions 11

You want to create a singleton class by using the Singleton design pattern.

Which two statements enforce the singleton nature of the design? (Choose two.)

Options:

A.

Make the class static.

B.

Make the constructor private.

C.

Override equals() and hashCode() methods of the java.lang.Object class.

D.

Use a static reference to point to the single instance.

E.

Implement the Serializable interface.

Buy Now
Questions 12

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 13

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}

Buy Now
Questions 14

Given the code fragment:

List nums = Arrays.asList (10, 20, 8):

System.out.println (

//line n1

);

Which code fragment must be inserted at line n1 to enable the code to print the maximum number in the nums list?

Options:

A.

nums.stream().max(Comparator.comparing(a -> a)).get()

B.

nums.stream().max(Integer : : max).get()

C.

nums.stream().max()

D.

nums.stream().map(a -> a).max()

Buy Now
Questions 15

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 16

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

recDelete (aFile.getAbsolutePath ());

} else {

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 17

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 18

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 19

Given the code fragment:

What is the result?

Options:

A.

A compilation error occurs at line n1.

B.

Checking…

C.

Checking…Checking…

D.

A compilation error occurs at line n2.

Buy Now
Questions 20

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 21

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 –da option?

Options:

A.

-10

B.

0

C.

An AssertionError is thrown.

D.

A compilation error occurs.

Buy Now
Questions 22

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

Buy Now
Questions 23

Given the definition of the Emp class:

public class Emp

private String eName;

private Integer eAge;

Emp(String eN, Integer eA) {

this.eName = eN;

this.eAge = eA;

}

public Integer getEAge () {return eAge;}

public String getEName () {return eName;}

}

and code fragment:

Listli = Arrays.asList(new Emp(“Sam”, 20), New Emp(“John”, 60), New Emp(“Jim”, 51));

Predicate agVal = s -> s.getEAge() > 50;//line n1

li = li.stream().filter(agVal).collect(Collectors.toList());

Stream names = li.stream()map.(Emp::getEName);//line n2

names.forEach(n -> System.out.print(n + “ “));

What is the result?

Options:

A.

Sam John Jim

B.

John Jim

C.

A compilation error occurs at line n1.

D.

A compilation error occurs at line n2.

Buy Now
Questions 24

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 25

Given this code;

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.

Buy Now
Questions 26

Given the code fragment:

Map books = new TreeMap<>();

books.put (1007, “A”);

books.put (1002, “C”);

books.put (1003, “B”);

books.put (1003, “B”);

System.out.println (books);

What is the result?

Options:

A.

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

B.

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

C.

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

D.

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

Buy Now
Questions 27

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 = Arrays.asList(new Product(1, 10),

new Product (2, 30),

new Product (2, 30));

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.

2 : 30

B.

4 : 0

C.

4 : 70

D.

4 : 602 : 303 : 201 : 10

E.

The program prints nothing.

Buy Now
Questions 28

Given:

Your design requires that:

    fuelLevel of Engine must be greater than zero when the start() method is invoked.

    The code must terminate if fuelLevel of Engine is less than or equal to zero.

Which code fragment should be added at line n1 to express this invariant condition?

Options:

A.

assert (fuelLevel) : “Terminating…”;

B.

assert (fuelLevel > 0) : System.out.println (“Impossible fuel”);

C.

assert fuelLevel < 0: System.exit(0);

D.

assert fuelLevel > 0: “Impossible fuel” ;

Buy Now
Questions 29

Given the code fragments:

class ThreadRunner implements Runnable {

public void run () { System.out.print (“Runnable”) ; }

}

class ThreadCaller implements Callable {

Public String call () throws Exception {return “Callable”; )

}

and

ExecutorService es = Executors.newCachedThreadPool ();

Runnable r1 = new ThreadRunner ();

Callable c1 = new ThreadCaller ();

// line n1

es.shutdown();

Which code fragment can be inserted at line n1 to start r1 and c1 threads?

Options:

A.

Future f1 = (Future) es.submit (r1);es.execute (c1);

B.

es.execute (r1);Future f1 = es.execute (c1) ;

C.

Future f1 = (Future) es.execute(r1);Future f2 = (Future) es.execute(c1);

D.

es.submit(r1);Future f1 = es.submit (c1);

Buy Now
Questions 30

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
Questions 31

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 32

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 33

Given the code fragment:

9. Connection conn = DriveManager.getConnection(dbURL, userName, passWord);

10. String query = “SELECT id FROM Employee”;

11. try (Statement stmt = conn.createStatement()) {

12. ResultSet rs = stmt.executeQuery(query);

13.stmt.executeQuery(“SELECT id FROM Customer”);

14. while (rs.next()) {

15. //process the results

16.System.out.println(“Employee ID: “+ rs.getInt(“id”));

17.}

18. } catch (Exception e) {

19. System.out.println (“Error”);

20. }

Assume that:

The required database driver is configured in the classpath.

The appropriate database is accessible with the dbURL, userName, and passWord exists.

The Employee and Customer tables are available and each table has id column with a few records and the SQL queries are valid.

What is the result of compiling and executing this code fragment?

Options:

A.

The program prints employee IDs.

B.

The program prints customer IDs.

C.

The program prints Error.

D.

compilation fails on line 13.

Buy Now
Questions 34

Given:

and this code fragment:

What is the result?

Options:

A.

Open-Close–Exception – 1Open–Close–

B.

Open–Close–Open–Close–

C.

A compilation error occurs at line n1.

D.

Open–Close–Open–

Buy Now
Questions 35

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.

Buy Now
Questions 36

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.

Buy Now
Questions 37

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 38

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.

Buy Now
Questions 39

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.name.equals(b name))}

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 40

Given the EMPLOYEE table;

Given the code fragment:

Assuming the database supports scrolling and updating, what is the result?

Options:

A.

The program throws a runtime exception at Line 1.

B.

A compilation error occurs.

C.

A new record is inserted and Employee Id: 102, Employee Name: Peter is displayed.

D.

A new record is inserted and Employee Id: 104, Employee Name: Michael is displayed.

Buy Now
Questions 41

Given:

What is the result?

Options:

A.

–catch--finally--dostuff-

B.

–catch-

C.

–finally--catch-

D.

–finally-dostuff--catch-

Buy Now
Questions 42

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 43

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 44

Given the content:

Given the code fragment:

Which two code fragments when inserted at Line 1, independently, enables the code fragment to print "Hallo'?

Options:

A.

B.

C.

D.

E.

Buy Now
Questions 45

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

(o1); } } );

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
Questions 46

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 47

Given the code fragment:

List codes = Arrays.asList (“DOC”, “MPEG”, “JPEG”);

codes.forEach (c -> System.out.print(c + “ “));

String fmt = codes.stream()

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

.reduce((s, t) -> s + t).get();

System.out.println(“\n” + fmt);

What is the result?

Options:

A.

DOC MPEG JPEGMPEGJPEG

B.

DOC MPEG MPEGJPEGMPEGMPEGJPEG

C.

MPEGJPEGMPEGJPEG

D.

The order of the output is unpredictable.

Buy Now
Questions 48

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

Buy Now
Questions 49

Given:

interface Rideable {Car getCar (String name); }

class Car {

private String name;

public Car (String name) {

this.name = name;

}

}

Which code fragment creates an instance of Car?

Options:

A.

Car auto = Car (“MyCar”): : new;

B.

Car auto = Car : : new;Car vehicle = auto : : getCar(“MyCar”);

C.

Rideable rider = Car : : new;Car vehicle = rider.getCar(“MyCar”);

D.

Car vehicle = Rideable : : new : : getCar(“MyCar”);

Buy Now
Questions 50

Given the code fragment:

Which code fragment, when inserted at line n1, enables the code to print /First.txt?

Options:

A.

Path iP = new Paths (“/First.txt”);

B.

Path iP = Paths.toPath (“/First.txt”);

C.

Path iP = new Path (“/First.txt”);

D.

Path iP = Paths.get (“/”, “First.txt”);

Buy Now
Questions 51

Given:

Which is refactored code with functional interfaces?

Options:

A.

B.

C.

D.

Buy Now
Questions 52

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 53

and the code fragment?

What is the result?

Options:

A.

$15.00

B.

15 $

C.

USD 15.00

D.

USD $15

Buy Now
Questions 54

Given the code fragment:

List empDetails = Arrays.asList(“100, Robin, HR”, “200, Mary, AdminServices”,“101, Peter, HR”);

empDetails.stream()

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

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

101, Peter, HR200, Mary, AdminServices

D.

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

Buy Now
Questions 55

Given the records from the Employee table:

and given the code fragment:

try {

Connection conn = DriverManager.getConnection (URL, userName, passWord);

Statement st = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,

ResultSet.CONCUR_UPDATABLE);

st.execute(“SELECT*FROM Employee”);

ResultSet rs = st.getResultSet();

while (rs.next()) {

if (rs.getInt(1) ==112) {

rs.updateString(2, “Jack”);

}

}

rs.absolute(2);

System.out.println(rs.getInt(1) + “ “ + rs.getString(2));

} catch (SQLException ex) {

System.out.println(“Exception is raised”);

}

Assume that:

The required database driver is configured in the classpath.

The appropriate database accessible with the URL, userName, and passWord exists.

What is the result?

Options:

A.

The Employee table is updated with the row:112 Jackand the program prints:112 Jerry

B.

The Employee table is updated with the row:112 Jackand the program prints:112 Jack

C.

The Employee table is not updated and the program prints:112 Jerry

D.

The program prints Exception is raised.

Buy Now
Questions 56

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 57

Given the code fragment:

What is the result?

Options:

A.

Word: why what when

B.

Word: why Word: why what Word: why what when

C.

Word: why Word: what Word: when

D.

Compilation fails at line n1.

Buy Now
Questions 58

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

Buy Now
Questions 59

Which action can be used to load a database driver by using JDBC3.0?

Options:

A.

Add the driver class to the META-INF/services folder of the JAR file.

B.

Include the JDBC driver class in a jdbc.properties file.

C.

Use the java.lang.Class.forName method to load the driver class.

D.

Use the DriverManager.getDriver method to load the driver class.

Buy Now
Questions 60

Given the content of /resourses/Message.properties:

welcome1=”Good day!”

and given the code fragment:

Properties prop = new Properties ();

FileInputStream fis = new FileInputStream (“/resources/Message.properties”);

prop.load(fis);

System.out.println(prop.getProperty(“welcome1”));

System.out.println(prop.getProperty(“welcome2”, “Test”));//line n1

System.out.println(prop.getProperty(“welcome3”));

What is the result?

Options:

A.

Good day!Testfollowed by an Exception stack trace

B.

Good day!followed by an Exception stack trace

C.

Good day!Testnull

D.

A compilation error occurs at line n1.

Buy Now
Questions 61

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 62

Given:

What change should you make to guarantee a single order of execution (printed values 1 -100 in order)?

Options:

A.

Line 3: public synchronized void run() {

B.

Line 1: class MyClass extends Thread {

C.

Line 2: public volatile int value;

D.

Line 2: public synchronized int value;

Buy Now
Exam Code: 1z0-809
Exam Name: Java SE 8 Programmer II
Last Update: Aug 17, 2025
Questions: 208
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