1Z0-805 | Most up-to-date 1Z0-805 Exam Study Guides With New Update Exam Questions


Q31. Given the code fragment: 

public static void processFile () throws IOException { 

Try (FileReader fr = new FileReader ("logfilesrc.txt"); 

FileWriter fw = new FileWriter ("logfilesdst.txt") ) { 

int i = fr.read(); 

Which statement is true? 

A. The code fragment contains compilation errors. 

B. The java runtime automatically closes the FileWriter Instance first and the FileReader instance next. 

C. The java runtime automatically closes the FileReader Instance first and the FileWriter instance next. 

D. The developer needs to close the FileReader instance first and the FileWriter instance explicitly in a catch block. 

E. The Java runtime may close the FileReader and FileWriter instance in an intermediate manner. Developers should not rely on the order in which they are closed. 

Answer:

Explanation: 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 implementjava.io.Closeable, can be used as a resource. 

Reference: The Java Tutorials, The try-with-resources Statement 

Q32. Given: 

public class MyGrades { 

private final List<Integer> myGrades = new ArrayList<Integer>(); 

private final ReadWriteLock rwlock = new ReentrantReadWriteLock(); 

public void addGrade(Integer grade) { 

/* 

lock and modify 

*/ 

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 line ** and line *** (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. rwlock.WriteLock().acquire(); rwlock.writeLock().release(); 

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

Answer:

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 

Q33. Given the code fragment: 

SimpleDateFormat sdf = new SimpleDateFormat("zzzz", Locale.US); 

System.out.println ("Result: " + sdf.format(today) ) ; 

What type of result is printed? 

A. Time zone abbreviation 

B. Full-text time zone name 

C. Era 

D. Julian date 

E. Time of the Epoch (in milliseconds) 

Answer:

Q34. Given: 

ConcurrentMap<String, String> partList = new ConcurrentHashMap<> (); 

Which fragment puts a key/value pair in partList without the possibility of overwriting an existing key? 

A. partList.put (key, "Blue Shirt"); 

B. partList.putAbsent(key, "Blu Shirt") 

C. partList.putIfNotLocked (key, "Blue Shirt"); 

D. partList.putAtomic (key, "Blue Shirt"); 

E. if (!partlist.containsKey(key)) partList.put(key, "Blue Shirt"); 

Answer:

Explanation: The containsKey method returns true if this map maps one or more keys to 

the specified value. 

So this statement adds a new key if they key is not present. 

Reference: Class ConcurrentHashMap<K,V> 

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

Answer:

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

Q36. Given the following code fragment: 

public static void getInfo() { 

//insert code here 

List fontCatalog = new ArrayList(); 

fontCatalog.add("Algerian"); 

fontCatalog.add("Cambria"); 

fontCatalog.add("Lucida Bright"); 

category.put("firstCategory",fontCatalog); 

List entrySet = new ArrayList(category.entrySet()); 

Iterator it = entrySet.iterator(); 

while(it.hasNext()) { 

System.out.println(it.next)); 

Which two code fragments, when inserted independently at line **, enable the code to compile? 

A. Map<String, List<String>> category = new HashMap<List> (); 

B. Map<String, List<String>> category = new HashMap<<>,List<>>(); 

C. Map<String, List<String>> category = new HashMap<> (); 

D. Map<String, List<String>> category = new HashMap <String, ArrayList<String>> (); 

E. Map<String, List<String>> category = new HashMap<String, List<String>> (); 

F. Map<String, List<String>> category = new HashMap<String, List <>> (); 

Answer: C,E 

Explanation: E: Redundant type arguments in new expressions. Use diamond operator instead. 

Q37. What are two benefits of a Factory design pattern? 

A. Eliminates direct constructor calls in favor of invoking a method 

B. Provides a mechanism to monitor objects for changes 

C. Eliminates the need to overload constructors in a class implementation 

D. Prevents the compile from complaining about abstract method signatures 

E. Prevents tight coupling between your application and a class implementation 

Answer: A,E 

Explanation: Factory methods are static methods that return an instance of the native 

class. 

Factory methods : 

* have names, unlike constructors, which can clarify code. 

* do not need to create a new object upon each invocation - objects can be cached and reused, if necessary. 

* can return a subtype of their return type - in particular, can return an object whose implementation class is unknown to the caller. This is a very valuable and widely used feature in many frameworks which use interfaces as the return type of static factory methods. 

Note: The factory pattern (also known as the factory method pattern) is a creational design pattern. A factory is a JavaSW class that is used to encapsulate object creation code. A factory class instantiates and returns a particular type of object based on data passed to the factory. The different types of objects that are returned from a factory typically are subclasses of a common parent class. The data passed from the calling code to the factory can be passed either when the factory is created or when the method on the factory is called to create an object. This creational method is often called something such as getInstance or getClass . 

Q38. View the Exhibit: 

Given the following code fragment: 

class Finder extends SimpleFileVisitor<Path> { 

private final PathMatcher matcher; 

private static int numMatches = 0; 

Finder() { 

matcher = FileSystems.getDefault().getPathMatcher("glob:*java"); 

void find(Path file) { 

Path Name = file.getFileName(); 

if (name != null && matcher.matches(name)) { 

numMatches++; 

void report() 

System.out.println("Matched: " + numMatches); 

@Override 

public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) { 

find(file); 

return CONTINUE; 

public class Visitor { 

public static void main(String[] args) throws IOException { 

Finder finder = new Finder(); 

Files.walkFileTree(Paths.get("d:\Project"), finder); 

finder.report(); 

What is the result? 

A. Compilation fails 

B. 6 

C. 4 

D. 1 

E. 3 

Answer:

Explanation: The program will compile and run. 

Referring to the exhibit there will be six nodes that matches glob:*java. 

Q39. 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:

Q40. What is the minimum SQL standard that a JDBC API implementation must support? 

A. SQL-92 

B. SQL 99 

C. SQL-2003 

D. JDBC 4.0 

Answer:

Explanation: JDBC sets minimum SQL conformance to the SQL92 entry level SQL standard. This gives guaranteed wide portability for applications designed to run on many platforms.