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

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: 21

Given:

public class DataCache {

private static final DataCache instance = new DataCache ();

public static DataCache getInstance () { return instance;

}

}

Which design pattern best describes the class?

  1. Singleton

  2. DAO

  3. Abstract Factory

  4. Composition

Answer: A

Explanation: Java has several design patterns Singleton Pattern being the most commonly used. Java Singleton pattern belongs to the family of design patterns, that govern the instantiation process. This design pattern proposes that at any time there can only be one instance of a singleton (object) created by the JVM.

The class’s default constructor is made private, which prevents the direct instantiation of the object by others (Other Classes). A static modifier is applied to the instance method that returns the object as it then makes this method a class level method that can be accessed without creating an object.

Question No: 22

Given the code format: SimpleDateFormat sdf;

Which code statements will display the full text month name?

  1. sdf = new SimpleDateFormat (quot;mmquot;, Locale.UK); System.out.println ( quot;Result: quot; sdf.format(new Date()));

  2. sdf = new SimpleDateFormat (quot;MMquot;, Locale.UK); System.out.println ( quot;Result: quot; sdf.format(new Date()));

  3. sdf = new SimpleDateFormat (quot;MMMquot;, Locale.UK); System.out.println ( quot;Result: quot; sdf.format(new Date()));

  4. sdf = new SimpleDateFormat (quot;MMMMquot;, Locale.UK); System.out.println ( quot;Result: quot; sdf.format(new Date()));

Answer: D

