1Z0-805 - Upgrade to Java SE 7 Programmer Exam

Go back to Oracle

Example Questions

Which statement is true about the DSYNC constant defined in standardopenoptions enums? Given: public class DAOManager { public AccountDAO getAccountDAO() { return new AccountJDBCDAO(); } } Which design pattern best describes the class? Given the code fragment: dataFormat df; Which statement defines a new DataFormat object that displays the default date format for the UK Locale? The advantage of a CallableStatement over a PreparedStatement is that it: Which two descriptions are benefits of using PreparedStatement objects over static SQL in JDBC? You have been asked to create a ResourceBundle file to localize an application. Which code example specifies valid keys of menu1 and menu2 with values of File Menu and View Menu? Given: Person public Person(int id) public int getid() public String getContactDetails() public void setContactDetails(String contactDetails) public String getName() public void setName(String name) public Person getPerson(int id) throws Exception public void createPerson(int id) throws Exception public Person deletePerson(int id) throws Exception public void updatePerson(Person p) throws Exception Which group of methods is moved to a new class when implementing the DAO pattern? What statement is true about thread starvation? Given: ConcurrentMap<String, String> partList = new ConcurrentHashMap<> (); Which fragment puts a key/value pair in partList without the possibility of overwriting an existing key? Given the code fragment: String query = "SELECT ID FROM Employee"; \\ Line 1 try (Statement stmt = conn.CreateStatement()) { \\ Line 2 ResultSet rs = stmt.executeQuery(query); \\ Line 3 stmt.executeQuery ("SELECT ID FROM Customer"); \\ Line 4 while (rs.next()) { \\process the results System.out.println ("Employee ID: " + rs.getInt("ID") ); } } catch (Exception e) { system.out.println ("Error"); } Assume that the SQL queries return records. What is the result of compiling and executing this code fragment? Given the code fragment: static void addContent () throws Exception { Path path = Paths.get("D:\\company\\report.txt"); UserPrincipal owner = path.getFileSystem().getUserPrincipalLookupService().lookupPrincipalByName("Bob"); Files.setOwner(path, owner); // insert code here ­ Line ** br.write("this is a text message "); } System.out.println("success"); } Assume that the report.txt file exists. Which try statement, when inserted at line **, enables appending the file content without writing the metadata to the underlying disk? Given a resource bundle MessageBundle, what is the name of the default bundle file? Given: private static void copyContents() { try ( InputStream fis = new FileInputStream("report1.txt"); OutputStream fos = new FileOutputStream("consolidate.txt"); ) { byte[] buf = new byte[8192]; int i; while ((i = fis.read(buf)) != -1) { fos.write(buf, 0, i); } fis.close(); fis = new FileInputStream("report2.txt"); while ((i = fis.read(buf)) != -1) { fos.write(buf, 0, i); } } What is the result? Which code fragment is required to load a JDBC 3.0 driver? Two companies with similar robots have merged. You are asked to construct a new program that allows the features of the robots to be mixed and matched using composition. Given the code fragments: public class CrusherRobot { public void walk () {} public void positionArm (int x, int y, int z) {} public void raiseHammer() {} public void dropHammer() {} } public class GripperRobot { public void walk() {} public void moveArm (int x, int y, int z) {} public void openGripper () {} public void closeGripper() {} } When applying composition to these two classes, what functionality should you extract into a new class? Which is a key aspect of composition? What design pattern does the Drivermanager.getconnection () method characterize? Given three resource bundles with these values set for menu1: ( The default resource bundle is written in US English.) English US resource Bundle Menu1 = small French resource Bundle Menu1 = petit Chinese Resource Bundle Menu = 1 And given the code fragment: Locale.setDefault (new Locale("es", "ES")); // Set default to Spanish and Spain loc1 = Locale.getDefault(); ResourceBundle messages = ResourceBundle.getBundle ("messageBundle", loc1); System.out.println (messages.getString("menu1")); What is the result? Which two code blocks correctly initialize a Locale variable? Given the code fragment: public static void main(String[] args) { Path file = Paths.get("D:\\company\\report.txt"); try (SeekableByteChannel sbc = Files.newByteChannel(file,new OpenOption[] sbc.position(5); sbc.truncate(30); } catch (IOException e) { System.err.printin("Caught IOException: " + e.getMessage () } ; } } What is the result if the report.txt file contains Welcome to the world of Java? Given the code fragment: SimpleDateFormat sdf; Which code fragment displays the three-character month abbreviation? Given this code fragment: try { String query = "SELECT * FROM Item"; Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery(query); ResultSetMetaData rsmd = rs.getMetaData(); int rowCount = rsmd.getRowCount(); System.out.println ("Processing: " + rowCount + " rows."); while (rs.next()) { // Process each row } } catch (SQLException se) { System.out.println("Error"); } Assume that the SQL query returns records. What is the result? The current working directory is named finance. Which two code fragments allow you to write the salary.dat file if it does not exist under "finance\payroll"? What are two benefits of a Factory design pattern? Given: public class DataCache { private static final DataCache instance = new DataCache (); public static DataCache getInstance () { return instance; } } Which design pattern best describes the class? Given: public class SampleClass { public static void main(String[] args) { SampleClass sc = new SampleClass(); sc.processCD(); } private void processCD() { try (CDStream cd = new CDStream()) { cd.open(); cd.read(); cd.write("lullaby"); cd.close(); } catch (Exception e) { System.out.println("Exception thrown"); } } class CDStream { String cdContents = null; public void open() { cdContents = "CD Contents"; System.out.println("Opened CD stream"); } public String read() throws Exception { throw new Exception("read error"); } public void write(String str) { System.out.println("CD str is: " + str); } public void close() { cdContents = null; } What is the result? Which two file attribute views support reading or updating the owner of a file? Given the fragment: public class CustomerApplication { public static void main (String [] args) { CustomerDAO custDao = new CustomerDAOMemoryImp1 (); // . . . other methods } } Which two valid alternatives to line 3 would decouple this application from a specific implementation of customerDAO? Given the code fragment: 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 11, enable you to print files with the extensions.java, .htm, end and .jar. Given the code fragment: List<Person> pList = new CopyOnWriteArrayList<Person>(); Which statement is true? Given the code fragment: public class TestString { public static void main(String[] args) { String str=null; switch(str) { case "": System.out.println("blank"); break; case "null": System.out.println("NULL"); break; default: System.out.println("invalid"); break; } } } What is the result? Given the code fragment: public static void processFile () throws IOException { Try (FileReader fr = new FileReader ("logfilesrc.txt"); FileWriter fw = new FileWriter ("logfilesdst.txt") ) { int i = fr.read(); } } Which statement is true? Given the following code fragment: public static void main(String[] args) { Path tempFile = null; try { Path p = Paths.get("emp"); tempFile = Files.createTempFile(p, "report", ".tmp"); try (BufferedWriter writer = Files.newBufferedWriter(tempFile, Charset.forName("UTF8")))){ writer.write("Java SE 7"); } System.out.println("Temporary file write done"); } catch(IOException e) { System.err.println("Caught IOException: " + e.getMessage()); } } What is the result? Given the code fragment: private static void copyContents (File source, File target) { try {inputStream fis = new FileInputStream(source); outputStream fos = new FileOutputStream (target); byte [] buf = new byte [8192]; int i; while ((i = fis.read(buf)) != -1) { fos.write (buf, 0, i); } //insert code fragment here. Line ** System.out.println ("Successfully copied"); } Which code fragments, when inserted independently at line **, enable the code to compile? The two methods of course rescue that aggregate the features located in multiple classes are __________. Given a language code of fr and a country code of FR, while file name represents a resource bundle file name that is not the default? Given the code fragment: Locale loc1 = Locale.getDefault (); ResourceBundle messages = ResourceBundle.getBundle("MessageBundle", loc1); Which two statements are a valid way to re-assign a resource bundle to a different Locale? Given the code fragment: SimpleDateFormat sdf = new SimpleDateFormat("zzzz", Locale.US); System.out.println ("Result: " + sdf.format(today) ) ; What type of result is printed? Which is true regarding the java.nio.file.Path Interface? What is the minimum SQL standard that a JDBC API implementation must support? Given: import java.util.*; public class StringApp { public static void main (String [] args) { Set <String> set = new TreeSet <> (); set.add("X"); set.add("Y"); set.add("X"); set.add("Y"); set.add("X"); Iterator <String> it = set.iterator (); int count = 0; while (it.hasNext()) { switch (it.next()){ case "X": System.out.print("X "); break; case "Y": System.out.print("Y "); break; } count++; } System.out.println ("\ncount = " + count); } } What is the result? Given the error message when running you application: Exception in thread "main" java.util.MissingResourceException: can't find bundle for base name messageBundle, Locale And given that the Message Bundle.properties file has been created, exists on your disk, and is properly formatted. What is the cause of the error message? Which statement is true about the take method defined in the WatchService interface? Which method or methods should you implement to create your own implementation of the java.nio.file.PathMatcher interface? Which two statements are true regarding the try with resources statement? Given the code fragment: public void processFile() throws IOException, ClassNotFoundException { try (FileReader fr = new FileReader ("logfilesrc.txt"); FileWriter fw = new FileWriter ("logfiledest.txt")) { Class c = Class.forName ("java.lang.JString"); } } If exception occur when closing the FileWriter object and when retrieving the JString class object, which exception object is thrown to the caller of the processFile method? Given the code fragment: public class Test { public static void main (String [] args) { Path path1 = Paths.get("D:\\sys\\asm\\.\\data\\..\\..\\mfg\\production.log"); System.out.println(path1.normalize()); System.out.println(path1.getNameCount()); } } What is the result? Given: public static void main(String[] args) throws Exception { try { processFile(); } catch(Exception e) { Throwable [] t = e.getSuppressed(); } } public static void processFile() throws IOException { try (FileReader fr = new FileReader"logfilesrc.txt"); FileWriter fw = new FileWriter("logfiledest.txt")) {{ java.util.zip.ZipFile zf = new java.util.zip.ZipFile("alllogs.zip"); System.out.println("Created files for logs"); } } The getSuppressed method returns an array of __________. Which two statements are true? Which statement creates a low-overhead, low contention random number generator that is isolated to a thread to generate a random number between 1 and 100?

Study Guides