[Free] 2017(Aug) CollectDumps Testking Oracle 1Z0-805 Dumps with VCE and PDF 31-40

CollectDumps 2017 Aug Oracle Official New Released 1Z0-805
100% Free Download! 100% Pass Guaranteed!
http://www.CollectDumps.com/1Z0-805.html

Upgrade to Java SE 7 Programmer

Question No: 31

Given the code fragment:

public static void processFile () throws IOException { Try (FileReader fr = new FileReader (quot;logfilesrc.txtquot;); FileWriter fw = new FileWriter (quot;logfilesdst.txtquot;) ) {

int i = fr.read();

}

}

Which statement is true?

  1. The code fragment contains compilation errors.

  2. The java runtime automatically closes the FileWriter Instance first and the FileReader instance next.

  3. The java runtime automatically closes the FileReader Instance first and the FileWriter instance next.

  4. The developer needs to close the FileReader instance first and the FileWriter instance explicitly in a catch block.

  5. The Java runtime may close the FileReader and FileWriter instance in an intermediate manner. Developers should not rely on the order in which they are closed.

Answer: B

Explanation: 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 implementjava.io.Closeable, can be used as a resource.

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

Question No: 32

Given this code fragment: ResultSet rs = null;

try (Connection conn = DriverManager. getConnection (url) ) { Statement stmt = conn.createStatement();

rs stmt.executeQuery(query);

//-.. other methods }

} catch (SQLException se) { System.out.println (quot;Errorquot;);

}

Which object is valid after the try block runs?

  1. The Connection object only

  2. The Statement object only

  3. The Result set object only

  4. The Statement and Result Set object only

  5. The connection, statement, and ResultSet objects

  6. Neither the Connection, Statement, nor ResultSet objects

Answer: C

Explanation: Generally, JavaScript has just 2 levels of scope: global and function. But, try/catch is an exception (no punn intended). When an exception is thrown and the exception object gets a variable assigned to it, that object variable is only available within the quot;catchquot; section and is destroyed as soon as the catch completes.

Question No: 33

View the Exhibit:

Collectdumps 2017 PDF and VCE

Given the following code fragment:

class Finder extends SimpleFileVisitorlt;Pathgt; {

private final PathMatcher matcher; private static int numMatches = 0;

Finder() {

matcher = FileSystems.getDefault().getPathMatcher(quot;glob:*javaquot;);

}

void find(Path file) {

Path Name = file.getFileName();

if (name != null amp;amp; matcher.matches(name)) { numMatches ;

}

}

void report()

{

System.out.println(quot;Matched: quot; numMatches);

}

@Override

public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) { find(file);

return CONTINUE;

}

}

public class Visitor {

public static void main(String[] args) throws IOException { Finder finder = new Finder();

Files.walkFileTree(Paths.get(quot;d:\\Projectquot;), finder); finder.report();

}

}

What is the result?

  1. Compilation fails

  2. 6

  3. 4

  4. 1

  5. 3

Answer: B

Explanation: The program will compile and run.

Referring to the exhibit there will be six nodes that matches glob:*java.

Question No: 34

Given the following code fragment:

public static void main(String[] args) { Path tempFile = null;

try {

Path p = Paths.get(quot;empquot;);

tempFile = Files.createTempFile(p, quot;reportquot;, quot;.tmpquot;);

try (BufferedWriter writer = Files.newBufferedWriter(tempFile, Charset.forName(quot;UTF8quot;)))){ writer.write(quot;Java SE 7quot;);

}

System.out.println(quot;Temporary file write donequot;);

} catch(IOException e) {

System.err.println(quot;Caught IOException: quot; e.getMessage());

}

}

What is the result?

  1. The report.tmp file is purged during reboot.

  2. The report.tmp file is automatically purged when it is closed.

  3. The report.tmp file exists until it is explicitly deleted.

  4. The report.tmp file is automatically purged when the execution of the program completes.

Answer: C

Explanation: The createTempFile (String prefix, String suffix,

FileAttributelt;?gt;… attrs) method creates an empty file in the default temporary-file directory, using the given prefix and suffix to generate its name.

