1Z0-804 - Java SE 7 Programmer II Exam

Go back to Oracle

Exam FAQ

How many questions are there on the 1Z0-804 exam? How long is the 1Z0-804 exam? How much does the 1Z0-804 exam cost? What is the best way to study for the 1Z0-804 exam?

Example Questions

Given: interface Rideable { String ride() ; } class Horse implements Rideable { String ride() { return "cantering "; } } class Icelandic extends Horse { String ride() { return "tolting "; } } class Test { public static void main(String[] args) { Rideable r1 = new Icelandic(); Rideable r2 = new Horse(); Horse h1 = new Icelandic(); System.out.println(r1.ride() + r2.ride() + h1.ride()); } } What is the result? Given the Greetings.properties file, containing: HELLO_MSG = Hello, everyone! GOODBYE_MSG = Goodbye everyone! And given: import java.util.Enumeration; import java.util.Locale; import java.util.ResourceBundle; public class ResourceApp { public void loadResourceBundle() { ResourceBundle resource = ResourceBundle.getBundle("Greetings", Locale.US); System.out.println(resource.getObject(1)); } public static void main(String[] args) { new ResourcesApp().loadResourceBundle(); } } What is the result? Which statement creates a low overhead, low-contention random number generator that is isolated to thread to generate a random number between 1 and 100? The two methods of code reuse that aggregate the features located in multiple classes are ____________ . Given: class Plant { abstract String growthDirection(); } class Embryophyta extends Plant { String growthDirection() { return "Up " } } public class Garden { public static void main(String[] args) { Embryophyta e = new Embryophyta(); Embryophyta c = new Carrot(); System.out.print(e.growthDirection() + growthDirection()); } } What is the result? Given: public class Counter { public static int getCount(String[] arr) { int count =0 ; for(String var:arr) { if(var!=null) count++; } return count; } public static void main(String[] args) { String[] arr =new String[4]; arr[1] = "C"; arr[2] = ""; arr[3] = "Java"; assert (getCount(arr) < arr.length); System.out.print(getCount(arr)); } } And the commands: javac Counter.java java ­ea Counter What is the result? Given: class Erupt implements Runnable { public void run() { System.out.print(Thread.currentThread().getName()); } } public class Yellowstone { static Erupt e = Erupt(); Yellowstone() { new Thread(e, "const").start(); } // line A public static void main(String[] args) { new Yellowstone(); new Faithful().go(); } static class Faithful { void go() { new Thread(e, "inner").start(); } // line B } } What is the result? Give: Class Employee { public int checkEmail() {/* . . . */} public void sendEmail (String email) {/* . . . */} public Boolean validDateEmail(){/* . . . */} public void printLetter (String letter) {/* . . . */} } Which is correct? Which three are true? Given: import java.util.*; public class SearchText { public static void main(String[] args) { Object[] array1 = new Object[3]; array1[0] = "foo"; array1[0] = 1; array1[0] = 'a'; int index = Arrays.binarySearch(array1, "bar"); System.out.println(index); } } What is the result? Which method would you supply to a class implementing the Callable interface? Given that myfile.txt contains: First Second Third Given the following code fragment: public class ReadFile02 { public static void main(String[] args) { String fileName1 = "myfile.txt"; String fileName2 = "newfile.txt"; try (BufferedReader buffIn = new BufferedReader(new FileReader(fileName1)); BufferedWriter buffOut = new BufferedWriter(new FileWriter(fileName2)) ) { String line = ""; int count = 1; line = buffIn.readLine(); while (line != null) { buffOut.write(count + ": " + line); buffOut.newLine(); count++; line = buffIn.readLine(); } } catch (IOException e) { System.out.println("Exception: " + e.getMessage()); } } } What is the result? Assuming the port statements are correct, which two code fragments create a one-byte file? When using the default file system provider with a JVM running on a DOS-based file system, which statement is true? Given: class Product { private int id; public Product (int id) { this.id = id; } public int hashCode() { return id + 42; } public boolean equals (Object obj) { return (this == obj) ? true : super.equals(obj); } } public class WareHouse { public static void main(String[] args) { Product p1 = new Product(10); Product p2 = new Product(10); Product p3 = new Product(20); System.out.print(p1.equals(p2) + " "); System.out.print(p1.equals(p3) ); } } What is the result? Give: public class Test { public static void main(String[] args) { String svar= "sports cars"; svar.replace(svar,"convertibles"); System.out.printf("There are %3$s %2$s and %d trucks.",5,svar,2+7); } } What is the result? Given the interface: Public interface Idgenerator { int getNextId(); } Which class implements IdGenerator in a thread-safe manner, so that no threads can get a duplicate id value current access? Given: import java.util.concurrent.atomic.AtomicInteger; public class AtomicCounter { private AtomicInteger c = new AtomicInteger(0); public void increment() { // insert code here } } Which line of code, inserted inside the increment () method, will increment the value of c? Given the code fragment: public class ReadFile01 { public static void main(String[] args) { String fileName = "myfile.txt"; try (BufferedReader buffIn = // Line 4 new BufferedReader(new FileReader(fileName))) { String line = ""; int count = 1; line = buffIn.readLine(); // Line 7 do { line = buffIn.readLine(); System.out.println(count + ": " + line); } while (line != null); } catch (IOException | FileNotFoundException e) { System.out.println("Exception: " + e); } } } What is the result, if the file myfile.txt does not exist? Given the code fragment: public void ReadFile (String source) { char[] c = new char [128]; int cLen = c.length; try (FileReader fr = new FileReader (source)) { int count = 0; int read = 0; while ((read = fr.read(c)) != -1) { count += read; } System.out.println("Read: " + count + " characters."); } catch (IOException i) { } What change should you make to this code to read and write strings instead of character arrays? Given the code fragment: try { String query = "SELECT * FROM Employee WHERE ID=110"; Statement stmt = conn.createStatement() ; ResultSet rs = stmt.executeQuery(query) ; // Line 13 System.out.println("Employee ID: " + rs.getInt("ID")); // Line 14 } catch (Exception se) { System.out.println("Error"); } Assume that the SQL query matches one record. What is the result of compiling and executing this code? Given: Deque <String> myDeque = new ArrayDeque<String>(); myDeque.push("one"); myDeque.push("two"); myDeque.push("three"); System.out.println(myDeque.pop()); What is the result? Given: public class StringSplit01 { public static void main(String[] args) { String names = "John-.-George-.-Paul-.-Ringo"; String[] results = names.split("-.."); for(String str:results) { System.out.println(str); } } } What is the result? Given: ConcurrentMap <String, String> PartList = new ConcurrentMap<>(); Which fragment puts a key/value pair in partList without the responsibility of overwriting an existing key? Given: public class Print01 { public static void main(String[] args) { double price = 24.99; int quantity = 2; String color = "Blue"; // insert code here. Line *** } } Which two statements, inserted independently at line ***, enable the program to produce the following output: We have 002 Blue pants that cost $24.99. Given the following code fragment: public static void main(String[] args) { Connection conn = null; Deque<String> myDeque = new ArrayDeque<>(); myDeque.add("one"); myDeque.add("two"); myDeque.add("three"); System.out.println(myDeque.remove()); } What is the result? Given: interface Rideable { String ride() ; } class Horse implements Rideable { String ride() { return "cantering "; } } class Icelandic extends Horse { String ride() { return "tolting "; } } public class Test1 { public static void main(String[] args) { Rideable r1 = new Icelandic(); Rideable r2 = new Horse(); Horse h1 = new Icelandic(); System.out.println(r1.ride() + r2.ride() + h1.ride()); } } What is the result? Given three resources bundles with these values set for menu1: (the default resource bundle in US English.) English US Resource Bundle Menu1 = small French Resource Bundle Menu1 = petit Chinese Resource Bundle Menu1 = And given the code fragment: Locale.setDefault(new Locale("es", "ES")); // Set default to Spanish and Spain Locale loc1 = Locale.getDefault(); ResourceBundle message = ResourceBundle.getBundle("MessageBundle", loc1); System.out.println(message.getString("menu1")); What is the result? Given: interface Event { String getCategory(); } public class CueSports { public String getCategory() { return "Cue sports"; } } public class Snooker extends CueSports implements Event { // Line 9 public static void main(String[] args) { Event obj1 = new Snooker(); // Line 11 CueSports obj2 = new Snooker(); // Line 12 System.out.print(obj1.GetCategory() + ", " + obj2.getCategory()); //Line 13 } } What is the result? Given the code fragment: public class Test { public static void main(String[] args) { Path dir = Paths.get("D:\\company"); //insert code here. Line *** for (Path entry: stream) { System.out.println(entry.getFileName()); } catch (IOException e) { System.err.println("Caught IOException: " + e.getMessage()); } } Which two try statements, when inserted at line ***, enable you to print files with the extensions.java, .htm, and .jar. Given the code fragment: try { String query = "SELECT * FROM Employee WHERE ID=110"; Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery(query); System.out.println("Employee ID: " + rs.getInt("ID")); } catch (Exception se) { System.out.println("Error"); } Assume that the SQL query matches one record. What is the result of compiling and executing this code? Given two classes in separate files: package a.b; / / import statement public class parent child c = new child(); package a.b.c; public class child{ } Which two import statements can make the a.b.parent class compliable? What are two differences between Callable and Runnable? Given that myFile.txt contains: First Second Third And given: import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; public class ReadFile04 { public static void main(String[] args) { try (BufferedReader buffIn = new BufferedReader(new FileReader("D:\\faculty\\myfile.txt"))) { String line = ""; int count = 1; buffIn.mark(1); line = buffIn.readLine(); System.out.println(count + ": " + line); line = buffIn.readLine(); count++; System.out.println(count + ": " + line); buffIn.reset(); line = buffIn.readLine(); count++; System.out.println(count + ": " + line); } catch (IOException e) { System.out.println("IOException"); } } } What is the result? Which concept allows generic collections to interoperate with java code that defines collections that use raw types? Given: import java.util.concurrent.atomic.AtomicInteger; public class Incrementor { public static void main(String[] args) { AtomicInteger[] var = new AtomicInteger[5]; for (int i = 0; i < 5; i++) { var[i] = new AtomicInteger(); System.out.print(var[i] + " "); } System.out.println(); for (int i = 0; i < var.length; i++) { var[i].incrementAndGet(); if (i == 2) var[i].compareAndSet(2,4); System.out.print(var[i] + " "); } } } What is the result? Given the code fragment: class Base { public void process() throws IOException { FileReader fr = new FileReader("userguide.txt"); BufferedReader br = new BufferedReader(fr); String record; while ((record = br.readLine()) != null) { System.out.println(record); } } } class Derived extends Base { public void process() throws Exception { super.process(); System.out.println("Success"); } public static void main(String[] args) { try { new Derived().process(); } catch (Exception e) { System.err.println(e.getClass()); } } } If the file userguide.txt does not exist, what is the result? Given this code fragment: public static void main(String[] args) { try { String query = "SELECT * FROM Item"; Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery(query); ResultSetMetaData rsmd = rs.getMetaData(); // Line 14 int colCount = rsmd.getColumnCount(); while (rs.next()) { for (int i = 1; i <= colCount; i++) { System.out.print(rs.getObject(i) + " "); // Line 17 } System.out.println(); } } catch (SQLException se) { System.out.println("Error"); } Assume that the SQL query returns records. What is the result? Given: public class Test { void display(String[] arr) { try { System.out.print(arr[2]); } catch (ArrayIndexOutOfBoundsException | NullPointerException e) { e = new Exception(); throw e; } } public static void main(String[] args) throws Exception { try { String[] arr = {"Unix","Solaris",null}; new Test().display(arr); } catch(Exception e) { System.err.print(e.getClass()); } } } What is the result? Given: import java.util.regex.Matcher; import java.util.regex.Pattern; public class Test { private static String REGEX = "\\Sto\\S|\\bo\\b"; private static String INPUT = "Nice to see you,to,be fine."; private static String REPLACE =","; public static void main(String[] args) { Pattern p = Pattern.compile(REGEX); Matcher m = p.matcher(INPUT); INPUT = m.replaceAll(REPLACE); System.out.println(INPUT); } } What is the result? Given: import java.io.IOException; import java.nio.file.Path; import java.nio.file.Paths; public class Path12 { public static void main(String s[]) throws IOException { Path path = Paths.get( "\\sales\\quarter\\..\\qtrlreport.txt" ); path.relativize(Paths.get( "\\sales\\annualreport.txt") ); if(path.endsWith("annualreport.txt")) { System.out.println(true); } else { System.out.println(false); } System.out.println(path); } } What is the result? Given the code fragment: public void otherMethod() { printFile(""); } public void printFile(String file) { try (FileInputStream fis = new FileInputStream(file)) { System.out.println (fis.read()); } catch (IOException e) { Given the integer implements comparable: import java.util.*; public class SortAndSearch2 { static final Comparator<Integer> IntegerComparator = new Comparator<Integer>() { public int compare (Integer n1, Integer n2) { return n2.compareTo(n1); } }; public static void main(String args[]) { ArrayList<Integer> list = new ArrayList<>(); list.add (4); list.add (1); list.add (3); list.add (2); Collections.sort(list, null); System.out.println(Collections.binarySearch(list, 3)); Collections.sort(list,IntegerComparator); System.out.println(Collections.binarySearch(list, 3)); } } What is the result? Given the existing destination file, a source file only 1000 bytes long, and the code fragment: public void process (String source, String destination) { try (InputStream fis = new FileInputStream(source); OutputStream fos = new FileOutputStream(destination) ) { byte [] buff = new byte[2014]; int i; while ((i = fis.read(buff)) != -1) { fos.write(buff,0,i); // line *** } } catch (IOException e) { System.out.println(e.getClass()); } } What is the result? Given the code fragment: class Base { BufferedReader br; String record; public void process() throws FileNotFoundException { br = new BufferedReader(new FileReader("manual.txt")); } } public class Derived extends Base { // insert code here. Line *** public static void main(String[] args) { try { new Derived().process(); } catch (Exception e) { } } } Which code fragment inserted at line ***, enables the code to compile? Given: import java.io.IOException; import java.io.file.Path; import java.io.file.Paths; public class Path12 { public static void main(String s[]) throws IOException { Path path = Paths.get("\\sales\\quarter\\..\\qtrlreport.txt"); path.relativize(Paths.get("\\sales\\annualreport.txt")); if(path.endsWith("annualreport.txt")) { System.out.println(true); } else { System.out.println(false); } System.out.println(path); } } What is the result? Given these facts about Java classes in an application: - Class X is-a Class SuperX. - Class SuperX has-a public reference to a Class Z. - Class Y invokes public methods in Class Util. - Class X uses public variables in Class Util. Which three statements are true? Given: public class Test { Integer x; // line 2 public static void main(String[] args) { new Test().go(5); } void go(Integer i) { // line 6 System.out.print(x + ++i); // line 7 } } What is the result? Which represents part of a DAO design pattern? Which class(es) safely protects the doIt () method from concurrent thread access?

Study Guides