1Z0-804 | 10 Tips For Most up-to-date 1Z0-804 pdf
Q41. The default file system includes a logFiles directory that contains the following files:
Log-Jan 2009
log_0l_20l0
log_Feb20l0
log_Feb2011
log_10.2012
log-sum-2012
How many files does the matcher in this fragment match?
PathMatcher matcher = FileSystems.getDefault ().getPathMatcher ("glob: *???_*1?" );
A. One
B. Two
C. Three
D. Four
E. Five
F. Six
Answer: B
Explanation:
The pattern to match is *???_*1? (regex ".*..._.*1.")
This means at least three characters before the symbol _ , followed by any amount of
characters. The next tolast character must be 1. The last character can by any character.
The following file names match this pattern:
log_Feb2011
log_10.2012 Trap !! l is not 1 !!
Q42. Given:
What is the result?
A. Compilation fails.
B. 78class java.lang.Array.IndexOutOfBoundException
C. class MarkOutOfBoundException
D. class java.lang.arrayIndexOutOfBoundException
Answer: A
Explanation:
The exception MarkOutOfBoundsException is already caught by the alternative ArrayIndexOutOfBoundsException
Q43. Given the fragment:
Which two valid alternatives to line 3 would decouple this application from a specific implementation ofCustomerDAO?
A. CustomerDAO custDao = CustomerDAO();
B. CustomerDAO custDao = (CustomerDAO) new Object ();
C. CustomerDAO custDao = CustomerDAO.getInstance();
D. CustomerDAO custDao = (CustomerDAO) new CustomerDAOmemoryImp1();
E. CustomerDAO custDao = customerDAOFactory.getInstance();
Answer: C,E
Explanation:
Note: In software development, the term"decoupling"is used to identify the separation of software blocks thatshouldn't depend on each other. Some building blocks are generic and shouldn't know details of others. Special design techniques allow software designers to have as few dependencies as possible. This typicallyreduces the risk of malfunction in one part of a system when the other part changed. It also forces thedeveloper to focus on one thing at a time. Decoupling lowers or minimizes Coupling.
Q44. Given the code fragment:
What is the result, if the file salesreport.dat does not exist?
A. Compilation fails only at line 6
B. Compilation fails only at line 13
C. Compilation fails at line 6 and 13
D. Class java.io.IOException
E. Class java.io.FileNotFoundException
Answer: B
Explanation:
Compilation fails Line 13 : The resource br of a try-with-resources statement cannot be assignedresources are final in try-with-resources statements
Q45. Assuming the port statements are correct, which two (three?) code fragments create a one-byte file?
A. OutputStream fos = new FileOutputStream(new File("/tmp/data.bin")); OutputStream bos = new BufferedOutputStream(fos); DataOutputStream dos = new DataOutputStream(bos); dos.writeByte(0); dos.close();
B. OutputStream fos = new FileOutputStream ("/tmp/data.bin");
DataOutputStream dos = new DataOutputStream(fos);
dos.writeByte(0);
dos.close();
C. OutputStream fos = new FileOutputStream (new File ("/tmp/data.bin"));
DataOutputStream dos = new DataOutputStream(fos);
dos.writeByte(0);
dos.close();
D. OutputStream fos = new FileOutputStream ("/tmp/data.bin"); fos.writeByte(0);
fos.close();
Answer: A,B,C
Explanation:
B:Create DataOutputStream from FileOutputStream public static void main(String[] args)
throws
Exception { FileOutputStream fos = new FileOutputS tream("C:/demo.txt");
DataOutputStream dos = new
DataOutputStream(fos);
Note:
The FileOutputStream class is a subclass of OutputStream. You can construct a
FileOutputStream object by
passing a string containing a path name or a File object.
You can also specify whether you want to append the output to an existing file.
public FileOutputStream (String path)
public FileOutputStream (String path, boolean append)
public FileOutputStream (File file)
public FileOutputStream (File file, boolean append)
With the first and third constructors, if a file by the specified name already exists, the file
will be overwritten. Toappend to an existing file, pass true to the second or fourth
constructor.
Note 2:public class DataOutputStreamextends FilterOutputStreamimplements DataOutput
A data output stream lets an application write primitive Java data types to an output stream
in a portable way.
An application can then use a data input stream to read the data back in.
Reference:java.io Class DataOutputStream
Q46. Which three are true?
A. A setAutoCommit (False) method invocation starts a transaction context.
B. An instance of Savepoint represents a point in the current transaction context.
C. A rollback () method invocation rolls a transaction back to the last savepoint.
D. A rollback () method invocation releases any database locks currently held by this connection object.
E. After calling rollback (mysavepoint), you must close the savepoint object by calling mySavepoint.close() .
Answer: A,B,C
Explanation:
A:The way to allow two or more statements to be grouped into a transaction is to disable the auto-commitmode. After the auto-commit mode is disabled, no SQL statements are committed until you call the methodcommit explicitly. All statements executed after the previous call to the method commit are included in thecurrent transaction and committed together as a unit. Note:When a connection is created, it is in auto-commit mode. This means that each individual SQL statementis treated as a transaction and is automatically committed right after it is executed. (To be more precise, thedefault is for a SQL statement to be committed when it is completed, not when it is executed. A statement iscompleted when all of its result sets and update counts have been retrieved. In almost all cases, however, astatement is completed, and therefore committed, right after it is executed.)
B:The method Connection.setSavepoint, sets a Savepoint object within the current transaction. The Connection.rollback method is overloaded to take a Savepoint argument. When a transaction is rolled back toa savepoint all changes made after that savepoint are undone.
C: calling the method rollback terminates a transaction and returns any values that were modified to theirprevious values. If you are trying to execute one or more statements in a transaction and get a SQLException, call the method rollback to end the transaction and start the transaction all over again.
Q47. Given:
Which two are true?
A. Thread is printed
B. Runnable is printed
C. No output is produced
D. No new threads of execution are started within the main method
E. One new thread of execution is started within the main method
F. Two new threads of exclusion are started within the main method
Answer: C,D
Q48. Which two demonstrate the valid usage of the keyword synchronized?
A. interface ThreadSafe {
synchronized void doIt();
}
B. abstract class ThreadSafe {
synchronized abstract void doIt();
}
C. class ThreadSafe {
synchronized static void soIt () {}
}
D. enum ThreadSafe {
ONE, TWO, Three;
synchronized final void doIt () {}
}
Answer: C
Explanation:
The Java programming language provides two basic synchronization idioms:
synchronized methods and synchronized statements.
To make a method synchronized, simply add the synchronized keyword to its declaration.
Q49. Given:
What is the result?
A. John Adams George Washington Thomas Jefferson
B. George Washington John Adams Thomas Jefferson
C. Thomas Jefferson John Adams George Washington
D. An exception is thrown at runtime
E. Compilation fails
Answer: B
Explanation: The program compiles and runs fine.
At runtime the NameList is built and then sorted by natural Order (String >> alphabetically).
Q50. Which two are valid initialization statements?
A. Map<String, String> m = new SortedMap<String, String>();
B. Collection m = new TreeMap<Object, Object>();
C. HashMap<Object, Object> m = new SortedMap<Object, Object>();
D. SortedMap<Object, Object> m = new TreeMap<Object, Object> ();
E. Hashtable m= new HashMap();
F. Map<List, ArrayList> m = new Hashtable<List, ArrayList>();
Answer: D,F