This method is only part of a temporary-file facility. Where used as a work files, the resulting file may be opened using the DELETE_ON_CLOSE option so that the file is deleted when the appropriate close method is invoked. Alternatively, a shutdown-hook, or the File.deleteOnExit() mechanism may be used to delete the file automatically.

In this scenario no delete mechanism is specified. Reference: java.nio.file.createTempFile

Question No: 35

Which two Capabilities does Java.util.concurcent.BlockingQueue provide to handle operation that cannot be handled immediately?

  1. Automatically retry access to the queue with a given periodicity.

  2. Wait for the queue to contain elements before retrieving an element.

  3. Increase the queue#39;s capacity based on the rate of blocked access attempts.

  4. Wait for space to become available in the queue before inserting an element.

Answer: B,D

Explanation: A blocking queue is a Queue that additionally supports operations that wait for the queue to become non-empty when retrieving an element, and wait for space to become available in the queue when storing an element.

Note: The BlockingQueue interface in the java.util.concurrent class represents a queue which is thread safe to put into, and take instances from.

The producing thread will keep producing new objects and insert them into the queue, until the queue reaches some upper bound on what it can contain. It#39;s limit, in other words. If the blocking queue reaches its upper limit, the producing thread is blocked while trying to insert the new object. It remains blocked until a consuming thread takes an object out of the queue.

The consuming thread keeps taking objects out of the blocking queue, and processes them. If the consuming thread tries to take an object out of an empty queue, the consuming thread is blocked until a producing thread puts an object into the queue.

Reference: Java.util.concurcent.BlockingQueue

Question No: 36

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

  1. The interface extends WatchService interface

  2. Implementations of this interface are immutable.

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

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

Answer: A

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

Question No: 37

What are two benefits of a Factory design pattern?

  1. Eliminates direct constructor calls in favor of invoking a method

  2. Provides a mechanism to monitor objects for changes

  3. Eliminates the need to overload constructors in a class implementation

  4. Prevents the compile from complaining about abstract method signatures

  5. Prevents tight coupling between your application and a class implementation

Answer: A,E

Explanation: Factory methods are static methods that return an instance of the native class.

Factory methods :

  • have names, unlike constructors, which can clarify code.

  • do not need to create a new object upon each invocation – objects can be cached and reused, if necessary.

  • can return a subtype of their return type – in particular, can return an object whose implementation class is unknown to the caller. This is a very valuable and widely used feature in many frameworks which use interfaces as the return type of static factory methods.

Note: The factory pattern (also known as the factory method pattern) is a creational design pattern. A factory is a JavaSW class that is used to encapsulate object creation code. A factory class instantiates and returns a particular type of object based on data passed to the factory. The different types of objects that are returned from a factory typically are subclasses of a common parent class.

The data passed from the calling code to the factory can be passed either when the factory is created or when the method on the factory is called to create an object. This creational method is often called something such as getInstance or getClass .

Question No: 38

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

  1. Inheritance

  2. Copy and Paste

  3. Composition

  4. Refactoring

  5. 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#39; function would be called (if it exists). If it is not virtual, the base class#39; 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.

Question No: 39

Given:

public class DAOManager {

public AccountDAO getAccountDAO() { return new AccountJDBCDAO();

}

}

Which design pattern best describes the class?

  1. Singleton

  2. DAO

  3. Factory

  4. Composition

Answer: B

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)

Question No: 40

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

  1. When preconditions on the uri parameter do not hold

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

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

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

  5. 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#39;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#39;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

100% Free Download!
Download Free Demo:1Z0-805 Demo PDF
100% Pass Guaranteed!
Download 2017 CollectDumps 1Z0-805 Full Exam PDF and VCE

CollectDumps ExamCollection Testking
Lowest Price Guarantee Yes No No
Up-to-Dated Yes No No
Real Questions Yes No No
Explanation Yes No No
PDF VCE Yes No No
Free VCE Simulator Yes No No
Instant Download Yes No No

2017 CollectDumps IT Certification PDF and VCE