how many questions of 1Z0-805 dumps?
Precise of 1Z0-805 test preparation materials and preparation labs for Oracle certification for customers, Real Success Guaranteed with Updated 1Z0-805 pdf dumps vce Materials. 100% PASS Upgrade to Java SE 7 Programmer exam Today!
2023 Oracle Official New Released 1Z0-805 ♥♥
https://www.certleader.com/1Z0-805-dumps.html
Q1. Given the code fragment:
/* method declaration */ {
try {
String className = "java.lang.String";
String fieldname = "somefield";
Class c = Class.forName(className);
Field f = c.getField(fieldname);
} catch(Exception e) {
e.printStackTrace();
throw e;
}
}
Which two method declarations are valid options to replace /* method declaration */?
A. public void getMetadata ()
B. public void getMetadat ()
C. public void getMetadata () throws Exception
D. public void getMetadata () throws NoSuchFieldException
E. public void getMetadata () throws classNotFoundException
F. public void getMetadata () throws ClassNotFoundException, NoSuchFieldException.
Answer: C,F
Explanation: We must specify that the getMetaData method can throw both ClassNotFoundException (line Class c = Class.forName(className);) and a NoSuchFieldException (line Field f = c.getField(fieldname);). We can do this by either declare that all exception can be thrown or that these two specific exceptions can be thrown
Note: Valid Java programming language code must honor the Catch or Specify Requirement. This means that code that might throw certain exceptions must be enclosed by either of the following:
* A try statement that catches the exception. The try must provide a handler for the exception.
* A method that specifies that it can throw the exception. The method must provide a throws clause that lists the exception.
Code that fails to honor the Catch or Specify Requirement will not compile.
Reference: The Java Tutorials, The Catch or Specify Requirement
Q2. The default file system includes a logFiles directory that contains the following files:
log – Jan2009
log_01_2010
log_Feb2010
log_Feb2011
log-sum-2012
How many files the matcher in this fragment match?
PathMatcher matcher = FileSystems.getDefault ().getPathMatcher ("glob:???_*1");
A. One
B. Two
C. Three
D. Four
E. Five
F. Six
Answer: A
Explanation: The glob pattern is: any three characters, followed by _ ,followed by any
number of characters, and ending with a 1.
Only log_Feb2011 matches this pattern.
Note:
You can use glob syntax to specify pattern-matching behavior.
A glob pattern is specified as a string and is matched against other strings, such as directory or file names. Glob syntax follows several simple rules:
* An asterisk, *, matches any number of characters (including none).
** Two asterisks, **, works like * but crosses directory boundaries. This syntax is generally
used for matching complete paths.
* A question mark, ?, matches exactly one character.
* Braces specify a collection of subpatterns. For example:
{sun,moon,stars} matches "sun", "moon", or "stars."
{temp*,tmp*} matches all strings beginning with "temp" or "tmp."
* Square brackets convey a set of single characters or, when the hyphen character (-) is
used, a range of characters. For example:
[aeiou] matches any lowercase vowel.
[0-9] matches any digit.
[A-Z] matches any uppercase letter.
[a-z,A-Z] matches any uppercase or lowercase letter.
* Within the square brackets, *, ?, and match themselves.
*All other characters match themselves.
* To match *, ?, or the other special characters, you can escape them by using the
backslash character, . For example: \ matches a single backslash, and ? matches the
question mark.
Reference: The Java Tutorials
Finding Files
What Is a Glob?
Q3. 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 .
Q4. Given the code fragment:
11.
public static getFileSize () throws IOException {
12.
path file = paths.get ("ex.txt");
13.
//insert code here
14.
System.out.println ("size: " + attr.size());
15.
}
public static getFileSize () throws IOException {
Path file = Paths.get ("ex.txt");
//insert code here Line **
System.out.println ("size: " + attr.size());
}
Which two fragments, when inserted independently at line **, enable printing of the file size?
A. BasicFileAttributes attr = Files.readAttributes (file, BasicFileAttributes.class);
B. PosixFileAttributes attr = Files.readAttributes (file, posixFileAttributes.class);
C. DosFileAttributes attr = Files.readAttributes (file, dosAttributes.class);
D. FileStore attr = Files.getFileStore (file);
E. AclFileAttributeview attr = Files.getFileAttributeView(File, AclFileAttributeview.class);
Answer: A,B
Explanation: A: The BasicFileAttributes has a size method.
B: The PosixFileAttributes has a size method.
Q5. 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: A
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.
Q6. 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.
Q7. 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: B
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
Q8. 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.
Q9. Given this code fragment:
ResultSet rs = null;
try (Connection conn = DriverManager. getConnection (url) ) {
Statement stmt = conn.createStatement();
rs stmt.executeQuery(query);
//-.. other methods }
} catch (SQLException se) {
System.out.println ("Error");
}
Which object is valid after the try block runs?
A. The Connection object only
B. The Statement object only
C. The Result set object only
D. The Statement and Result Set object only
E. The connection, statement, and ResultSet objects
F. Neither the Connection, Statement, nor ResultSet objects
Answer: C
Explanation: Generally, JavaScript has just 2 levels of scope: global and function. But, try/catch is an exception (no punn intended). When an exception is thrown and the exception object gets a variable assigned to it, that object variable is only available within the "catch" section and is destroyed as soon as the catch completes.
Q10. 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
Answer: C,F,G
Explanation: 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 pattern belongs 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.