Ensurepass.com : Ensure you pass the IT Exams
2018 Jan Oracle Official New Released 1Z0-805
100% Free Download! 100% Pass Guaranteed!
http://www.EnsurePass.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?
-
Singleton
-
DAO
-
Abstract Factory
-
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?
-
sdf = new SimpleDateFormat (quot;mmquot;, Locale.UK); System.out.println ( quot;Result: quot; sdf.format(new Date()));
-
sdf = new SimpleDateFormat (quot;MMquot;, Locale.UK); System.out.println ( quot;Result: quot; sdf.format(new Date()));
-
sdf = new SimpleDateFormat (quot;MMMquot;, Locale.UK); System.out.println ( quot;Result: quot; sdf.format(new Date()));
-
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;);
-
One
-
Two
-
Three
-
Four
-
Five
-
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?
-
sdf = new SimpleDateFormat (quot;mmquot;, Locale.UK); System.out.printIn ( “Result: ” sdf.format(new Date()))
-
sdf = new SimpleDateFormat (quot;MMquot;, Locale.UK); System.out.printIn ( “Result: ” sdf.format(new Date()))
-
sdf = new SimpleDateFormat (quot;MMMquot;, Locale.UK); System.out.printIn ( quot;Result: quot; sdf.format(new Date()))
-
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?
-
CONTINUE
-
SKIP_SIBLINGS
-
FOLLOW_LINKS
-
TERMINATE
-
NOFOLLOW_LINKS
-
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?
-
java.io.IOException
-
java.lang.Exception
-
java.lang.ClassNotException
-
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?
-
Results must be retrieved from the newly created MyTask Instances and combined.
-
The THRESHOLD value must be increased so that the overhead of task creation does not dominate the cost of computation.
-
The midpoint computation must be altered so that it splits the workload in an optimal manner.
-
The compute () method must be changed to return an Integer result.
-
The computeDirectly () method must be enhanced to fork () newly created tasks.
-
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?
-
Compilation fails due to an error at line 28
-
Compilation fails due to error at line 15 and 16
-
The contents of report1.txt are copied to consolidate.txt. The contents of report2.txt are appended to consolidate.txt, after a new line
-
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?
-
A new Thread is used for each task.
-
A number of Threads equal to the number of CPUs is used to execute tasks.
-
A single Thread is used to execute all tasks.
-
A developer-defined number of Threads Is used to execute tasks.
-
A number of Threads determined by system load is used to execute tasks.
-
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?
-
sdf = new SimpleDateFormat (quot;mmquot;, Locale.UK); System.out.println (quot;Result: quot; sdf.format(new Date()));
-
sdf = new SimpleDateFormat (“MM”, Locale.UK); System.out.println (quot;Result: quot; sdf.format(new Date()));
-
sdf = new SimpleDateFormat (“MMM”, Locale.UK); System.out.println (quot;Result: quot; sdf.format(new Date()));
-
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% Ensurepass Free Download!
–Download Free Demo:1Z0-805 Demo PDF
100% Ensurepass Free Guaranteed!
–1Z0-805 Dumps
EnsurePass | 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 |
100-105 Dumps VCE PDF
200-105 Dumps VCE PDF
300-101 Dumps VCE PDF
300-115 Dumps VCE PDF
300-135 Dumps VCE PDF
300-320 Dumps VCE PDF
400-101 Dumps VCE PDF
640-911 Dumps VCE PDF
640-916 Dumps VCE PDF
70-410 Dumps VCE PDF
70-411 Dumps VCE PDF
70-412 Dumps VCE PDF
70-413 Dumps VCE PDF
70-414 Dumps VCE PDF
70-417 Dumps VCE PDF
70-461 Dumps VCE PDF
70-462 Dumps VCE PDF
70-463 Dumps VCE PDF
70-464 Dumps VCE PDF
70-465 Dumps VCE PDF
70-480 Dumps VCE PDF
70-483 Dumps VCE PDF
70-486 Dumps VCE PDF
70-487 Dumps VCE PDF
220-901 Dumps VCE PDF
220-902 Dumps VCE PDF
N10-006 Dumps VCE PDF
SY0-401 Dumps VCE PDF