1Z0-804 | how many questions of 1Z0-804 pdf?


Q71. Which statement declares a generic class? 

A. public class Example < T > { } 

B. public class <Example> { } 

C. public class Example <> { } 

D. public class Example (Generic) { } 

E. public class Example (G) { } 

F. public class Example { } 

Answer:

Explanation: 

Example: 

public class Pocket<T> 

private T value; 

public Pocket() {} 

public Pocket( T value ) { this.value = value; } 

public void set( T value ) { this.value = value; } 

public T get() { return value; } 

public boolean isEmpty() { return value != null; } 

public void empty() { value = null; } 

Q72. Given: 

String s = new String("3"); 

System.out.print(1 + 2 + s + 4 + 5); 

What is the result? 

A. 12345 

B. 3345 

C. 1239 

D. 339 

E. Compilation fails. 

Answer:

Explanation: 

1 and 2 are added. 

Then the string s is concatenated. 

Finally 3 and 4 are concatenated as strings. 

Q73. Given the following files in doc directory: -Index.htm 

-Service.html 

-Logo.gif 

-Title.jpg 

And the code fragment: 

What is the result, if doc is present in the current directory? 

A. No output is produced. 

B. index.htm 

C. index.htm userguide.txt logo.gif 

D. index.htm service.html userguide.txt logo.gif 

Answer:

Explanation: 

The Glob search expression is defined through "glob:*.htm, html, xml" The correct answer is A The glob is trying to match all the string. The correct way is 

glob:*.{htm,html,xml} 

and then would be found: 

Index.htm 

Service.html 

Q74. Given: 

From what threading problem does the program suffer? 

A. deadlock 

B. livelock 

C. starvation D. race condition 

Answer:

Explanation: 

A thread often acts in response to the action of another thread. If the other thread's action is also a response tothe action of another thread, then livelock may result. As with deadlock, livelocked threads are unable to makefurther progress. 

However, the threads are not blocked -- they are simply too busy responding to each other to resume work. This is comparable to two people attempting to pass each other in a corridor: Alphonse moves to his left to let Gaston pass, while Gaston moves to his right to let Alphonse pass. Seeing that they are still blocking eachother, Alphone moves to his right, while Gaston moves to his left. They'restill blocking each other, so. 

Q75. Given: What is the result? 

A. 1 

B. 0 

C. 2 

D. Compilation fails 

E. An exception is thrown at runtime 

Answer:

Explanation: Section: (none) 

Explanation 

The code compiles fine. 

java.lang.NullPointerException 

because only one element of list is initialized : element [0] 

elements [1] and [2] equals null 

alte Begründung: 

An exception is thrown at runtime due to data type comparison mismatch: 

Exception in thread "main" java.lang.ClassCastException: java.lang.String cannot be cast 

to java.lang.Integer 

at java.lang.Integer.compareTo(Integer.java:52) 

at java.util.Arrays.binarySearch0(Arrays.java:1481) 

at java.util.Arrays.binarySearch(Arrays.java:1423) 

at searchtext.SearchText.main(SearchText.java:22) 

Note:binarySearch 

public static int binarySearch(char[] a, 

char key)Searches the specified array of chars for the specified value using the binary 

search algorithm. The array mustbe sorted (as by the sort method, above) prior to making 

this call. If it is not sorted, the results are undefined. Ifthe array contains multiple elements 

with the specified value, there is no guarantee which one will be found. 

Parameters: 

a - the array to be searched. 

key - the value to be searched for. 

Returns: 

Indexof the search key, if it is contained in the list; otherwise, (-(insertion point) - 1). The 

insertionpoint is defined as the point at which the key would be inserted into the list: the 

index of the first elementgreater than the key, or list.size(), if all elements in the list are less 

than the specified key. Note that thisguarantees that the return value will be >= 0 if and 

only if the key is found. 

Q76. Given the following code fragment: 

10. 

p1 = paths.get("report.txt"); 

11. 

p2 = paths.get("company"); 

12. 

/ / insert code here 

Which code fragment, when inserted independently at line 12, move the report.txt file to the company directory,at the same level, replacing the file if it already exists? 

A. Files.move(p1, p2, StandardCopyOption.REPLACE_EXISTING, 

StandardCopyOption.ATOMIC_MOVE); 

B. Files.move(p1, p2, StandardCopyOption.REPLACE_Existing, 

LinkOption.NOFOLLOW_LINKS); 

C. Files.move(p1, p2, StandardCopyOption.REPLACE_EXISTING, 

LinkOption.NOFOLLOW_LINKS); 

D. Files.move(p1, p2, StandardCopyOption.REPLACE_EXISTING, 

StandardCopyOption.copy_ATTRIBUTES, 

StandrardCopyOp) 

E. Files.move (p1, p2, StandardCopyOption.REPLACE_EXISTING, 

StandardCopyOption.copy_ATTRIBUTES, 

LinkOption.NOF) 

Answer: A,C 

Explanation: 

Moving a file is equally as straight forward move(Path source, Path target, CopyOption... options); The available StandardCopyOptions enums available are: StandardCopyOption.REPLACE_EXISTING StandardCopyOption.ATOMIC_MOVE If Files.move is called with StandardCopyOption.COPY_ATTRIBUTES an UnsupportedOperationException isthrown. 

Q77. Given the code fragment: 

Which three are true? 

A. On line 3, the current thread stops and waits until the t1 thread finishes. 

B. On line 3, the t1 thread stops and waits until the current thread finishes. 

C. On line 4, the t1 thread is dead. 

D. On line 4, the t1 thread is waiting to run. 

E. This code cannot throw a checked exception. 

F. This code may throw a checked exception. 

Answer: A,C,F 

Explanation: 

Thejoin()methods waits for this thread to die. 

Q78. Given the code fragment: 

Assume the method printNums is passed a valid array containing data. Why is this method not producingoutput on the console? 

A. There is a compilation error. 

B. There is a runtime exception. 

C. The variable number is not initialized. 

D. Standard error is mapped to another destination. 

Answer:

Explanation: 

The code compiles fine. 

The code runs fine. 

The errorstream can be redirected. 

Note: 

System.out.println -> Sends the output to a standard output stream. Generally monitor. 

System.err.println -> Sends the output to a standard error stream. Generally monitor. err is 

the "standard" erroroutput stream. This stream is already open and ready to accept output 

data. 

Typically this stream corresponds to display output or another output destination specified 

by the hostenvironment or user. By convention, this output stream is used to display error 

messages or other informationthat should come to the immediate attention of a user even if the principal output stream, the value of thevariable out, has been redirected to a file or other destination that is typically not continuously monitored. 

Reference:java.lang.System 

Q79. Given the fragment: 

If thread a and thread b are running, but not completing, which two could be occurring? 

A. livelock 

B. deadlock 

C. starvation 

D. loose coupling 

E. cohesion 

Answer: A,B 

Explanation: 

A: A thread often acts in response to the action of another thread. If the other thread's action is also a responseto the action of another thread, then livelock may result. A thread often acts in response to the action ofanother thread. If the other thread's action is also a response to the action of another thread, then livelock mayresult. 

B: Deadlock describes a situation where two or more threads are blocked forever, waiting for each other. 

Q80. Given the code fragment: 

What is the result? 

A. Java 7 

B. Java 6 

C. Java 7, Java 6 

D. Java 7 java 6 

E. Java 

Answer:

Explanation: 

regex: Java / one or more anything !!! / ends with a digit so it is the source string