1Z0-805 | Replace Oracle 1Z0-805 vce


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

A. java.io.IOException 

B. java.lang.Exception 

C. java.lang.ClassNotException 

D. java.lang.NoSuchClassException 

Answer:

Q12. Given: 

public AccountDAO getAccountDAO() { 

return new AccountJDBCDAO(); 

Which design pattern best describes the class? 

A. Singleton 

B. DAO 

C. Factory 

D. Composition 

Answer:

Explanation: Data Access Object 

Abstracts and encapsulates all access to a data source 

Manages the connection to the data source to obtain and store data 

Makes the code independent of the data sources and data vendors (e.g. plain-text, xml, 

LDAP, MySQL, Oracle, DB2) 

Q13. Which two scenarios throw FileSystemNotFoundException when the paths.get(URI) method is invoked? 

A. When preconditions on the uri parameter do not hold 

B. When the provider identified by the URI’S scheme component is not installed 

C. When a security manager is installed and it denies an unspecified permission to acess the file system. 

D. When the file system identified by the uri does not exist and cannot be created automatically 

E. When the path string cannot be converted to a Path 

Answer: B,D 

Explanation: The file system, identified by the URI, does not exist and cannot be created automatically, or the provider identified by the URI's scheme component is not installed. 

Note: This method converts the given URI to a Path object. It throws the following exceptions: 

* IllegalArgumentException - if preconditions on the uri parameter do not hold. The format of the URI is provider specific. 

* FileSystemNotFoundException - The file system, identified by the URI, does not exist and cannot be created automatically, or the provider identified by the URI's scheme component is not installed 

* SecurityException - if a security manager is installed and it denies an unspecified permission to access the file system 

Reference: java.nio.file.Paths 

Q14. Which two statements are true about the walkFileTree method of the files class? 

A. The file tree traversal is breadth-first with the given FileVisitor invoked for each file encountered. 

B. If the file is a directory, and if that directory could not be opened, the postVisitFileFailed method is invoked with the I/O exception. 

C. The maxDepth parameter’s value is the maximum number of directories to visit. 

D. By default, symbolic links are not automatically followed by the method. 

Answer: C,D 

Explanation: C: The method walkFileTree(Path start, Set<FileVisitOption> options, int maxDepth, FileVisitor<? super Path> visitor) walks a file tree. The maxDepth parameter is the maximum number of levels of directories to visit. A value of 0 means that only the starting file is visited, unless denied by the security manager. A value of MAX_VALUE may be used to indicate that all levels should be visited. The visitFile method is invoked for all files, including directories, encountered at maxDepth, unless the basic file attributes cannot be read, in which case the visitFileFailed method is invoked. 

D: You need to decide whether you want symbolic links to be followed. If you are deleting files, for example, following symbolic links might not be advisable. If you are copying a file tree, you might want to allow it. By default, walkFileTree does not follow symbolic links. 

Reference: The Java Tutorials, Walking the File Tree 

Reference: walkFileTree 

Q15. Which statement is true about the DSYNC constant defined in standardopenoptions enums? 

A. DSYNC keeps only the file content and not the metadata synchronized with the underlying storage device. 

B. DSYNC keeps the file (both content and metadata) synchronized with the underlying storage device. 

C. DSYNC keeps only the file metadata and not the file content synchronized with the underlying storage device. 

D. DSYNC keeps the file (both content and metadata) de-synchronized with copies in the und< storage device. 

Answer:

Explanation: DSYNC keeps the file content synchronized with the underlying storage device. 

Note: SYNC keeps the file (both content and metadata) synchronized with the underlying storage device. 

Note 2: These are from the java.nio.file.StandardOpenOption enum class. 

Q16. Which code fragment is required to load a JDBC 3.0 driver? 

A. DriverManager.loadDriver(“org.xyzdata.jdbc.network driver”); 

B. Class.forname (“org.xyzdata.jdbc.NetWorkDriver”); 

C. Connection con = Connection.getDriver (“jdbc:xyzdata: //localhost:3306/EmployeeDB”); 

D. Connection con = Drivermanager.getConnection (“jdbc:xyzdata: //localhost:3306/EmployeeDB”); 

Answer:

Explanation: Note that your application must manually load any JDBC drivers prior to 

version 4.0. 

The simplest way to load a driver class is to call the Class.forName() method. 

If the fully-qualified name of a class is available, it is possible to get the corresponding 

Class using the static method Class.forName(). 

Q17. The advantage of a CallableStatement over a PreparedStatement is that it: 

A. Is easier to construct 

B. Supports transactions 

C. Runs on the database 

D. Uses Java instead of native SQL 

Answer:

Explanation: A Statement is an interface that represents a SQL statement. You execute 

Statement objects, and they generate ResultSet objects, which is a table of data 

representing a database result set. 

There are three different kinds of statements: 

* Statement: Used to implement simple SQL statements with no parameters. 

* PreparedStatement: (Extends Statement.) Used for precompiling SQL statements that might contain input parameters. 

* CallableStatement: (Extends PreparedStatement.) Used to execute stored procedures that may contain both input and output parameters. 

A stored procedure is a group of SQL statements that form a logical unit and perform a particular task, and they are used to encapsulate a set of operations or queries to execute on a database server. 

Reference: The Java Tutorials: 

Executing Queries 

Using Stored Procedures 

Q18. Given the code fragment: 

public class App { 

public static void main (String [] args) { 

path path = paths.get(“C\educations\institute\student\report.txt”); 

system.out.printIn(“getName(0): %s”, path.getName(0)); 

system.out.prinIn(“subpath(0, 2): %s” path.subpath(0, 2)); 

What is the result? 

A. getName (0): C: 

subpath(0, 2): C:educationreport.txt 

B. getName (0): C: 

subpath(0, 2): educationinstitute 

C. getName(0): education 

subpath(0, 2: educationinstitutestudent 

D. getName(0): education 

subpath(0, 2): educationinstitute 

E. getName(0): report.txt 

subpath (0, 2): institutestudent 

Answer:

Explanation: The getName(int index) method returns a name element of this path as a Path object. 

The subpath(int beginIndex, int endIndex) method returns a relative Path that is a subsequence of the name elements of this path. 

Reference: java.nio.file.Path 

Q19. Given the code fragment: 

Path path1 = Paths.get("D:\sales\.\quarterly\..\report"); path1 = path1.normalize(); 

Path path2 = path1.relativize(Paths.get("d:\empdetails.dat")); path2 = path2.resolve(path1); 

System.out.println(path1); 

System.out.println(path2); 

What is the result? 

A. D: salesreport 

B. salesreport 

C. D: salesquarterly . . . report 

D. salesreport 

E. D: salesquarterly . . .report 

F. salesreportempdetails.dat 

G. D: salesreport 

H. salesreportempdetails.dat 

Answer:

Explanation: Path1 is the normalized result of D:\sales\.\quarterly\..\report namely D: salesreport. 

The normalize method removes any redundant elements, which includes any "." or 

"directory/.." occurrences. 

Consider path2. 

With the relativize line path2 is set to ../../empdetails.dat 

In this scenario the following applies to the resolve statement: Passing an absolute path to the resolve method returns the passed-in path. So Path2 will be set to Path1 in the statement path2 =path2.resolve(path1); 

Note: 

A common requirement when you are writing file I/O code is the capability to construct a path from one location in the file system to another location. You can meet this using the relativizemethod. This method constructs a path originating from the original path and ending at the location specified by the passed-in path. The new path is relative to the original path. 

You can combine paths by using the resolve method. You pass in a partial path , which is a path that does not include a root element, and that partial path is appended to the original path. 

Reference: The Java Tutorials, Path Operations 

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

A. Compilation CD stream 

B. Opened CD thrown 

C. Exception thrown 

D. Opened CD stream CD str is: lullaby 

Answer:

Explanation: In this example the compilation of line " try (CDStream cd = new CDStream()) {" will fail, as try-with-resources not applicable to variable type CDStream. 

Note: The try-with-resources statement is a try statement that declares one or more resources. A resource is an object that must be closed after the program is finished with it. The try-with-resources statement ensures that each resource is closed at the end of the statement. Any object that implements java.lang.AutoCloseable, which includes all objects which implement java.io.Closeable, can be used as a resource. 

Reference: The Java Tutorials,The try-with-resources Statement