invokeAll(new MyTask(low, mid), new MyTask(mid, high));
Which two changes make the program work correctly?
A. Results must be retrieved from the newly created MyTask Instances and combined. B. The THRESHOLD value must be increased so that the overhead of task creation does not dominate the cost of computation. C. The midpoint computation must be altered so that it splits the workload in an optimal manner. D. The compute () method must be changed to return an Integer result. E. The computeDirectly () method must be enhanced to fork () newly created tasks. F. The MyTask class must be modified to extend RecursiveAction instead of RecursiveTask.
A. Results must be retrieved from the newly created MyTask Instances and combined. D. The compute () method must be changed to return an Integer result.
D: the compute() method must return a result.
A: These results must be combined (in the lineinvokeAll(new MyTask(low, mid), new MyTask(mid, high));)
Note 1:A RecursiveTask is a recursive result-bearing ForkJoinTask.
Note 2: The invokeAll(ForkJoinTask>... 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 42:
Given the code fragment: static void addContent () throws Exception {
Which try statement, when inserted at line **, enables appending the file content without writing the metadata to the underlying disk?
A. try (BufferWriter br = Files.newBufferedWriter (path, Charset.forName ("UTF-8"), new openOption [] {StandardOpenOption.CREATE, StandardOpenOption.Append, StandardOpenOption.DSYNC}};} { B. try (BufferWriter br = Files.newBufferedWriter (path, Charset.forName ("UTF-8"), new openOption [] {StandardOpenOption.APPEND, StandardOpenOption.SYNC));){ C. try (BufferWriter br = Files.newBufferedWriter (path, Charset.forName ("UTF - 8"), new openOption [] {StandardOpenOption.APPEND, StandardOpenOption.DSYNC} D. try (BufferWriter br = Files.newBufferedWriter (path, Charset.forName ("UTF?;), new openOption [] {StandardOpenOption.CREATENEW, StandardOpenOption.APPEND, StandardOpenOption.SYNC}} } E. try (BufferWriter br = Files.newBufferedWriter (path, Charset.forName ("UTF - 8"), new openOption [] {StandardOpenOption.APPEND, StandardOpenOption.ASYNC});) {
C. try (BufferWriter br = Files.newBufferedWriter (path, Charset.forName ("UTF - 8"), new openOption [] {StandardOpenOption.APPEND, StandardOpenOption.DSYNC}
StandardOpenOption should be both APPEND (if the file is opened for WRITE access then bytes will be written to the end of the file rather than the beginning)and DSYNC (Requires that every update to the file's content be written
synchronously to the underlying storage device.).
Note 1:The newBufferedWriter method Opens or creates a file for writing, returning a BufferedWriter that may be used to write text to the file in an efficient manner. The options parameter specifies how the the file is created or opened. If no
options are present then this method works as if the CREATE, TRUNCATE_EXISTING, and WRITE options are present. In other words, it opens the file for writing, creating the file if it doesn't exist, or initially truncating an existing regular-file
to a size of 0 if it exists.
Note2: public static final StandardOpenOption APPEND
If the file is opened for WRITE access then bytes will be written to the end of the file rather than the beginning.
If the file is opened for write access by other programs, then it is file system specific if writing to the end of the file is atomic.
Reference: java.nio.file.Files
java.nio.file Enum StandardOpenOption
Question 43:
import java.util.*;
public class StringApp {
public static void main (String [] args)
{ Set set = new TreeSet <> ();
set.add("X");
set.add("Y");
set.add("X");
set.add("Y");
set.add("X");
Iterator it = set.iterator ();
int count = 0;
while (it.hasNext())
{ switch
(it.next()){ case "X":
System.out.print("X ");
break; case "Y":
System.out.print("Y ");
break;
}
count++;
}
System.out.println ("\ncount = " + count);
}
}
A. X X Y X Y count = 5 B. X Y X Y count = 4 C. X Y count = s D. X Y count = 2
D. X Y count = 2
A set is a collection that contains no duplicate elements. So set will include only two elements at the start of while loop. The while loop will execute once for each element. Each element will be printed.
Note:
*public interface Iterator
An iterator over a collection. Iterator takes the place of Enumeration in the Java collections framework. Iterators differ from enumerations in two ways:
Iterators allow the caller to remove elements from the underlying collection during the iteration with well-defined semantics.
Method names have been improved.
*hasNext
public boolean hasNext()
Returns true if the iteration has more elements. (In other words, returns true if next would return element rather than throwing an exception.)
*next
publicObjectnext()
Returns the next element in the iteration.
Question 44:
You are using a database from XY/Data. What is a prerequisite for connecting to the database using a JDBC 4.0 driver from XY/Data?
A. Use the JDBC DriverManager.loadDriver method. B. Put the XY/data driver into the classpath of your application. C. Create an instance of the XY/Data driver class using the new keyword. D. Create an Implementation of DriverManager that extends the XY/Data driver
B. Put the XY/data driver into the classpath of your application.
First, you need to establish a connection with the data source you want to use. A data source can be a DBMS, a legacy file system, or some other source of data with a corresponding JDBC driver. Typically, a JDBC application connects to a target data source using one of two classes:
*
DriverManager: This fully implemented class connects an application to a data source, which is specified by a database URL. When this class first attempts to establish a connection, it automatically loads any JDBC 4.0 drivers found within the class path(B). Note that your application must manually load any JDBC drivers prior to version 4.0.
*
DataSource: This interface is preferred over DriverManager because it allows details about the underlying data source to be transparent to your application. A DataSource object's properties are set so that it represents a particular data source.
Note:The JDBC Architecture mainly consists of two layers:
First is JDBC API, which provides the application-to-JDBC Manager connection. Second is JDBC Driver API, which supports the JDBC Manager-to-Driver Connection. This has to provide by the vendor of database, you must have notice that
one external jar file has to be there in class path for forth type of driver (B).
The JDBC API uses a driver manager and database-specific drivers to provide transparent connectivity to heterogeneous databases. The JDBC driver manager ensures that the correct driver is used to access each data source. The driver
manager is capable of supporting multiple concurrent drivers connected to multiple heterogeneous databases.
Reference: The Java Tutorials, Establishing a Connection
Question 45:
Two companies with similar robots have merged. You are asked to construct a new program that allows the features of the robots to be mixed and matched using composition. Given the code fragments:
public class CrusherRobot {
public void walk () {}
public void positionArm (int x, int y, int z) {}
public void raiseHammer() {}
public void dropHammer() {}
}
public class GripperRobot {
public void walk() {}
public void moveArm (int x, int y, int z) {}
public void openGripper () {}
public void closeGripper() {}
}
When applying composition to these two classes, what functionality should you extract into a new class?
A. A new BasicRobot class that provides walking. B. A new BasicRobot class that combines gripping and hammering. C. A new BasicRobotFactory class to construct instances of GripperRobot. D. A new BasicRobotFactory class to construct instances of CrusherRobot.
B. A new BasicRobot class that combines gripping and hammering.
Question 46:
Given: Which design pattern moves the getPerson, createPerson, deletePerson, and updatePerson methods to a new class?
A. Singleton B. DAO C. Factory D. Composition
B. DAO
We move the most abstract highest level methods into a separate class.
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 47:
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.
B. The code prints the employee ID.
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
Which two statements are a valid way to re-assign a resource bundle to a different Locale?
A. loc1 = ResourceBundle.getBundle ("MessageBundle", Locale.CHINA); B. loc1 = ResourceBundle.getBundle ("MessageBundle", new Locale ("es", "ES")); C. messages = ResourceBundle.getBundle ("messageBundle", new Locale ("es", "ES")); D. messages = ResourceBundle.getBundle ("MessageBundle", Locale.CHINA);
C. messages = ResourceBundle.getBundle ("messageBundle", new Locale ("es", "ES")); D. messages = ResourceBundle.getBundle ("MessageBundle", Locale.CHINA);
Question 49:
What statement is true about thread starvation?
A. Thread "A" is said to be starved when it is frequently unable to gain access to a resource that it shares with another thread. B. Thread "A" is said to be starved when it is blocked waiting for Thread "13," which in turn waiting for Thread "A." C. Starvation can occur when threads become so busy responding to other threads that they move forward with their other work. D. When some of the processors in a multi-processor environment go offline and the live thread(s) blocked waiting for CPU cycles, that blocking is referred to as "thread starvation."
A. Thread "A" is said to be starved when it is frequently unable to gain access to a resource that it shares with another thread.
Starvation describes a situation where a thread is unable to gain regular access to shared resources and is unable to make progress. This happens when shared resources are made unavailable for long periods by "greedy" threads. For example, suppose an object provides a synchronized method that often takes a long time to return. If one thread invokes this methodfrequently, other threads that also need frequent synchronized access to the same object will often be blocked.
Reference: The Java Tutorials,Starvation and Livelock
Question 50:
Given:
public class TemperatureSensor {
public TemperatureSensor () {
}
public double getCurrTemp () {
// . . . method to retrieve temperature from a sensor
Return temp;
}
}
Which three changes should you make to apply the singleton design pattern to this class?
A. Make the class abstract. B. Add a method to return a singleton class type. C. Change the access of the constructor to private. D. Add a public constructor that takes a single argument. E. Change the class to implement the singleton interface. F. Add a private static final variable that is initialized to new TemperatureSensor{}; G. Add a public static method that returns the class variable of type
C. Change the access of the constructor to private. F. Add a private static final variable that is initialized to new TemperatureSensor{}; G. Add a public static method that returns the class variable of type
C: We provide a default Private constructor F,G:We write a public static getter or access method(G)to get the instance of the Singleton Object at runtime. First time the object is created inside this method as it is null. Subsequent calls to this method returns the same object created as the object is globally declared (private)(F)and the hence the same referenced object is returned. Note: Java has several design patterns Singleton Pattern being the most commonly used. Java Singleton patternbelongs 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 (C), 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.
Nowadays, the certification exams become more and more important and required by more and more
enterprises when applying for a job. But how to prepare for the exam effectively? How to prepare
for the exam in a short time with less efforts? How to get a ideal result and how to find the
most reliable resources? Here on Vcedump.com, you will find all the answers.
Vcedump.com provide not only Oracle exam questions,
answers and explanations but also complete assistance on your exam preparation and certification
application. If you are confused on your 1Z0-805 exam preparations
and Oracle certification application, do not hesitate to visit our
Vcedump.com to find your solutions here.