Exam Code: 1Z0-805 (Practice Exam Latest Test Questions VCE PDF)
Exam Name: Upgrade to Java SE 7 Programmer
Certification Provider: Oracle
Free Today! Guaranteed Training- Pass 1Z0-805 Exam.

2016 Oct 1Z0-805 latest exam

Q31. In the Java SE7 API, which method is most commonly used by factories to instantiate objects? 

A. new () 

B. make () 

C. create () 

D. getObject () 

E. getInstance () 

F. createObject () 

Answer: E 

Explanation: For example: KeyFactory.getInstance, ObjectFactory. getObjectInstance. 


Q32. Given the code format: 

SimpleDateFormat sdf; 

Which code statements will display the full text month name? 

A. sdf = new SimpleDateFormat ("mm", Locale.UK); System.out.println ( "Result: " + sdf.format(new Date())); 

B. sdf = new SimpleDateFormat ("MM", Locale.UK); System.out.println ( "Result: " + sdf.format(new Date())); 

C. sdf = new SimpleDateFormat ("MMM", Locale.UK); System.out.println ( "Result: " + sdf.format(new Date())); 

D. sdf = new SimpleDateFormat ("MMMM", Locale.UK); System.out.println ( "Result: " + sdf.format(new Date())); 

Answer: D 

Explanation: To get the full length month name use SimpleDateFormat('MMMM'). Note: SimpleDateFormat is a concrete class for formatting and parsing dates in a locale-sensitive manner. It allows for formatting (date -> text), parsing (text -> date), and normalization. SimpleDateFormat allows you to start by choosing any user-defined patterns for date-time formatting. However, you are encouraged to create a date-time formatter with either getTimeInstance, getDateInstance, orgetDateTimeInstance in DateFormat. Each of these class methods can return a date/time formatter initialized with a default format pattern. You may modify the format pattern using the applyPattern methods as desired. 


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


Q34. Which is a key aspect of composition? 

A. Using inheritance 

B. Method delegation 

C. Creating abstract classes 

D. Implementing the composite interface 

Answer: B 

Explanation: In an object-oriented design of a Java program, the way in which you model objects that contain other objects is with composition, the act of composing a class out of references to other objects. With composition, references to the constituent objects become fields of the containing object. To use composition in Java, you use instance variables of one object to hold references to other objects. The relationship modeled by composition is often referred to as the "has-a" relationship. Delegation involves re-exporting methods; in a composition relationship, the inner objects methods may be used only privately and not re-exposed. 


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


certifyforall.com

Replace 1Z0-805 exam:

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. Given the code fragment: 

SimpleDateFormat sdf; 

Which code fragment displays the three-character month abbreviation? 

A. sdf = new SimpleDateFormat ("mm", Locale.UK); System.out.println ("Result: " + sdf.format(new Date())); 

B. sdf = new SimpleDateFormat (“MM”, Locale.UK); System.out.println ("Result: " + sdf.format(new Date())); 

C. sdf = new SimpleDateFormat (“MMM”, Locale.UK); System.out.println ("Result: " + sdf.format(new Date())); 

D. sdf = new SimpleDateFormat (“MMMM”, Locale.UK); System.out.println ("Result: " + sdf.format(new Date())); 

Answer: C 

Explanation: C: Output example: Apr 

Note: SimpleDateFormat is a concrete class for formatting and parsing dates in a locale-sensitive manner. It allows for formatting (date -> text), parsing (text -> date), and normalization. SimpleDateFormat allows you to start by choosing any user-defined patterns for date-time formatting. However, you are encouraged to create a date-time formatter with either getTimeInstance, getDateInstance, orgetDateTimeInstance in DateFormat. Each of these class methods can return a date/time formatter initialized with a default format pattern. You may modify the format pattern using the applyPattern methods as desired. 


Q38. Given the code fragment: public static void main(String[] args) { 

String source = "d:\\company\\info.txt"; 

String dest = "d:\\company\\emp\\info.txt"; 

//insert code fragment here Line ** 

} catch (IOException e) { 

System.err.println ("Caught IOException: " + e.getmessage(); 

Which two try statements, when inserted at line **, enable the code to successfully move the file info.txt to the destination directory, even if a file by the same name already exists in the destination directory? 

A. try {FileChannel in = new FileInputStream(source).getChannel(); 

FileChannel out = new FileOutputStream(dest).getChannel (); 

in.transferTo (0, in.size(), out); 

B. try {Files.copy(Paths.get(source), Paths.get(dest)); 

Files.delete(Paths.get(source)); 

C. try {Files.copy(Paths.get(source), Paths.get(dest)); 

Files.delete(Paths.get(source)); 

D. try {Files.move (Paths.get(source), Paths.get(dest)); 

E. try {BufferedReader br = Files.newBufferedReader(Paths.get(source), Charset.forName 

("UTF-8")); 

BufferedWriter bw = Files.newBufferedWriter (Paths.get(dest), Charset.forName ("UTF-

8")); 

String record = ""; 

while ((record = br.readLine()) != null){ 

bw.write (record); 

bw.newLine(); 

Files.delete(Paths.get(source)); 

Answer: B,D 


Q39. Which is true regarding the java.nio.file.Path Interface? 

A. The interface extends WatchService interface 

B. Implementations of this interface are immutable. 

C. Implementations of this interface are not safe for use by multiple concurrent threads. 

D. Paths associated with the default provider are not interoperable with the java.io.File class. 

Answer: A 

Explanation: The java.nio.file.Path interface extends Watchable interface so that a directory located by a path can be registered with a WatchService and entries in the directory watched. 

Note: An object that may be used to locate a file in a file system. It will typically represent a system dependent file path. A Path represents a path that is hierarchical and composed of a sequence of directory and file name elements separated by a special separator or delimiter. A root component, that identifies a file system hierarchy, may also be present. The name element that is farthest from the root of the directory hierarchy is the name of a file or directory. The other name elements are directory names. A Path can represent a root, a root and a sequence of names, or simply one or more name elements. A Path is considered to be an empty path if it consists solely of one name element that is empty. Accessing a file using an empty path is equivalent to accessing the default directory of the file system. Path defines the getFileName, getParent, getRoot, and subpath methods to access the path components or a subsequence of its name elements. 

Reference: java.nio.file.Path Interface 


Q40. Given: 

Person 

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)