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

2016 Apr 1Z0-804 Study Guide Questions:

Q41. Given the following code fragment: 

What is the result? 

A. Three 

B. One 

C. Compilation fails 

D. The program runs, but prints no outout 

Answer: B 

Explanation: 

add boolean add(E e) Inserts the specified element into the queue represented by this deque (in other words, at the tail of thisdeque) if it is possible to do so immediately without violating capacity restrictions, returning true uponsuccess and throwing an IllegalStateException if no space is currently available. When using acapacity-restricted deque, it is generally preferable to use offer. This method is equivalent to addLast(E). remove E remove() Retrieves and removes the head of the queue represented by this deque (in other words, the first element ofThisdeque). This method differs from poll only in that it throws an exception if this deque is empty. This method is equivalent to removeFirst(). Returns: Thehead of the queue represented by this deque Class ArrayDeque 


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

A. Locale loc1 = "UK"; 

B. Locale loc2 = Locale.getInstance("ru"); 

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

D. Locale loc4 = Locale.UK; 

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

Answer: D,E 

Explanation: 

The Locale class provides a number of convenient constants that you can use to create 

Locale objects forcommonly used locales. 

For example, the following creates a Locale object for the United States: 

Locale.US 

E: Create a Locale object using the constructors in this class: 

Locale(String language) 

Locale(String language, String country) 

Locale(String language, String country, String variant) 

Reference: java.utilClass Locale 


Q43. Given: 

What is the result? 

A. false \sales\quarter\ . . \qtrlreport.txt 

B. false \quarter\ . . \qtrlreport.txt 

C. true . . \ . . \ . . \ annualreport.txt 

D. true \ . . \ . . \annualreport.txt 

Answer: A 

Explanation: 

( richtig !! import java.nio.file.Path; import java.nio.file.Paths; ) original-Aufgabe war ( falsch >> import java.io.file.Path; import java.io.file.Paths; ) The relativize method that can be used to construct a relative path between two paths. relativize Path relativize(Path other) Constructs a relative path between this path and a given path. Parameters:other - the path to relativize against this path Returns:the resulting relative path, or an empty path if both paths are equal Note: Relativization is the inverse of resolution. This method attempts to construct a relative path that when resolvedagainst this path, yields a path that locates the same file as the given path. For18example, on UNIX, if this path is "/a/b" and the given path is "/a/b/c/d" then the resulting relative path would be"c/d". Where this path and the given path do not have a root component, then a relative path can beconstructed. A relative path cannot be constructed if only one of the paths have a root component. Where bothpaths have a root component then it is implementation dependent if a relative path can be constructed. If thispath and the given path are equal then an empty path is returned. For any two normalized paths p and q, where q does not have a root component,p.relativize(p.resolve(q)).equals(q) When symbolic links are supported, then whether the resulting path, when resolved against this path, yields apath that can be used to locate the same file as other is implementation dependent. For example, if this path is"/a/b" and the given path is "/a/x" then the resulting relative path may be "../x". If "b" is a symbolic link then isimplementation dependent if "a/b/../x" would locate the same file as "/a/x". 


1Z0-804 practice question

Improved java 1z0-804 books:

Q44. For which three objects must a vendor provide implementations in its JDBC driver? 

A. Time 

B. Date 

C. Statement 

D. ResultSet 

E. Connection 

F. SQLException 

G. DriverManager 

Answer: C,D,E 

Explanation: 

All JDBC drivers implement the four important JDBC classes: Driver, Connection, Statement, and ResultSet. 


Q45. The default file system includes a logFiles directory that contains the following files: 

Log-Jan 2009 

log_0l_20l0 

log_Feb20l0 

log_Feb2011 

log_10.2012 

log-sum-2012 

How many files does 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: B 

Explanation: 

The pattern to match is *???_*1? (regex ".*..._.*1.") 

This means at least three characters before the symbol _ , followed by any amount of 

characters. The next tolast character must be 1. The last character can by any character. 

The following file names match this pattern: 

log_Feb2011 

log_10.2012 Trap !! l is not 1 !! 


Q46. Given these facts about Java classes in an application: 

-

Class X is-a Class SuperX. 

-

Class SuperX has-a public reference to a Class Z. 

-

Class Y invokes public methods in Class Util. 

-

Class X uses public variables in Class Util. 

Which three statements are true? 

A. Class X has-a Class Z. 

B. Class Util has weak encapsulation. 

C. Class Y demonstrates high cohesion. 

D. Class X is loosely coupled to Class Util. 

E. Class SuperX's level of cohesion CANNOT be determined 

Answer: B,D,E 

Explanation: 

B: Has class Util has both public methods and variables, it is an example of weak 

encapsulation. 

Note:Inheritance is also sometimes said to provide "weak encapsulation," because if you 

have code thatdirectly uses a subclass, such as Apple, that code can be broken by 

changes to a superclass, such as Fruit. 

One of the ways to look at inheritance is that it allows subclass code to reuse superclass 

code. For example, if 

Apple doesn't override a method defined in its superclass 

Fruit, Apple is in a sense reusing Fruit's implementation of the method. But Apple only 

