100% Correct of 1Z0-805 free exam materials and practice exam for Oracle certification for IT examinee, 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 practice test

Q21. Given: 

What two changes should you make to apply the DAO pattern to this class? 

A. Make the customer class abstract. 

B. Make the customer class an interface. 

C. Move the add, delete, find, and update methods into their own implementation class. 

D. Create an interface that defines the signatures of the add, delete, find and update command. 

E. Make the add, delete, find, and update methods private for encapsulation. 

F. Make the getName and getId methods private fir encapsulation. 

Answer: C,D 

Explanation: In computer software, a data access object (DAO) is an object that provides an abstract interface to some type of database or persistence mechanism, providing some specific operations without exposing details of the database. It provides a mapping from application calls to the persistence layer. This isolation separates the concerns of what data accesses the application needs, in terms of domain-specific objects and data types (the public interface of the DAO), and how these needs can be satisfied with a specific DBMS, database schema, etc. (the implementation of the DAO). 

In the specific context of the Java programming language, Data Access Objects as a design concept can be implemented in a number of ways. This can range from a fairly simple interface that separates the data access parts from the application logic, to frameworks and commercial products. 

Q22. Which two descriptions are benefits of using PreparedStatement objects over static SQL in JDBC? 

A. Conversion to native SQL 

B. Supports BLOB types on every type of database 

C. Prevention of SQL injection attacks 

D. Improved performance from frequently run SQL queries 

E. Built in support for multi database transaction semantics 

Answer: A,D 

Explanation: Sometimes it is more convenient to use a PreparedStatement object for sending SQL statements to the database. This special type of statement is derived from the more general class, Statement, that you already know. 

If you want to execute a Statement object many times, it usually reduces execution time to use a PreparedStatement object instead. 

The main feature of a PreparedStatement object is that, unlike a Statement object, it is given a SQL statement when it is created. The advantage to this is that in most cases, this SQL statement is sent to the DBMS right away, where it is compiled. As a result, the PreparedStatement object contains not just a SQL statement, but a SQL statement that has been precompiled. This means that when the PreparedStatement is executed, the DBMS can just run the PreparedStatement SQL statement without having to compile it first. 

Although PreparedStatement objects can be used for SQL statements with no parameters, you probably use them most often for SQL statements that take parameters. The advantage of using SQL statements that take parameters is that you can use the same statement and supply it with different values each time you execute it. 

Reference: The Java Tutorials, Using Prepared Statements 

Q23. Which statement is true about the take method defined in the WatchService interface? 

A. Retrieves and removes the next watch key, or returns null of none are present. 

B. Retrieves and removes the next watch key. If a queued key is not immediately available, the program waits for the specified wait time. 

C. Retrieves and removes the next watch key: waits if no key is yet present. 

D. Retrieves and removes all pending events for the watch key, returning a list of the events that were retrieved. 

Answer: C 

Explanation: The WatchKey take() method retrieves and removes next watch key, waiting if none are yet present. 

Note: A watch service that watches registered objects for changes and events. For example a file manager may use a watch service to monitor a directory for changes so that it can update its display of the list of files when files are created or deleted. A Watchable object is registered with a watch service by invoking its register method, returning a WatchKey to represent the registration. When an event for an object is detected the key is signalled, and if not currently signalled, it is queued to the watch service so that it can be retrieved by consumers that invoke the poll or take methods to retrieve keys and process events. Once the events have been processed the consumer invokes the key's reset method to reset the key which allows the key to be signalled and re-queued with further events. 

Reference: Interface WatchService 

