1Z0-809 Premium Bundle

1Z0-809 Premium Bundle

Java SE 8 Programmer II Certification Exam

4.5 
(5775 ratings)
0 QuestionsPractice Tests
0 PDFPrint version
November 5, 2024Last update

Oracle 1Z0-809 Free Practice Questions

Q1. 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:

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

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

Q4. Which two statements are true about localizing an application? 

A. Support for new regional languages does not require recompilation of the code. 

B. Textual elements (messages and GUI labels) are hard-coded in the code. 

C. Language and region-specific programs are created using localized data. 

D. Resource bundle files include data and currency information. 

E. Language codes use lowercase letters and region codes use uppercase letters. 

Answer: A,E 

Reference: http://docs.oracle.com/javase/7/docs/technotes/guides/intl/ 

Q5. Given: 

public class Test<T> { 

private T t; 

public T get () { 

return t; 

public void set (T t) { 

this.t = t; 

public static void main (String args [ ] ) { 

Test<String> 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? 

A. Java 100 

B. java.lang.string@<hashcode>java.lang.Integer@<hashcode> 

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

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

Answer:

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

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. 

Answer: A,E 

Q7. Given the code fragments: 

interface CourseFilter extends Predicate<String> { 

public default boolean test (String str) { 

return str.equals (“Java”); 

and 

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

Predicate<String> 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? 

A. 2 

B. 3 

C. A compilation error occurs at line n1. 

D. A compilation error occurs at line n2. 

Answer:

Q8. 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:

Q9. Given the code fragment: 

List<Integer> nums = Arrays.asList (10, 20, 8): 

System.out.println ( 

//line n1 

); 

Which code fragment must be inserted at line n1 to enable the code to print the maximum number in the nums list? 

A. nums.stream().max(Comparator.comparing(a -> a)).get() 

B. nums.stream().max(Integer : : max).get() 

C. nums.stream().max() 

D. nums.stream().map(a -> a).max() 

Answer:

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

Q11. Which two items can legally be contained within a java class declaration? 

A. An import statement 

B. A field declaration 

C. A package declaration 

D. A method declaration 

Answer: B,D 

Reference: 

http://docs.oracle.com/javase/tutorial/java/javaOO/methods.html 

Q12. Given: What is the result? 

A. Marrown String out of limits JesOran 

B. Marrown String out of limits Array out of limits 

C. Marrown String out of limits 

D. Marrown NanRed JesOran 

Answer:

Q13. public class StringReplace { 

public static void main(String[] args) { 

String message = "Hi everyone!"; 

System.out.println("message = " + message.replace("e", "X")); } 

What is the result? 

A. message = Hi everyone! 

B. message = Hi XvXryonX! 

C. A compile time error is produced. 

D. A runtime error is produced. 

E. message = 

F. message = Hi Xveryone! 

Answer:

Q14. Given the code fragment: 

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

BufferedReader br = new BufferedReader (new InputStremReader (System.in)); 

System.out.print (“Enter GDP: “); 

//line 1 

Which code fragment, when inserted at line 1, enables the code to read the GDP from the user? 

A. int GDP = Integer.parseInt (br.readline()); 

B. int GDP = br.read(); 

C. int GDP = br.nextInt(); 

D. int GDP = Integer.parseInt (br.next()); 

Answer:

Q15. Given that /green.txt and /colors/yellow.txt are accessible, and the code fragment: 

Path source = Paths.get(“/green.txt); 

Path target = Paths.get(“/colors/yellow.txt); 

Files.move(source, target, StandardCopyOption.ATOMIC_MOVE); 

Files.delete(source); 

Which statement is true? 

A. The green.txt file content is replaced by the yellow.txt file content and the yellow.txt file is deleted. 

B. The yellow.txt file content is replaced by the green.txt file content and an exception is thrown. 

C. The file green.txt is moved to the /colors directory. 

D. A FileAlreadyExistsException is thrown at runtime. 

Answer:

START 1Z0-809 EXAM