Explanation: To get the full length month name use SimpleDateFormat(#39;MMMM#39;).

Note: SimpleDateFormat is a concrete class for formatting and parsing dates in a locale- sensitive manner. It allows for formatting (date -gt; text), parsing (text -gt; 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.

Question No: 23

The default file system includes a logFiles directory that contains the following files:

log – Jan2009 log_01_2010 log_Feb2010 log_Feb2011 log-sum-2012

How many files the matcher in this fragment match?

PathMatcher matcher = FileSystems.getDefault ().getPathMatcher (quot;glob:???_*1quot;);

  1. One

  2. Two

  3. Three

  4. Four

  5. Five

  6. Six

Answer: A

Explanation: The glob pattern is: any three characters, followed by _ ,followed by any number of characters, and ending with a 1.

Only log_Feb2011 matches this pattern.

Note:

You can use glob syntax to specify pattern-matching behavior.

A glob pattern is specified as a string and is matched against other strings, such as directory or file names. Glob syntax follows several simple rules:

  • An asterisk, *, matches any number of characters (including none).

    ** Two asterisks, **, works like * but crosses directory boundaries. This syntax is generally used for matching complete paths.

  • A question mark, ?, matches exactly one character.

  • Braces specify a collection of subpatterns. For example:

    {sun,moon,stars} matches quot;sunquot;, quot;moonquot;, or quot;stars.quot;

    {temp*,tmp*} matches all strings beginning with quot;tempquot; or quot;tmp.quot;

  • Square brackets convey a set of single characters or, when the hyphen character (-) is used, a range of characters. For example:

[aeiou] matches any lowercase vowel. [0-9] matches any digit.

[A-Z] matches any uppercase letter.

[a-z,A-Z] matches any uppercase or lowercase letter.

  • Within the square brackets, *, ?, and \ match themselves.

    *All other characters match themselves.

  • To match *, ?, or the other special characters, you can escape them by using the backslash character, \. For example: \\ matches a single backslash, and \? matches the question mark.

    Reference: The Java Tutorials Finding Files

    What Is a Glob?

    Question No: 24

    Given the code fragment: SimpleDateFormat sdf;

    Which code fragment displays the two-digit month number?

    1. sdf = new SimpleDateFormat (quot;mmquot;, Locale.UK); System.out.printIn ( “Result: ” sdf.format(new Date()))

    2. sdf = new SimpleDateFormat (quot;MMquot;, Locale.UK); System.out.printIn ( “Result: ” sdf.format(new Date()))

    3. sdf = new SimpleDateFormat (quot;MMMquot;, Locale.UK); System.out.printIn ( quot;Result: quot; sdf.format(new Date()))

    4. sdf = new SimpleDateFormat (quot;MMMMquot;, Locale.UK); System.out.printIn ( quot;Result: quot; sdf.format(new Date()))

    Answer: B

    Explanation: B: Output example (displays current month numerically): 04

    Note: SimpleDateFormat is a concrete class for formatting and parsing dates in a locale- sensitive manner. It allows for formatting (date -gt; text), parsing (text -gt; 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.

    Question No: 25

    Which three enum constants are defined in FilevisitResult?

    1. CONTINUE

    2. SKIP_SIBLINGS

    3. FOLLOW_LINKS

    4. TERMINATE

    5. NOFOLLOW_LINKS

    6. DELETE_CHILD

    Answer: A,B,D

    Explanation: The FileVisitor methods return a FileVisitResult value. You can abort the file walking process or control whether a directory is visited by the values you return in the FileVisitor methods:

  • CONTINUE – Indicates that the file walking should continue. If the preVisitDirectory method returns CONTINUE, the directory is visited.

  • SKIP_SIBLINGS – When preVisitDirectory returns this value, the specified directory is not visited, postVisitDirectory is not invoked, and no further unvisited siblings are visited. If returned from the postVisitDirectory method, no further siblings are visited. Essentially, nothing further happens in the specified directory.

  • TERMINATE – Immediately aborts the file walking. No further file walking methods are invoked after this value is returned.

  • SKIP_SUBTREE – When preVisitDirectory returns this value, the specified directory and its subdirectories are skipped. This branch is quot;pruned outquot; of the tree.

    Note: To walk a file tree, you first need to implement a FileVisitor. A FileVisitor specifies the required behavior at key points in the traversal process: when a file is visited, before a directory is accessed, after a directory is accessed, or when a failure occurs.

    Reference: The Java Tutorials, Walking the File Tree

    Question No: 26

    Given the code fragment:

    public void processFile() throws IOException, ClassNotFoundException { try (FileReader fr = new FileReader (quot;logfilesrc.txtquot;);

    FileWriter fw = new FileWriter (quot;logfiledest.txtquot;)) { Class c = Class.forName (quot;java.lang.JStringquot;);

    }

    }

    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?

    1. java.io.IOException

    2. java.lang.Exception

    3. java.lang.ClassNotException

    4. java.lang.NoSuchClassException

    Answer: A

    Question No: 27

    Given the following incorrect program:

    class MyTask extends RecursiveTasklt;Integergt; { final int low;

    final int high;

    static final int THRESHOLD = /* . . . */

    MyTask (int low, int high) { this.low = low; this.high = high; }

    Integer computeDirectly()/* . . . */ protected void compute() {

    if (high – low lt;= THRESHOLD) return computeDirectly();

    int mid = (low high) / 2;

    invokeAll(new MyTask(low, mid), new MyTask(mid, high)); Which two changes make the program work correctly?

    1. Results must be retrieved from the newly created MyTask Instances and combined.

    2. The THRESHOLD value must be increased so that the overhead of task creation does not dominate the cost of computation.

    3. The midpoint computation must be altered so that it splits the workload in an optimal manner.

    4. The compute () method must be changed to return an Integer result.

    5. The computeDirectly () method must be enhanced to fork () newly created tasks.

    6. The MyTask class must be modified to extend RecursiveAction instead of RecursiveTask.

    Answer: A,D

    Explanation: D: the compute() method must return a result.

    A: These results must be combined (in the line invokeAll(new MyTask(low, mid), new MyTask(mid, high));)

    Note 1: A RecursiveTask is a recursive result-bearing ForkJoinTask.

    Note 2: The invokeAll(ForkJoinTasklt;?gt;… tasks) forks the given tasks, returning when isDone holds for each task or an (unchecked) exception is encountered, in which case the exception is rethrown.

    Note 3: Using the fork/join framework is simple. The first step is to write some code that performs a segment of the work. Your code should look similar to this:

    if (my portion of the work is small enough) do the work directly

    else

    split my work into two pieces

    invoke the two pieces and wait for the results

    Wrap this code as a ForkJoinTask subclass, typically as one of its more specialized types RecursiveTask(which can return a result) or RecursiveAction.

    Question No: 28

    Given:

    private static void copyContents() { try (

    InputStream fis = new FileInputStream(quot;report1.txtquot;); OutputStream fos = new FileOutputStream(quot;consolidate.txtquot;);

    ) {

    byte[] buf = new byte[8192];

    int i;

    while ((i = fis.read(buf)) != -1) { fos.write(buf, 0, i);

    }

    fis.close();

    fis = new FileInputStream(quot;report2.txtquot;);

    while ((i = fis.read(buf)) != -1) { fos.write(buf, 0, i);

    }

    }

    What is the result?

    1. Compilation fails due to an error at line 28

    2. Compilation fails due to error at line 15 and 16

    3. The contents of report1.txt are copied to consolidate.txt. The contents of report2.txt are appended to consolidate.txt, after a new line

    4. The contents of report1.txt are copied to consolidate.txt. The contents of report2.txt are appended to consolidate.txt, without a break in the flow.

    Answer: A

    Explanation: The auto-closable resource fis may not be assigned.

    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

    Question No: 29

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

    1. A new Thread is used for each task.

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

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

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

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

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

    Answer: F

    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

Question No: 30

Given the code fragment: SimpleDateFormat sdf;

Which code fragment displays the three-character month abbreviation?

  1. sdf = new SimpleDateFormat (quot;mmquot;, Locale.UK); System.out.println (quot;Result: quot; sdf.format(new Date()));

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

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

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

Answer: C

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 -gt; text), parsing (text -gt; 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.

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