1Z0-809 Premium Bundle

1Z0-809 Premium Bundle

Java SE 8 Programmer II Certification Exam

4.5 
(17295 ratings)
0 QuestionsPractice Tests
0 PDFPrint version
May 20, 2024Last update

Oracle 1Z0-809 Free Practice Questions

Q1. The data.doc, data.txt and data.xml files are accessible and contain text. 

Given the code fragment: 

Stream<Path> paths = Stream.of (Paths. get(“data.doc”), 

Paths. get(“data.txt”), 

Paths. get(“data.xml”)); 

paths.filter(s-> s.toString().endWith(“txt”)).forEach( 

s -> { 

try { 

Files.readAllLines(s) 

.stream() 

.forEach(System.out::println); //line n1 

} catch (IOException e) { 

System.out.println(“Exception”); 

); 

What is the result? 

A. The program prints the content of data.txt file. 

B. The program prints: 

Exception 

<<The content of the data.txt file>> 

Exception 

C. A compilation error occurs at line n1. 

D. The program prints the content of the three files. 

Answer:

Q2. Given: 

A. X XX 

B. X Y X 

C. Y Y X 

D. Y YY 

Answer:

Q3. 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<Vehicle> 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 Ford 10124 BMW 

B. 10124 BMW 10123 Ford 

C. A compilation error occurs. 

D. A ClassCastException is thrown at run time. 

Answer:

Q4. Given: 

class Sum extends RecursiveAction { //line n1 

static final int THRESHOLD_SIZE = 3; 

int stIndex, lstIndex; 

int [ ] data; 

public Sum (int [ ]data, int start, int end) { 

this.data = data; 

this stIndex = start; 

this. lstIndex = end; 

protected void compute ( ) { 

int sum = 0; 

if (lstIndex – stIndex <= THRESHOLD_SIZE) { 

for (int i = stIndex; i < lstIndex; i++) { 

sum += data [i]; 

System.out.println(sum); 

} else { 

new Sum (data, stIndex + THRESHOLD_SIZE, lstIndex).fork( ); 

new Sum (data, stIndex, 

Math.min (lstIndex, stIndex + THRESHOLD_SIZE) 

).compute (); 

and the code fragment: 

ForkJoinPool fjPool = new ForkJoinPool ( ); int data [ ] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} fjPool.invoke (new Sum (data, 0, data.length)); 

and given that the sum of all integers from 1 to 10 is 55. Which statement is true? 

A. The program prints several values that total 55. 

B. The program prints 55. 

C. A compilation error occurs at line n1. 

D. The program prints several values whose sum exceeds 55. 

Answer:

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

Test 

followed by an Exception stack trace 

B. Good day! 

followed by an Exception stack trace 

C. Good day! 

Test 

null 

D. A compilation error occurs at line n1. 

Answer:

Q6. Given the code fragment: 

ZonedDateTime depart = ZonedDateTime.of(2015, 1, 15, 3, 0, 0, 0, ZoneID.of(“UTC-7”)); ZonedDateTime arrive = ZonedDateTime.of(2015, 1, 15, 9, 0, 0, 0, ZoneID.of(“UTC-5”)); long hrs = ChronoUnit.HOURS.between(depart, arrive); //line n1 System.out.println(“Travel time is” + hrs + “hours”); 

What is the result? 

A. Travel time is 4 hours 

B. Travel time is 6 hours 

C. Travel time is 8 hours 

D. An exception is thrown at line n1. 

Answer:

Q7. You want to create a singleton class by using the Singleton design pattern. Which two statements enforce the singleton nature of the design? 

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. 

Answer: A,B 

Q8. Given: 

What is the result? 

A. The sum is 2 

B. The sum is 14 

C. The sum is 15 

D. The loop executes infinite times 

E. Compilation fails 

Answer:

Q9. 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<Product> 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 : 60 

D. 4 : 60 

2 : 30 

3 : 20 

1 : 10 

E. 

The program prints nothing. 

Answer:

Q10. Given the code fragments: 

What is the result? 

A. Super Sub Sub 

B. Contract Contract Super 

C. Compilation fails at line n1 

D. Compilation fails at line n2 

Answer:

Q11. Given: 

Book.java: 

public class Book { 

private String read(String bname) { return “Read” + bname } 

EBook.java: 

public class EBook extends Book { 

public class String read (String url) { return “View” + url } 

Test.java: 

public class Test { 

public static void main (String[] args) { 

Book b1 = new Book(); 

b1.read(“Java Programing”); 

Book b2 = new EBook(); 

b2.read(“http://ebook.com/ebook”); 

What is the result? 

A. Read Java Programming View http:/ ebook.com/ebook 

B. Read Java Programming Read http:/ ebook.com/ebook 

C. The EBook.java file fails to compile. 

D. The Test.java file fails to compile. 

Answer:

Q12. Which two are Java Exception classes? 

A. SercurityException 

B. DuplicatePathException 

C. IllegalArgumentException 

D. TooManyArgumentsException 

Answer: A,C 

Q13. Given: What is the result? 

A. 0 Done 

B. First Exception Done 

C. Second Exception 

D. Done Third Exception 

E. Third Exception 

Answer:

Q14. Given the code fragment: 

Path source = Paths.get (“/data/december/log.txt”); 

Path destination = Paths.get(“/data”); 

Files.copy (source, destination); 

and assuming that the file /data/december/log.txt is accessible and contains: 

10-Dec-2014 – Executed successfully 

What is the result? 

A. A file with the name log.txt is created in the /data directory and the content of the /data/december/log.txt file is copied to it. 

B. The program executes successfully and does NOT change the file system. 

C. A FileNotFoundException is thrown at run time. 

D. A FileAlreadyExistsException is thrown at run time. 

Answer:

Q15. Given the definition of the Vehicle class: 

class Vehicle { 

String name; 

void setName (String name) { 

this.name = name; 

String getName() { 

return name; 

Which action encapsulates the Vehicle class? 

A. Make the Vehicle class public. 

B. Make the name variable public. 

C. Make the setName method public. 

D. Make the name variable private. 

E. Make the setName method private. 

F. Make the getName method private. 

Answer:

START 1Z0-809 EXAM