New Year Special Limited Time Flat 70% Discount offer - Ends in 0d 00h 00m 00s - Coupon code: 70spcl

Oracle 1z0-809 Java SE 8 Programmer II Exam Practice Test

Page: 1 / 20
Total 196 questions

Java SE 8 Programmer II Questions and Answers

Question 1

Given the code fragment:

Question # 1

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

Question 2

Given the code fragment:

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

//line n2

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.

Question 3

Given:

public class Test {

private T t;

public T get () {

return t;

}

public void set (T t) {

this.t = t;

}

public static void main (String args [ ] ) {

Test type = new Test<>();

Test type 1 = new Test ();//line n1

type.set(“Java”);

type1.set(100);//line n2

System.out.print(type.get() + “ “ + type1.get());

}

}

What is the result?

Options:

A.

Java 100

B.

java.lang.string@java.lang.Integer@

C.

A compilation error occurs. To rectify it, replace line n1 with:Test type1 = new Test<>();

D.

A compilation error occurs. To rectify it, replace line n2 with:type1.set (Integer(100));

Question 4

Given:

public interface Moveable {

public default void walk (Integer distance) {System.out.println(“Walking”);)

public void run(Integer distance);

}

Which statement is true?

Options:

A.

Moveable can be used as below:Moveable animal = n - > System.out.println(“Running” + n);animal.run(100);animal.walk(20);

B.

Moveable can be used as below:Moveable animal = n - > n + 10;animal.run(100);animal.walk(20);

C.

Moveable can be used as below:Moveable animal = (Integer n) - > System.out.println(n);animal.run(100);Moveable.walk(20);

D.

Movable cannot be used in a lambda expression.

Question 5

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;

Question 6

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.

Question 7

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.

Question 8

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.

Question 9

Given that these files exist and are accessible:

Question # 9

and given the code fragment:

Question # 9

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

Question 10

Given:

Question # 10

Which two interfaces can you use to create lambda expressions? (Choose two.)

Options:

A.

T

B.

R

C.

P

D.

S

E.

Q

F.

U

Question 11

Which two statements are true about synchronization and locks? (Choose two.)

Options:

A.

A thread automatically acquires the intrinsic lock on a synchronized statement when executed.

B.

The intrinsic lock will be retained by a thread if return from a synchronized method is caused by an uncaught exception.

C.

A thread exclusively owns the intrinsic lock of an object between the time it acquires the lock and the time it releases it.

D.

A thread automatically acquires the intrinsic lock on a synchronized method’s object when entering that method.

E.

Threads cannot acquire intrinsic locks on classes.

Question 12

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.id = = b.id) {

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

Question 13

Given the code fragments:

Question # 13

and

Question # 13

What is the result?

Options:

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.

Question 14

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.

Question 15

Given:

public class Customer {

private String fName;

private String lName;

private static int count;

public customer (String first, String last) {fName = first, lName = last;

++count;}

static { count = 0; }

public static int getCount() {return count; }

}

public class App {

public static void main (String [] args) {

Customer c1 = new Customer(“Larry”, “Smith”);

Customer c2 = new Customer(“Pedro”, “Gonzales”);

Customer c3 = new Customer(“Penny”, “Jones”);

Customer c4 = new Customer(“Lars”, “Svenson”);

c4 = null;

c3 = c2;

System.out.println (Customer.getCount());

}

}

What is the result?

Options:

A.

0

B.

2

C.

3

D.

4

E.

5

Question 16

Given:

Question # 16

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.

Question 17

Given the records from the STUDENT table:

Question # 17

Given the code fragment:

Question # 17

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.

Question 18

Given the code fragments:

interface CourseFilter extends Predicate {

public default boolean test (String str) {

return str.equals (“Java”);

}

}

and

List strs = Arrays.asList(“Java”, “Java EE”, “Java ME”);

Predicate cf1 = s - > s.length() > 3;

Predicate cf2 = new CourseFilter() { //line n1

public boolean test (String s) {

return s.contains (“Java”);

}

};

long c = strs.stream()

.filter(cf1)

.filter(cf2//line n2

.count();

System.out.println(c);

What is the result?

Options:

A.

2

B.

3

C.

A compilation error occurs at line n1.

D.

A compilation error occurs at line n2.

Question 19

Given:

Question # 19

What is the result?

Options:

A.

Hi Interface-2

B.

A compilation error occurs.

C.

Hi Interface-1

D.

Hi MyClass

Question 20

Given:

Question # 20

and the code fragment:

Question # 20

What is the result?

Options:

A.

0

B.

A compilation error occurs at line n1.

C.

An Exception is thrown at run time.

D.

2

Question 21

Given the code fragment:

List str = Arrays.asList (“my”, “pen”, “is”, “your’, “pen”);

Predicate test = s -> {

int i = 0;

boolean result = s.contains (“pen”);

System.out.print(i++) + “:”);

return result;

};

str.stream()

.filter(test)

.findFirst()

.ifPresent(System.out ::print);

What is the result?

Options:

A.

0 : 0 : pen

B.

0 : 1 : pen

C.

0 : 0 : 0 : 0 : 0 : pen

D.

0 : 1 : 2 : 3 : 4 :

E.

A compilation error occurs.

Question 22

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

Question 23

Which two code blocks correctly initialize a Locale variable? (Choose two.)

Options:

A.

Locale loc1 = “UK”;

B.

Locale loc2 = Locale.getInstance(“ru”);

C.

Locale loc3 = Locale.getLocaleFactory(“RU”);

D.

Locale loc4 = Locale.UK;

E.

Locale loc5 = new Locale (“ru”, “RU”);

Question 24

Given:

class UserException extends Exception { }

class AgeOutOfLimitException extends UserException { }

and the code fragment:

class App {

public void doRegister(String name, int age)

throws UserException, AgeOutOfLimitException {

if (name.length () < 6) {

throw new UserException ();

} else if (age >= 60) {

throw new AgeOutOfLimitException ();

} else {

System.out.println(“User is registered.”);

}

}

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

App t = new App ();

t.doRegister(“Mathew”, 60);

}

}

What is the result?

Options:

A.

User is registered.

B.

An AgeOutOfLimitException is thrown.

C.

A UserException is thrown.

D.

A compilation error occurs in the main method.

Question 25

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.

Question 26

Given the code fragment:

Question # 26

What is the result?

Options:

A.

5 : 3 : 6

B.

6 : 5 : 6

C.

3 : 3 : 4

D.

4 : 4 : 4

Question 27

Given:

Question # 27

Which option fails?

Options:

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

Question 28

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]

Question 29

Given the code fragment:

Path path1 = Paths.get(“/app/./sys/”);

Path res1 = path1.resolve(“log”);

Path path2 = Paths.get(“/server/exe/”);

Path res1 = path1.resolve(“/readme/”);

System.out.println(res1);

System.out.println(res2);

What is the result?

Options:

A.

/app/sys/log/readme/server/exe

B.

/app/log/sys/server/exe/readme

C.

/app/./sys/log/readme

D.

/app/./sys/log/server/exe/readme

Page: 1 / 20
Total 196 questions