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.

2021 May 1Z0-804 Study Guide Questions:

Q31. Given the code fragment: 

Why is there no output when otherMethod is called? 

A. An exception other than IOException is thrown. 

B. Standard error is not mapped to the console. 

C. There is a compilation error. 

D. The exception is suppressed. 

Answer: C 

Explanation: 

C: wenn printStackTrace() ohne Referenz auf das Exception object aufgerufen 

A : java.io.FileNotFoundException: wenn e.printStackTrace(); 

The code compiles fine 

The line 

FileInputStream fis = new FileInputStream(file)) 

will fail at runtime since file is an empty string. 

Note: 

public void printStackTrace() 

Prints this throwable and its backtrace to the standard error stream. 


Q32. Given the classes: What is the result? 

A. John Harry 

B. unknown Harry 

C. john unknown 

D. unknown unknown 

E. Compilation fails. 

F. An exception is thrown at runtime. 

Answer: B 

Explanation: 

getName() is missing in John, hence Pupils getName() is invoked and the String in Pupils scope returned. 


Q33. Given: 

ConcurrentMap <String, String> PartList = new ConcurrentMap<>(); 

Which fragment puts a key/value pair in partList without the responsibility of overwriting an existing key? 

A. partList.out(key,"Blue Shirt"); 

B. partList.putIfAbsent(key,"Blue Shirt"); 

C. partList.putIfNotLocked (key,"Blue Shirt"); 

D. partList.putAtomic(key,"Blue Shirt") 

E. if (!partList.containsKey(key)) partList.put (key,"Blue Shirt"); 

Answer: B 

Explanation: 

putIfAbsent(K key, V value) 

If the specified key is not already associated with a value, associate it with the given value. 

Reference:java.util.concurrent,Interface ConcurrentMap<K,V> 


2passeasy.com

Updated 1z0-804 exam preparation:

Q34. Given the code fragment: 

If the file userguide.txt does not exist, what is the result? 

A. An empty file iscreated and success is printed 

B. class java.io.FileNotFoundException 

C. class java.io.IOException 

D. class java.lang.Exception 

E. Compilation fails 

Answer: E 

Explanation: 

Compilation fails : Exception Exception is not compatible with throws clause in Base.process() IOExceptiondie Exception in der Derived Class Methode muss zur Base 

Class Methode passen. 


Q35. Given the code fragment: 

And a DOS-based file system: 

Which option, containing statement(s), inserted at line 3, creates the file and sets its attributes to hidden andread-only? 

A. DOSFileAttributes attrs = Files.setAttribute(file,"dos:hidden","dos: readonly") Files.createFile(file, attrs) 

B. Files.craeteFile(file); Files.setAttribute(file,"dos:hidden","dos:readonly"); 

C. Files.createFile(file,"dos:hidden","dos:readonly"); 

D. Files.createFile(file); Files.setAttribute(file,"dos:hidden", true); Files.setAttribute(file,"dos:readonly", true); 

Answer: D 

Explanation: 

You can set a DOS attribute using the setAttribute(Path, String, Object, LinkOption...) 

method, as 

follows: 

Path file = ...; 

Files.setAttribute(file, "dos:hidden", true); 

Note: 

setAttribute 

public static Path setAttribute(Path path, 

String attribute, 

Object value, 

LinkOption... options) 

throws IOException 

Sets the value of a file attribute. 

Reference:Interface DosFileAttribute 


Q36. Given: 

What is the result? 

A. Cue sports, Cue sports 

B. Compilation fails at line 9 

C. Compilation fails at line 11 

D. Compilation fails at line 12 

E. Compilation fails at line 13 

Answer: B 

Explanation: 

Class Snooker is public. Should be declared in a separate file. // Line 9 getCategory() >>> GetCategory() Line 13 


2passeasy.com

Precise java exam 1z0-804:

Q37. Given: What is the result? 

A. 1 

B. 0 

C. 2 

D. Compilation fails 

E. An exception is thrown at runtime 

Answer: E 

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. 


Q38. Which four are true about enums? 

A. An enum is typesafe. 

B. An enum cannot have public methods or fields. 

C. An enum can declare a private constructor. 

D. All enums implicitly implement Comparable. 

E. An enum can subclass another enum. 

F. An enum can implement an interface. 

Answer: A,C,D,F Explanation: 

C: The constructor for an enum type must be package-private or private access. Reference: Java Tutorials,Enum Types 


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


Q40. 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: D 

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