Weekend Sale Limited Time 70% Discount Offer - Ends in 0d 00h 00m 00s - Coupon code: xmas50

Oracle 1z0-809 - Java SE 8 Programmer II

Page: 5 / 6
Total 196 questions

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

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?

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.

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?

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.

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

Given the code fragment:

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

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

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?

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

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?

A.

ur :: va

B.

ueJa

C.

The program prints nothing.

D.

A compilation error occurs at line n1.

Given the content of the employee.txt file:

Every worker is a master.

Given that the employee.txt file is accessible and the file allemp.txt does NOT exist, and the code fragment:

What is the result?

A.

Exception 1

B.

Exception 2

C.

The program executes, does NOT affect the system, and produces NO output.

D.

allemp.txt is created and the content of employee.txt is copied to it.

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.

Given the code fragment:

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

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