1Z0-805 | 10 Tips For Regenerate 1Z0-805 braindumps


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

A. The code prints error. 

B. The code prints the employee ID. 

C. Compilation fails due to an error at line 13. 

D. Compilation fails due to an error at line 14. 

Answer:

Explanation: Assuming that the connection conn has been set up fine, the code will compile and run fine. 

Note #1: The GetInt method retrieves the value of the designated column in the current row of this ResultSet object as an int in the Java programming language. 

Note 2: A table of data representing a database result set, which is usually generated by executing a statement that queries the database. 

A ResultSet object maintains a cursor pointing to its current row of data. Initially the cursor is positioned before the first row. The next method moves the cursor to the next row, and because it returns false when there are no more rows in the ResultSet object, it can be used in a while loop to iterate through the result set. 

A default ResultSet object is not updatable and has a cursor that moves forward only. Thus, you can iterate through it only once and only from the first row to the last row. It is possible to produce ResultSet objects that are scrollable and/or updatable. 

Reference: The Java Tutorials, Interface ResultSet 

Q2. Given: 

Which design pattern moves the getPerson, createPerson, deletePerson, and updatePerson methods to a new class? 

A. Singleton 

B. DAO 

C. Factory 

D. Composition 

Answer:

Explanation: We move the most abstract highest level methods into a separate class. 

Note: 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) 

Q3. Given the code fragment: 