"weakly encapsulates"the Fruit code it is reusing, because changes to Fruit's interface can 

break code that directly uses Apple. 

D: 

Note:Tight coupling is when a group of classes are highly dependent on one another. 

This scenario arises when a class assumes too many responsibilities, or when one concern 

is spread overmany classes rather than having its own class. 

Loose coupling is achieved by means of a design that promotes single-responsibility and 

separation ofconcerns. 

A loosely-coupled class can be consumed and tested independently of other (concrete) 

classes. 

Interfaces are a powerful tool to use for decoupling. Classes can communicate through 

interfaces rather thanother concrete classes, and any class can be on the other end of that 

communication simply by implementingthe interface. 

E: Not enough information regarding SuperX' to determine the level of cohesion. 


1Z0-804 exam topics

Guaranteed oracle press 1z0-804:

Q47. Given: 

Which two classes correctly override the getDepth method? 

A. public class deep extends Deeper { 

protected Integer getDepth(){ 

return 5; 

}} 

B. public class deep extends Deeper { 

public Double getDepth() { 

return 5d; 

}} 

C. public class deep extends Deeper { 

public String getDepth () { 

}} 

D. public class deep extends Deeper { 

public Long getDepth (int d) { 

return 5L; 

}} 

E. public class deep extends Deeper { 

public Short getDepth () { 

return 5; 

}} 

Answer: A,E 

Explanation: 

Note: The abstract class Number is the superclass of classes Byte, Double, Float, Integer, Long, and Short. 

Subclasses of Number must provide methods to convert the represented numeric value to byte, double, float, int, long, and short. 

When class C extends B, we say that C is a "subclass" of B, and B is the "superclass" of C. This is called inheritence, because C inherited from B. 


Q48. Which is a factory method from the java.text.NumberFormat class? 

A. format (long number) 

B. getInstance() 

C. getMaxiraumFractionDigits () 

D. getAvailableLocales () 

E. isGroupingUsed() 

Answer: B 

Explanation: 

To obtain a NumberFormat for a specific locale, including the default locale, call one ofNumberFormat's factory methods, such as getInstance(). Reference:java.textClass DecimalFormat 


Q49. Given the code fragment: 

DateFormat df; 

Which statement defines a new Dateformat object that displays the default date format for the UK Locale? 

A. df = DateFormat.getDateInstance (DateFormat.DEFAULT, Locale (UK)); 

B. df = DateFormat.getDateInstance (DateFormat.DEFAULT, UK); 

C. df = DateFormat.getDateInstance (DateFormat.DEFAULT, Locale.UK); 

D. df = new DateFormat.getDateInstance (DateFormat.DEFAULT, Locale.UK); 

E. df = new DateFormat.getDateInstance (DateFormat.DEFAULT, Locale (UK)); 

Answer: C 

Explanation: 

The UK locale is constructed withLocale.UK. 

To format a date for a different Locale, specify it in the call to getDateInstance(). 

DateFormat df = 

DateFormat.getDateInstance(DateFormat.LONG, Locale.FRANCE); 

Note: getDateInstance( int style, Locale aLocale ) 

Gets the date formatter with the given formatting style for the given locale. 

Reference:Class DateFormat 


Q50. Assuming the port statements are correct, which two (three?) code fragments create a one-byte file? 

A. OutputStream fos = new FileOutputStream(new File("/tmp/data.bin")); OutputStream bos = new BufferedOutputStream(fos); DataOutputStream dos = new DataOutputStream(bos); dos.writeByte(0); dos.close(); 

B. OutputStream fos = new FileOutputStream ("/tmp/data.bin"); 

DataOutputStream dos = new DataOutputStream(fos); 

dos.writeByte(0); 

dos.close(); 

C. OutputStream fos = new FileOutputStream (new File ("/tmp/data.bin")); 

DataOutputStream dos = new DataOutputStream(fos); 

dos.writeByte(0); 

dos.close(); 

D. OutputStream fos = new FileOutputStream ("/tmp/data.bin"); fos.writeByte(0); 

fos.close(); 

Answer: A,B,C 

Explanation: 

B:Create DataOutputStream from FileOutputStream public static void main(String[] args) 

throws 

Exception { FileOutputStream fos = new FileOutputS tream("C:/demo.txt"); 

DataOutputStream dos = new 

DataOutputStream(fos); 

Note: 

The FileOutputStream class is a subclass of OutputStream. You can construct a 

FileOutputStream object by 

passing a string containing a path name or a File object. 

You can also specify whether you want to append the output to an existing file. 

public FileOutputStream (String path) 

public FileOutputStream (String path, boolean append) 

public FileOutputStream (File file) 

public FileOutputStream (File file, boolean append) 

With the first and third constructors, if a file by the specified name already exists, the file 

will be overwritten. Toappend to an existing file, pass true to the second or fourth 

constructor. 

Note 2:public class DataOutputStreamextends FilterOutputStreamimplements DataOutput 

A data output stream lets an application write primitive Java data types to an output stream 

in a portable way. 

An application can then use a data input stream to read the data back in. 

Reference:java.io Class DataOutputStream