1Z0-809 Premium Bundle

1Z0-809 Premium Bundle

Java SE 8 Programmer II Certification Exam

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

Oracle 1Z0-809 Free Practice Questions

Q1. Which statement is true about the DriverManager class? 

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. 

Answer:

Explanation: The DriverManager returns an instance of Doctrine\DBAL\Connection which is a wrapper around the underlying driver connection (which is often a PDO instance). Reference: http://doctrine-dbal.readthedocs.org/en/latest/reference/configuration.html 

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

Answer:

Q3. Given: 

What is the result? 

A. 10 : 22 : 20 

B. 10 : 22 : 22 

C. 10 : 22 : 6 

D. 10 : 30 : 6 

Answer:

Q4. Given: What is the result? 

A. Initialized Started 

B. Initialized Started Initialized 

C. Compilation fails 

D. An exception is thrown at runtime 

Answer:

Q5. Given the code fragment: 

List<Integer> list1 = Arrays.asList(10, 20); 

List<Integer> list2 = Arrays.asList(15, 30); 

//line n1 

Which code fragment, when inserted at line n1, prints 10 20 15 30? 

A. Stream.of(list1, list2) 

.flatMap(list -> list.stream()) 

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

B. Stream.of(list1, list2) 

.flatMap(list -> list.intStream()) 

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

C. list1.stream() 

.flatMap(list2.stream().flatMap(e1 -> e1.stream()) 

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

D. Stream.of(list1, list2) 

.flatMapToInt(list -> list.stream()) 

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

Answer:

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

Answer:

Q7. Given the code fragments: 

class Caller implements Callable<String> { 

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? 

A. The program prints: 

Run Runner 

Call Caller : null 

And the program does not terminate. 

B. The program terminates after printing: 

Run Runner 

Call Caller : Run 

C. A compilation error occurs at line n1. 

D. An Execution is thrown at run time. 

Answer:

Q8. Given the class definitions: 

And the code fragment of the main() method, 

What is the result? 

A. Java Java Java 

B. Java Jeve va 

C. Java Jeve ve 

D. Compilation fails 

Answer:

Q9. Given the definition of the Country class: 

public class country { 

public enum Continent {ASIA, EUROPE} 

String name; 

Continent region; 

public Country (String na, Continent reg) { 

name = na, region = reg; 

public String getName () {return name;} 

public Continent getRegion () {return region;} 

and the code fragment: 

List<Country> couList = Arrays.asList ( 

new Country (“Japan”, Country.Continent.ASIA), 

new Country (“Italy”, Country.Continent.EUROPE), 

new Country (“Germany”, Country.Continent.EUROPE)); Map<Country.Continent, List<String>> regionNames = couList.stream () .collect(Collectors.groupingBy (Country ::getRegion, Collectors.mapping(Country::getName, Collectors.toList())))); System.out.println(regionNames); 

What is the output? 

A. {EUROPE = [Italy, Germany], ASIA = [Japan]} 

B. {ASIA = [Japan], EUROPE = [Italy, Germany]} 

C. {EUROPE = [Germany, Italy], ASIA = [Japan]} 

D. {EUROPE = [Germany], EUROPE = [Italy], ASIA = [Japan]} 

Answer:

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

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. 

Answer:

Q11. Which two statements are true for a two-dimensional array of primitive data type? 

A. It cannot contain elements of different types. 

B. The length of each dimension must be the same. 

C. At the declaration time, the number of elements of the array in each dimension must be specified. 

D. All methods of the class object may be invoked on the two-dimensional array. 

Answer: C,D 

Explanation: http://stackoverflow.com/questions/12806739/is-an-array-a-primitive-type-or-an-object-or-something-else-entirely 

Q12. Given the code fragment: What is the result? 

A. 20 

B. 25 

C. 29 

D. Compilation fails 

E. AnArrayIndexOutOfBoundsException is thrown at runtime 

Answer:

Q13. Given: 

What is the result? 

A. Good Day! Good Luck! 

B. Good Day! Good Day! 

C. Good Luck! Good Day! 

D. Good Luck! Good Luck! 

E. Compilation fails 

Answer:

Q14. Given: 

final class Folder {//line n1 //line n2 public void open () { System.out.print(“Open”); } } public class Test { public static void main (String [] args) throws Exception { try (Folder f = new Folder()) { f.open(); } } } Which two modifications enable the code to print Open Close? 

A. Replace line n1 with: 

class Folder implements AutoCloseable { 

B. Replace line n1 with: 

class Folder extends Closeable { 

C. Replace line n1 with: 

class Folder extends Exception { 

D. At line n2, insert: 

final void close () { 

System.out.print(“Close”); 

E. At line n2, insert: 

public void close () throws IOException { 

System.out.print(“Close”); 

Answer: A,C 

Q15. public class ForTest { 

public static void main(String[] args) { 

int[] arrar = {1,2,3}; 

for ( foo ) { 

Which three are valid replacements for foo so that the program will compiled and run? 

A. int i: array 

B. int i = 0; i < 1; i++ 

C. ;; 

D. ; i < 1; i++ 

E. ; i < 1; 

Answer: A,B,C 

START 1Z0-809 EXAM