/* method declaration */ { 

try { 

String className = "java.lang.String"; 

String fieldname = "somefield"; 

Class c = Class.forName(className); 

Field f = c.getField(fieldname); 

} catch(Exception e) { 

e.printStackTrace(); 

throw e; 

Which two method declarations are valid options to replace /* method declaration */? 

A. public void getMetadata () 

B. public void getMetadat () 

C. public void getMetadata () throws Exception 

D. public void getMetadata () throws NoSuchFieldException 

E. public void getMetadata () throws classNotFoundException 

F. public void getMetadata () throws ClassNotFoundException, NoSuchFieldException. 

Answer: C,F 

Explanation: We must specify that the getMetaData method can throw both ClassNotFoundException (line Class c = Class.forName(className);) and a NoSuchFieldException (line Field f = c.getField(fieldname);). We can do this by either declare that all exception can be thrown or that these two specific exceptions can be thrown 

Note: Valid Java programming language code must honor the Catch or Specify Requirement. This means that code that might throw certain exceptions must be enclosed by either of the following: 

* A try statement that catches the exception. The try must provide a handler for the exception. 

* A method that specifies that it can throw the exception. The method must provide a throws clause that lists the exception. 

Code that fails to honor the Catch or Specify Requirement will not compile. 

Reference: The Java Tutorials, The Catch or Specify Requirement 

Q4. Which is true regarding the java.nio.file.Path Interface? 

A. The interface extends WatchService interface 

B. Implementations of this interface are immutable. 

C. Implementations of this interface are not safe for use by multiple concurrent threads. 

D. Paths associated with the default provider are not interoperable with the java.io.File class. 

Answer:

Explanation: The java.nio.file.Path interface extends Watchable interface so that a directory located by a path can be registered with a WatchService and entries in the directory watched. 

Note: An object that may be used to locate a file in a file system. It will typically represent a system dependent file path. A Path represents a path that is hierarchical and composed of a sequence of directory and file name elements separated by a special separator or delimiter. A root component, that identifies a file system hierarchy, may also be present. The name element that is farthest from the root of the directory hierarchy is the name of a file or directory. The other name elements are directory names. A Path can represent a root, a root and a sequence of names, or simply one or more name elements. A Path is considered to be an empty path if it consists solely of one name element that is empty. Accessing a file using an empty path is equivalent to accessing the default directory of the file system. Path defines the getFileName, getParent, getRoot, and subpath methods to access the path components or a subsequence of its name elements. 

Reference: java.nio.file.Path Interface 

Q5. How many Threads are created when passing tasks to an Executor Instance? 

A. A new Thread is used for each task. 

B. A number of Threads equal to the number of CPUs is used to execute tasks. 

C. A single Thread is used to execute all tasks. 

D. A developer-defined number of Threads Is used to execute tasks. 

E. A number of Threads determined by system load is used to execute tasks. 

F. The method used to obtain the Executor determines how many Threads are used to execute tasks. 

Answer:

Explanation: A simple way to create an executor that uses a fixed thread pool is to invoke the newFixedThreadPool factory method in java.util.concurrent.Executors This class also provides the following factory methods: 

* The newCachedThreadPool method creates an executor with an expandable thread pool. This executor is suitable for applications that launch many short-lived tasks. 

* The newSingleThreadExecutor method creates an executor that executes a single task at a time. 

* Several factory methods are ScheduledExecutorService versions of the above executors. 

If none of the executors provided by the above factory methods meet your needs, constructing instances of java.util.concurrent.ThreadPoolExecutor or java.util.concurrent.ScheduledThreadPoolExecutor will give you additional options. 

Note: The Executor interface provides a single method, execute, designed to be a drop-in replacement for a common thread-creation idiom. If r is a Runnable object, and e is an Executor object you can replace (new Thread(r)).start(); with e.execute(r); However, the definition of execute is less specific. The low-level idiom creates a new thread and launches it immediately. Depending on the Executor implementation, execute may do the same thing, but is more likely to use an existing worker thread to run r, or to place r in a queue to wait for a worker thread to become available. 

Reference: The Java Tutorials, Thread Pools 

Reference: The Java Tutorials, Executor Interfaces 

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

A. public static void setFileContent (String[] s) throws IOException { 

path p=paths.get("payroll\salary.dat"); 

File file=p.toAbsolutePath().toFile(); 

try (BufferWriter br = new BufferWriter (new FileWriter(File))) { 

br.write (“experience new features of java”); 

B. public static void setFileContent (String[] s) throws IOException { 

path p=paths.get ("payroll\salary.dat"); 

File file=p.toAbsolutePath(LinkOption.NOFOLLOW_LINKS).toFile(); 

try (BufferWriter br = new BufferWriter (new FileWriter(File))) { 

br.write (“experience new features of java”); 

C. public static void setFileContent (String[] s) throws IOException { 

File file= new file ("payroll\salary.dat").getCanonicalFile(); 

try (BufferWriter br = new BufferWriter (new FileWriter(File))) { 

br.write (“experience new features of java”); 

D. public static void setFileContent (String[] s) throws IOException { 

File file= new File ("payroll\salary.dat").getCanonicalFile(); 

try (BufferWriter br = new BufferWriter (new FileWriter(File))) { 

br.write (“experience new features of java”); 

E. public static void setFileContent (String[] s) throws IOException { 

File file=new File ("payroll\salary.dat").getAbsolutePath(); 

try (BufferWriter br = new BufferWriter (new FileWriter(File))) { 

br.write (“experience new features of java”); 

} } 

Answer: B,D 

Explanation: The problem in this scenario is how to construct a system-dependent filename from the string "payroll\salary.dat". 

Regarding File-paths: 

1- A file can have many relative paths.2- Canonical paths are absolute paths.3- An absolute path is not necessarily a canonical path! This holds trueespecially under Unix, which support symbolic links. Under Windows, anabsolute path is usually a canonical path. 

B: The absolute path can include symbolic links. Here we ignore them with NOFOLLOW_LINKS option. 

D: The File.getCanonicalFile Method creates a new instance of a File object representing the file located at the absolute path of the current File object. All '.' and '..' references will be resolved. 

Q7. The two methods of course rescue that aggregate the features located in multiple classes are __________. 

A. Inheritance 

B. Copy and Paste 

C. Composition 

D. Refactoring 

E. Virtual Method Invocation 

Answer: C,E 

Explanation: C: Composition is a special case of aggregation. In a more specific manner, a restricted aggregation is called composition. When an object contains the other object, if the contained object cannot exist without the existence of container object, then it is called composition. 

E: In object-oriented programming, a virtual function or virtual method is a function or method whose behaviour can be overridden within an inheriting class by a function with the same signature. This concept is a very important part of the polymorphism portion of object-oriented programming (OOP). The concept of the virtual function solves the following problem: In OOP when a derived class inherits a base class, an object of the derived class may be referred to (or cast) as either being the base class type or the derived class type. If there are base class methods overridden by the derived class, the method call behaviour is ambiguous. The distinction between virtual and non-virtual resolves this ambiguity. If the function in question is designated virtual in the base class then the derived class' function would be called (if it exists). If it is not virtual, the base class' function would be called. Virtual functions overcome the problems with the type-field solution by allowing the programmer to declare functions in a base class that can be redefined in each derived class. 

Note: Aggregation is a special case of association. A directional association between objects. When an object ‘has-a’ another object, then you have got an aggregation between them. Direction between them specified which object contains the other object. Aggregation is also called a “Has-a” relationship. 

Q8. Which two statements are true? 

A. Implementing a DAO often includes the use of factory. 

B. To be implemented properly, factories rely on the private keyword. 

C. Factories are an example of the OO principle "program to an interface." 

D. Using factory prevents your replication from being tightly coupled with a specific Singleton 

E. One step in implementing a factory is to add references from all the classes that the factory will merge. 

Answer: A,C 

Explanation: A: The DAO design pattern completely hides the data access implementation from its clients. The interfaces given to client does not changes when the underlying data source mechanism changes. this is the capability which allows the DAO to adopt different access scheme without affecting to business logic or its clients. generally it acts as a adapter between its components and database. The DAO design pattern consists of some factory classes, DAO interfaces and some DAO classes to implement those interfaces. 

C: The essence of the Factory method Pattern is to "Define an interface for creating an object, but let the classes which implement the interface decide which class to instantiate. The Factory method lets a class defer instantiation to subclasses." 

Note: The factory method pattern is an object-oriented design pattern to implement the concept of factories. Like other creational patterns, it deals with the problem of creating objects (products) without specifying the exact class of object that will be created. The creation of an object often requires complex processes not appropriate to include within a composing object. The object's creation may lead to a significant duplication of code, may require information not accessible to the composing object, may not provide a sufficient level of abstraction, or may otherwise not be part of the composing object's concerns. The factory method design pattern handles these problems by defining a separate method for creating the objects, whichsubclasses can then override to specify the derived type of product that will be created. Some of the processes required in the creation of an object include determining which object to create, managing the lifetime of the object, and managing specialized build-up and tear-down concerns of the object. 

Q9. Which two file attribute views support reading or updating the owner of a file? 

A. AclFileAttributeView 

B. DosFileAttributeView 

C. FileOwnerAttributeView 

D. FileStoreAttributeView 

E. BasicFileAttributeView 

Answer: A,C 

Explanation: A: The AclFileAttributeView is a file attribute view that supports reading or updating a file's Access Control Lists (ACL) or file owner attributes. 

C: The FileOwnerAttributeView.setOwner(UserPrincipal owner) method updates the file owner. 

Reference: Interface AclFileAttributeView, Interface FileOwnerAttributeView 

Q10. Given the code fragment: 

SimpleDateFormat sdf; 

Which code fragment displays the three-character month abbreviation? 

A. sdf = new SimpleDateFormat ("mm", Locale.UK); System.out.println ("Result: " + sdf.format(new Date())); 

B. sdf = new SimpleDateFormat (“MM”, Locale.UK); System.out.println ("Result: " + sdf.format(new Date())); 

C. sdf = new SimpleDateFormat (“MMM”, Locale.UK); System.out.println ("Result: " + sdf.format(new Date())); 

D. sdf = new SimpleDateFormat (“MMMM”, Locale.UK); System.out.println ("Result: " + sdf.format(new Date())); 

Answer:

Explanation: C: Output example: Apr 

Note: SimpleDateFormat is a concrete class for formatting and parsing dates in a locale-sensitive manner. It allows for formatting (date -> text), parsing (text -> date), and normalization. SimpleDateFormat allows you to start by choosing any user-defined patterns for date-time formatting. However, you are encouraged to create a date-time formatter with either getTimeInstance, getDateInstance, orgetDateTimeInstance in DateFormat. Each of these class methods can return a date/time formatter initialized with a default format pattern. You may modify the format pattern using the applyPattern methods as desired.