Q24. Given the following code fragment: public class Calc { 

public static void main (String [] args) { 

//* insert code here Line ** 

System.out.print("The decimal value is" + var); 

Which three code fragments, when inserted independently at line **, enable the code to compile/ 

A. int var = 0b_1001; 

B. long var = 0b100_01L; 

C. float var = 0b10_01; 

D. float var = 0b10_01F; 

E. double var = 0b10_01; 

F. double var = 0b10_01D; 

Answer: B,C,E 

Explanation: B: output 17 

C: output 9.0 

E: output 9.0 

Not A: A _ character cannot begin a number. 

Not D: A float cannot be defined as a binary number (with literal B) 

Not F: A float cannot be defined as a decimal number (with literal D) 

Note 1: 

In Java SE 7 and later, any number of underscore characters (_) can appear anywhere 

between digits in a numerical literal. This feature enables you, for example. to separate 

groups of digits in numeric literals, which can improve the readability of your code. 

For instance, if your code contains numbers with many digits, you can use an underscore 

character to separate digits in groups of three, similar to how you would use a punctuation 

mark like a comma, or a space, as a separator. 

You can place underscores only between digits; you cannot place underscores in the 

following places: 

* At the beginning or end of a number (not A) 

* Adjacent to a decimal point in a floating point literal 

* Prior to an F or L suffix 

* In positions where a string of digits is expected 

Note 2: An integer literal is of type long if it ends with the letter L or l; otherwise it is of type int. It is recommended that you use the upper case letter L because the lower case letter l is hard to distinguish from the digit 1. 

Values of the integral types byte, short, int, and long can be created from int literals. Values of type long that exceed the range of int can be created from long literals. Integer literals can be expressed by these number systems: 

Decimal: Base 10, whose digits consists of the numbers 0 through 9; this is the number system you use every day Hexadecimal: Base 16, whose digits consist of the numbers 0 through 9 and the letters A through F Binary: Base 2, whose digits consists of the numbers 0 and 1 (you can create binary literals in Java SE 7 and later) 

Reference: The Java Tutorials, Primitive Data Types: 

Using Underscore Characters in Numeric Literals 

Integer Literals 

Q25. Which code fragments print 1? 

A. String arr [] = {"1", "2", "3"}; 

List <? extends String > arrList = new LinkedList <> (Arrays.asList (arr)); 

System.out.println (arrList.get (0)); 

B. String arr [] = {"1", "2", "3"}; 

List <Integer> arrList = new LinkedList <> (Arrays.asList (arr)); 

System.out.println (arrList.get (0)); 

C. String arr [] = {"1", "2", "3"}; 

List <?> arrList = new LinkedList <> (Arrays.asList (arr)); 

System.out.println (arrList.get (0)); 

D. String arr [] = {"1", "2", "3"}; 

List <?> arrList = new LinkedList <?> (Arrays.asList (arr)); 

System.out.println (arrList.get (0)); 

E. String arr [] = {"1", "2", "3"}; 

List <Integer> extends String > arrList = new LinkedList <Integer> (Arrays.asList (arr)); System.out.println (arrList.get (0)); 

Answer: A,C 


Note: You can replace the type arguments required to invoke the constructor of a generic class with an empty set of type parameters (<>) as long as the compiler can infer the type arguments from the context. This pair of angle brackets is informally called the diamond. 

1Z0-805  free exam

Refresh 1Z0-805 exam answers:

Q26. 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) { 


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. 

Answer: B 

Explanation: 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 updatable. 

Reference: The Java Tutorials, Interface ResultSet 

Q27. Given: 

public class SampleClass { 

public static void main(String[] args) { 

SampleClass sc = new SampleClass(); 


private void processCD() { 

try (CDStream cd = new CDStream()) { 





} catch (Exception e) { 

System.out.println("Exception thrown"); 

class CDStream { 

String cdContents = null; 

public void open() { 

cdContents = "CD Contents"; 

System.out.println("Opened CD stream"); 

public String read() throws Exception { 

throw new Exception("read error"); 

public void write(String str) { 

System.out.println("CD str is: " + str); 

public void close() { 

cdContents = null; 

What is the result? 

A. Compilation CD stream 

B. Opened CD thrown 

C. Exception thrown 

D. Opened CD stream CD str is: lullaby 

Answer: A 

Explanation: In this example the compilation of line " try (CDStream cd = new CDStream()) {" will fail, as try-with-resources not applicable to variable type CDStream. 

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 

Q28. Given a resource bundle MessageBundle, what is the name of the default bundle file? 

A. MessageBundle.profile 

B. MessageBundle.xml 

C. MessageBundle.java 

D. MessageBundle.properties 

Answer: D 

Explanation: A properties file is a simple text file. You should always create a default properties file. The name of this file begins with the base name of your ResourceBundle and ends with the .properties suffix. 

Reference: The Java Tutorials, Backing a ResourceBundle with Properties Files 

Q29. You have been asked to create a ResourceBundle file to localize an application. 

Which code example specifies valid keys of menu1 and menu2 with values of File Menu and View Menu? 

A. <Key name = “menu1”>File Menu</Key> <Key name = “menu2”>view Menu </Key> 

B. <Key>menu1</key><value>File Menu </value> <Key>menu2</key><value>View Menu </value> 

C. menu1, File Menu, menu2, View Menu 

D. menu1 = File Menu menu2 = View Menu 

Answer: D 

Explanation: A properties file is a simple text file. You can create and maintain a properties file with just about any text editor. 

You should always create a default properties file. The name of this file begins with the base name of your ResourceBundle and ends with the .properties suffix. 

An example of the contents of a ResourceBundle file: 

# This is a comment s1 = computer s2 = disk s3 = monitor s4 = keyboard 

Note that in the preceding file the comment lines begin with a pound sign (#). The other lines contain key-value pairs. The key is on the left side of the equal sign and the value is on the right. For instance, s2 is the key that corresponds to the value disk. The key is arbitrary. We could have called s2 something else, like msg5 or diskID. Once defined, however, the key should not change because it is referenced in the source code. The values may be changed. In fact, when your localizers create new properties files to accommodate additional languages, they will translate the values into various languages. 

Reference: The Java Tutorials, Backing a ResourceBundle with Properties Files 

Q30. Given: 


public Person(int id) 

public int getid() 

public String getContactDetails() 

public void setContactDetails(String contactDetails) 

public String getName() 

public void setName(String name) 

public Person getPerson(int id) throws Exception 

public void createPerson(int id) throws Exception 

public Person deletePerson(int id) throws Exception 

public void updatePerson(Person p) throws Exception 

Which group of methods is moved to a new class when implementing the DAO pattern? 

A. public int getId () 

public String getContractDetails () 

public void setContactDetails (String ContactDetails) 

public void getName () 

public Person setName (String name) 

B. public int getId () 

public String getContractDetails () 

public void getName () 

public person getPerson (int id) throws Exception 

C. public void setContactDetails(String contactDetails) 

public void setName (String name) 

D. public person getPerson(int id) throws Exception 

public void createPerson (person p) throws exception 

public void deleteperson(int id) throws Exception 

public void updatePerson (Person p) throws Exception 

Answer: D 

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)