Exambible offers free demo for 1Z0-804 exam. "Java SE 7 Programmer II Exam", also known as 1Z0-804 exam, is a Oracle Certification. This set of posts, Passing the Oracle 1Z0-804 exam, will help you answer those questions. The 1Z0-804 Questions & Answers covers all the knowledge points of the real exam. 100% real Oracle 1Z0-804 exams and revised by experts!

Q1. Given the code fragment: 

What is the result? 

A. M001, , 

B. M001, null, null 

C. M001, Sam, 

D. M001, Sam, null 

E. M001, Sam, ABC Inc (Frage unvolst.ndig!!!) 

F. Compilation fails 

G. A NullPointerException is thrown at runtime 

Answer:


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


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


Q4. 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; 


Q5. Which class(es) safely protects the doIt () method from concurrent thread access? A. Option A 

B. Option B 

C. Option C 

D. Option D 

Answer: A,D 

Explanation: 

only A und D possible 

It should be pointed out that: 

public void blah() { 

synchronized (this) { 

// do stuff 

}} 

is semantically equivalent to: 

public synchronized void blah() { 

// do stuff 

Incorrect answer: 

B: A constructor cannot be synchronized. () Object cannot be resolved to a type 

C: in static context (static void main !) no reference to this possible 


Q6. Give: What is the likely result? 

A. The program produces the correct result, with similar performance to the original. 

B. The program produces the correct result, with performance degraded to the equivalent of being singlethreaded. 

C. The program produces an incorrect result. 

D. The program goes into an infinite loop. 

E. An exception is thrown at runtime. 

F. The program produces the correct result, with better performance than the original. 

Answer:

Explanation: 

join() does not proceed until the task's result has been computed. Here we start to wait beforedoing the computing. The code will not finish. 


Q7. How many Threads are created when passing task to an Executor instance? 

A. A new Thread is used for each task. 

B. A number of Threads equal to the number of CPUs Is used to execute tasks. 

C. A single Thread Is used to execute all tasks. 

D. A developer-defined number of Threads is used to execute tasks. 

E. A number of Threads determined by system load is used to execute tasks. 

F. The method used to obtain the Executor determines how many Threads are used to execute tasks. 

Answer:

Explanation: 

The Executor interface provides a single method, execute, designed to be a drop-in replacementfor a common thread-creation idiom. If r is a Runnable object, and e is an Executor object you can replace(new Thread(r)).start(); 

with e.execute(r); However, the definition of execute is less specific. The low-level idiom creates a new thread and launches it immediately. Depending on the Executor implementation, execute may do the same thing, but is more likely to use an existing worker thread to run r, or to place r in a queue to wait for a worker thread to become available. 

Reference: The Java Tutorial,The Executor Interface 


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


Q9. Given the code fragment: What is the result when infected() is invoked? 

A. before try catch finally after 

B. before catch finally after 

C. before catch after 

D. before catch finally 

E. before catch 

Answer:

Explanation: 

The following line throws and exception: 

int i = 1/0; 

This exception is caught by: 

catch(Exception e) { 

System.out.print("catch "); 

throw e; 

Lastly, the finally statement is run as the finally block always executes when the try block 

exits. This ensuresthat the finally block is executed even if an unexpected exception 

occurs. 

Reference: Java Tutorial,The finally Block 


Q10. Given that myFile.txt contains: 

What is the result? 

A. 1: First 

2: Second 

3:

 Third 

B. 

1: First 

2: Second 

3:

 First 

C. 

1: First 

2: First 

3:

 First 

D. 

IOExcepton 

E. 

Compilation fails 

Answer:

Explanation: 

BufferedReader: mark() : Marks the present position in the stream. Subsequent calls to 

reset() will attempt toreposition the stream to this point. 

reset() : Resets the stream to the most recent mark. 

!! After last Line is read (readLine()), a trial to reset() throws IOException : Mark invalid