1Z0-804 Exam - Java SE 7 Programmer II Exam

certleader.com

Q1. When using the default file system provider with a JVM running on a DOS-based file system, which statementis true? 

A. DOS file attributes can be read as a set in a single method call. 

B. DOS file attributes can be changed as a set in a single method call. 

C. DOS file attributes can be modified for symbolic links and regular files. 

D. DOS file attributes can be modified in the same method that creates the file. 

Answer:

Explanation: 

File attributes associated with a file in a file system that supports legacy "DOS" attributes. 

Usage Example: 

Path file = ... 

DosFileAttributes attrs = Files.readAttributes(file, DosFileAttributes.class); 

Note: 

The methodreadAttributes() reads a file's attributes as a bulk operation. 

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

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 

Q3. Select four examples that initialize a NumberFormat reference using a factory. 

A. NumberFormat nf1 = new DecimalFormat(); 

B. NumberFormat nf2 = new DecimalFormat("0.00") ; C. NumberFormat nf3 = NumberFormat.getInstance(); 

D. NumberFormat nf4 = NumberFormat.getIntegerInstance(); 

E. NumberFormat nf5 = DecimalFormat.getNumberInstance (); 

F. NumberFormat nf6 = NumberFormat.getCurrencyInstance () ; 

Answer: C,D,E,F 

Explanation: 

getInstance 

public static finalNumberFormatgetInstance() 

Returns the default number format for the current default locale. The default format is one 

of the styles 

provided by the other factory methods: getNumberInstance(E), getIntegerInstance(D), 

getCurrencyInstance(F) 

or getPercentInstance. Exactly which one is locale dependant. 

C: To obtain a NumberFormat for a specific locale, including the default locale, call one of NumberFormat'sfactory methods, such as getInstance(). E:To obtain standard formats for a given locale, use the factory methods on NumberFormat such asgetNumberInstance. These factories will return the most appropriate sub-class of NumberFormat for a givenlocale. F:To obtain standard formats for a given locale, use the factory methods on NumberFormat such asgetInstance or getCurrencyInstance. 

Reference:java.textClass NumberFormat 

Q4. Given the two Java classes: 

Which two code snippets, added independently at line ***, can make the Buzzword class compile? 

A. this (); 

B. this (100); 

C. this ("Buzzword"); 

D. super (); 

E. super (100); 

F. super ("Buzzword"); 

Answer: C,F 

Q5. Given: 

What is the result? 

A. 5 

B. 6 

C. An exception is thrown at runtime 

D. Compilation fails due to an error on line 6 

E. Compilation fails due to an error on line 7 

Answer:

Explanation: 

The code compile fine but java.lang.NullPointerException is thrown at runtime. 

x has no value. The code would run if line 2 was changed to: 

Integer x = 3; 

Q6. Given: 

What is the result? 

A. fast slow 

B. fast goes 

C. goes goes 

D. fast fast 

E. fast followed by an exception 

F. Compilation fails 

Answer:

Explanation: 

Line:Vehicle v = new Sportscar(); 

causes compilation failure: 

error: cannot find symbol 

Vehicle v = new Sportscar(); 

symbol: class Sportscar 

location: class VehicleTest 

Q7. Given: 

Which two statements are true about the writer class? 

A. It compiles without any changes. 

B. It compiles if the code void write (String s); is added at line***. 

C. It compiles if the code void write (); is added at line ***. 

D. It compiles if the code void write (string s) { } is added at line ***. 

E. It compiles if the code write () {}is added at line ***. 

Answer:

Explanation: 

An abstract class does not need to implement the interface methods. 

Q8. Given: 

Which two are true about the lines labeled A through D? 

A. The code compiles and runs as is. 

B. If only line A is removed, the code will compile and run. 

C. If only line B is removed, the code will compile and run. 

D. If only line D is removed, the code will compile and run. 

E. Line C is optional to allow the code to compile and run. 

F. Line C is mandatory to allow the code to compile andrun. 

Answer: A,E Explanation: 

A: The code will compile. The abstract method doDock() is implemented fine, and doFloat() isoverridden. 

E: Line C overrides the implementation of doFloat(). This is optional. 

Q9. Which method would you supply to a class implementing the Callable interface? 

A. callable () 

B. executable () 

C. call () 

D. run () 

E. start () 

Answer:

Explanation: 

public interface Callable<V> 

A task that returns a result and may throw an exception. Implementors define a single 

method with noarguments called call. 

Note: 

Interface Callable<V> 

Type Parameters: 

V - the result type of method call 

The Callable interface is similar to Runnable, in that both are designed for classes whose 

instances arepotentially executed by another thread. A Runnable, however, does not return 

a result and cannot throw achecked exception. 

The Executors class contains utility methods to convert from other common forms to 

Callable classes. 

Reference:java.util.concurrent 

Q10. Given: 

What is the result of invoking Car's scop method? 

A. Both vehicles and Motorized's stop methods are invoked. 

B. Vehicles stop method is invoked. 

C. Motorized's stop method is invoked-

D. The implementation of the Car's stop determines the behavior. 

E. Compilation fails. 

Answer:

Explanation: 

The Car class is implementing the methods. Methods are not implemented in interfaces.