Labour Day Sale Limited Time 70% Discount Offer - Ends in 0d 00h 00m 00s - Coupon code: scxmas70

1z0-809 Exam Dumps - Java SE 8 Programmer II

Question # 4

Given the Greetings.properties file, containing:

and given:

What is the result?

A.

Compilation fails.

B.

GOODBY_MSG

C.

Hello, everyone!

D.

Goodbye everyone!

E.

HELLO_MSG

Full Access
Question # 5

Given:

Which option fails?

A.

Foo mark = new Foo (“Steve”, 100);

B.

Foo pair = Foo.twice (“Hello World!”);

C.

Foo percentage = new Foo(“Steve”, 100);

D.

Foo grade = new Foo <> (“John”, “A”);

Full Access
Question # 6

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?

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

Full Access
Question # 7

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?

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;

Full Access
Question # 8

Given the code fragment:

What is the result?

A.

Val:20 Val:40 Val:60

B.

Val:10 Val:20 Val:30

C.

A compilation error occurs.

D.

Val: Val: Val:

Full Access
Question # 9

Given the code fragments:

and

What is the result?

A.

The program prints Run… and throws an exception.

B.

A compilation error occurs at line n1.

C.

Run…Call…

D.

A compilation error occurs at line n2.

Full Access
Question # 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?

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

Full Access
Question # 11

Given the code fragment:

List 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?

A.

A compilation error occurs at line n2.

B.

200.12300.32

C.

100.12200.32

D.

A compilation error occurs at line n1.

Full Access
Question # 12

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?

A.

-10

B.

0

C.

An AssertionError is thrown.

D.

A compilation error occurs.

Full Access
Question # 13

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?

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

Full Access
Question # 14

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?

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

Full Access
Question # 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?

A.

An exception is thrown at runtime.

B.

Compilation fails.

C.

The code prints Error.

D.

The code prints information about Item 110.

Full Access
Question # 16

Given the content:

and given the code fragment:

Which two code fragments, when inserted at line 1 independently, enable the code to print “Wie geht’s?”

A.

currentLocale = new Locale (“de”, “DE”);

B.

currentLocale = new Locale.Builder ().setLanguage (“de”).setRegion (“DE”).build();

C.

currentLocale = Locale.GERMAN;

D.

currentlocale = new Locale();currentLocale.setLanguage (“de”);currentLocale.setRegion (“DE”);

E.

currentLocale = Locale.getInstance(Locale.GERMAN,Locale.GERMANY);

Full Access
Question # 17

Given:

public enum USCurrency {

PENNY (1),

NICKLE(5),

DIME (10),

QUARTER(25);

private int value;

public USCurrency(int value) {

this.value = value;

}

public int getValue() {return value;}

}

public class Coin {

public static void main (String[] args) {

USCurrency usCoin =new USCurrency.DIME;

System.out.println(usCoin.getValue()):

}

}

Which two modifications enable the given code to compile? (Choose two.)

A.

Nest the USCurrency enumeration declaration within the Coin class.

B.

Make the USCurrency enumeration constructor private.

C.

Remove the new keyword from the instantion of usCoin.

D.

Make the getter method of value as a static method.

E.

Add the final keyword in the declaration of value.

Full Access
Question # 18

Given:

and the code fragment:

Which definition of the ColorSorter class sorts the blocks list?

A.

B.

C.

D.

Full Access
Question # 19

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?

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

Full Access
Question # 20

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?

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;

Full Access
Question # 21

Given:

and the code fragment:

What is the result?

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.

Full Access
Question # 22

Given:

and the code fragment:

What is the result?

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.

Full Access
Question # 23

Given:

interface Doable {

public void doSomething (String s);

}

Which two class definitions compile? (Choose two.)

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

Full Access
Question # 24

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?

A.

2 : 30

B.

4 : 0

C.

4 : 70

D.

4 : 602 : 303 : 201 : 10

E.

The program prints nothing.

Full Access
Question # 25

Given the definition of the Vehicle class:

Class Vehhicle {

int distance;//line n1

Vehicle (int x) {

this distance = x;

}

public void increSpeed(int time) {//line n2

int timeTravel = time;//line n3

class Car {

int value = 0;

public void speed () {

value = distance /timeTravel;

System.out.println (“Velocity with new speed”+value+”kmph”);

}

}

new Car().speed();

}

}

and this code fragment:

Vehicle v = new Vehicle (100);

v.increSpeed(60);

What is the result?

A.

Velocity with new speed

B.

A compilation error occurs at line n1.

C.

A compilation error occurs at line n2.

D.

A compilation error occurs at line n3.

Full Access
Question # 26

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?

A.

10123 Ford10124 BMW

B.

10124 BMW10123 Ford

C.

A compilation error occurs.

D.

A ClassCastException is thrown at run time.

Full Access
Question # 27

Given the code fragment:

What is the result?

A.

A compilation error occurs.

B.

[Java, J2EE, J2ME, JSTL, JSP]

C.

null

D.

[Java, J2EE, J2ME, JSTL]

Full Access
Question # 28

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?

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.

Full Access
Question # 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 –da option?

A.

-10

B.

0

C.

An AssertionError is thrown.

D.

A compilation error occurs.

Full Access