Oracle Upgrade to Java SE 7 Programmer - 1Z1-805 Exam Practice Test
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?
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?
Correct Answer: C
Explanation: Only visible for TrainingDump members. You can sign-up / login (it's free).
Which three enum constants are defined in FilevisitResult?
Correct Answer: A,C,D
Explanation: Only visible for TrainingDump members. You can sign-up / login (it's free).
Which two methods are defined in the FileStore class print disk space information?
Correct Answer: C,D
Explanation: Only visible for TrainingDump members. You can sign-up / login (it's free).
Which two Capabilities does Java.util.concurcent.BlockingQueue provide to handle operation that cannot be handled immediately?
Correct Answer: A,C
Explanation: Only visible for TrainingDump members. You can sign-up / login (it's free).
Which is a key aspect of composition?
Correct Answer: B
Explanation: Only visible for TrainingDump members. You can sign-up / login (it's free).
Given:
public class MyGrades {
private final List<Integer> myGrades = new ArrayList<Integer>();
private final ReadWriteLock rwlock = new ReentrantReadWriteLock();
public void addGrade(Integer grade) {
// acquire _______ lock
myGrades.add(grade);
// release __________ lock
}
public void averageGrades() {
// acquire _______ lock Line ** double sum = 0;
int i = 0;
for (i = 0; i < myGrades.size(); i++) {
sum += myGrades.get(i);
}
// release __________ lock Line ***
System.out.println("The average is: " + sum/(i+1));
}
}
Which pair's statements should you insert at lines ** and lines *** (respectively) to acquire and release the most appropriate lock?
public class MyGrades {
private final List<Integer> myGrades = new ArrayList<Integer>();
private final ReadWriteLock rwlock = new ReentrantReadWriteLock();
public void addGrade(Integer grade) {
// acquire _______ lock
myGrades.add(grade);
// release __________ lock
}
public void averageGrades() {
// acquire _______ lock Line ** double sum = 0;
int i = 0;
for (i = 0; i < myGrades.size(); i++) {
sum += myGrades.get(i);
}
// release __________ lock Line ***
System.out.println("The average is: " + sum/(i+1));
}
}
Which pair's statements should you insert at lines ** and lines *** (respectively) to acquire and release the most appropriate lock?
Correct Answer: D
Explanation: Only visible for TrainingDump members. You can sign-up / login (it's free).
Given the following incorrect program:
class MyTask extends RecursiveTask<Integer> {
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 <= 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?
class MyTask extends RecursiveTask<Integer> {
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 <= 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?
Correct Answer: B,F
Explanation: Only visible for TrainingDump members. You can sign-up / login (it's free).
In the Java SE7 API, which method is most commonly used by factories to instantiate objects?
Correct Answer: F
Explanation: Only visible for TrainingDump members. You can sign-up / login (it's free).
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?
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?
Correct Answer: B,D,F
Explanation: Only visible for TrainingDump members. You can sign-up / login (it's free).