Certified of 1Z0-805 practice test materials and free samples for Oracle certification for IT professionals, Real Success Guaranteed with Updated 1Z0-805 pdf dumps vce Materials. 100% PASS Upgrade to Java SE 7 Programmer exam Today!

2021 Jul 1Z0-805 simulations

Q1. 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 


// 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? 

A. rwlock.readLock().acquire(); rwlock.readLock().release(); 

B. rwlock.readLock().lock(); rwlock.readLock().unlock(); 

C. rwlock.getLock().acquire(); rwlock.getLock().release(); 

D. rwlock.getLock().lock(); rwlock.getLock().Unlock(); 

E. relock.WriteLock().acquire(); rwlock.writeLock().release(); 

F. rwlock.writeLock().lock(); rwlock.WriteLock().unlock(); 

Answer: B 

Explanation: We need a read lock, not a write lock, we are just reading data, not 

writing/updating data. 

To aquire and release the lock the method lock() and unlock are used. 

Reference: Class ReentrantReadWriteLock 

Q2. Given: 

Which design pattern moves the getPerson, createPerson, deletePerson, and updatePerson methods to a new class? 

A. Singleton 


C. Factory 

D. Composition 

Answer: B 

Explanation: We move the most abstract highest level methods into a separate class. 

Note: 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) 

Q3. Given the error message when running you application: 

Exception in thread “main” java.util.MissingResourceException: can’t find bundle for base name messageBundle, Locale 

And given that the Message Bundle.properties file has been created, exists on your disk, and is properly formatted. 

What is the cause of the error message? 

A. The file is not in the environment PATH. 

B. The file is not in the CLASSPATH. 

C. The file is not in the JJAVAPATH. 

D. You cannot use a file to store a ResourceBundle. 

Answer: B 

Q4. Given this code fragment: 

try { 

String query = "SELECT * FROM Item"; 

Statement stmt = conn.createStatement(); 

ResultSet rs = stmt.executeQuery(query); 

ResultSetMetaData rsmd = rs.getMetaData(); 

int rowCount = rsmd.getRowCount(); 

System.out.println ("Processing: " + rowCount + " rows."); 

while (rs.next()) { 

// Process each row 

} catch (SQLException se) { 


Assume that the SQL query returns records. What is the result? 

A. Compilation fails. 

B. The program prints Error 

C. An exception is thrown at runtime 

D. The statement at line 16 execute 

Answer: A 

Explanation: There is no GetRowCount method in java.sql.ResultSetMetaData. 

The following line will not compile: 

int rowCount = rsmd.getRowCount(); 

Reference: java.sql.ResultSetMetaData 

Q5. 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? 

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. 

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(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. 


Refresh 1Z0-805 exam answers:

Q6. Given: 

public AccountDAO getAccountDAO() { 

return new AccountJDBCDAO(); 

Which design pattern best describes the class? 

A. Singleton 


C. Factory 

D. 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) 

Q7. Given the code fragment: 

public class App { 

public static void main (String [] args) { 

path path = paths.get(“C\educations\institute\student\report.txt”); 

system.out.printIn(“getName(0): %s”, path.getName(0)); 

system.out.prinIn(“subpath(0, 2): %s” path.subpath(0, 2)); 

What is the result? 

A. getName (0): C: 

subpath(0, 2): C:educationreport.txt 

B. getName (0): C: 

subpath(0, 2): educationinstitute 

C. getName(0): education 

subpath(0, 2: educationinstitutestudent 

D. getName(0): education 

subpath(0, 2): educationinstitute 

E. getName(0): report.txt 

subpath (0, 2): institutestudent 

Answer: D 

Explanation: The getName(int index) method returns a name element of this path as a Path object. 

The subpath(int beginIndex, int endIndex) method returns a relative Path that is a subsequence of the name elements of this path. 

Reference: java.nio.file.Path 

Q8. Which two file attribute views support reading or updating the owner of a file? 

A. AclFileAttributeView 

B. DosFileAttributeView 

C. FileOwnerAttributeView 

D. FileStoreAttributeView 

E. BasicFileAttributeView 

Answer: A,C 

Explanation: A: The AclFileAttributeView is a file attribute view that supports reading or updating a file's Access Control Lists (ACL) or file owner attributes. 

C: The FileOwnerAttributeView.setOwner(UserPrincipal owner) method updates the file owner. 

Reference: Interface AclFileAttributeView, Interface FileOwnerAttributeView 

Q9. Which two code blocks correctly initialize a Locale variable? 

A. Locale loc1 = "UK"; 

B. Locale loc2 = Locale.get Instance ( "ru" ); 

C. Locale loc3 = Locale.getLocaleFactory("RU"); 

D. Locale loc4 = Locale.UK; 

E. Locale loc5 = new Locale("ru", "RU"); 

Answer: D,E 

Reference: The Java Tutorials, Creating a Locale 

Q10. Given the code fragment: 

List<Person> pList = new CopyOnWriteArrayList<Person>(); 

Which statement is true? 

A. Read access to the List should be synchronized. 

B. Write access to the List should be synchronized. 

C. Person objects retrieved from the List are thread-safe. 

D. A Person object retrieved from the List is copied when written to. 

E. Multiple threads can safely delete Person objects from the List. 

Answer: C 

Explanation: CopyOnWriteArrayList produces a thread-safe variant of ArrayList in which all mutative operations (add, set, and so on) are implemented by making a fresh copy of the underlying array. 

Note: his is ordinarily too costly, but may be more efficient than alternatives when traversal operations vastly outnumber mutations, and is useful when you cannot or don't want to synchronize traversals, yet need to preclude interference among concurrent threads. The "snapshot" style iterator method uses a reference to the state of the array at the point that the iterator was created. This array never changes during the lifetime of the iterator, so interference is impossible and the iterator is guaranteed not to throw ConcurrentModificationException. The iterator will not reflect additions, removals, or changes to the list since the iterator was created. Element-changing operations on iterators themselves (remove, set, and add) are not supported. These methods throw UnsupportedOperationException. 

All elements are permitted, including null. 

Memory consistency effects: As with other concurrent collections, actions in a thread prior to placing an object into a CopyOnWriteArrayList happen-before actions subsequent to the access or removal of that element from the CopyOnWriteArrayList in another thread. 

Reference: java.util.concurrent.CopyOnWriteArrayList<E>