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 Jun 1Z0-804 Study Guide Questions:

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


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 

Q12. Given: 

And the command-line invocation: 

Java Tracker 12 11 

What is the result? 

A. General category 

B. class InvalidAgeException 

C. class java.lang.IllegalArgumentException 

D. class java.lang.RuntimeException 

Answer: B 


The second argument 11 makes the program to throw an InvalidAgeException due to the 


if (age < 12) 

throw new InvalidAgeException (); 

Q13. Given: What is the result? 

A. tolting cantering tolting 

B. cantering cantering cantering 

C. compilation fails 

D. an exception is thrown at runtime 

Answer: C 


Compiler says: Cannot reduce the visibility of the inherited method from Rideable. müssen 

PUBLIC sein 

public String ride() { return "cantering "; } 

public String ride() { return "tolting "; } 

if this is given then the result would be: 

A : tolting cantering tolting 

1Z0-804  free exam

Up to the minute oracle press 1z0-804:

Q14. Given the code fragment: 

What is the result when the result.txt file already exists in c:student? 

A. The program replaces the file contents and the file's attributes and prints Equal. 

B. The program replaces the file contents as well as the file attributes and prints Not equal. 

C. An UnsupportedOperationException is thrown at runtime. 

D. The program replaces only the file attributes and prints Not equal. 

Answer: B 


Assuming there is a file D:\faculty\report.txt then this file will be copied and will be replacing C:\student\report.txt. 

Q15. Given the code fragment: 

Assume that the SQL query matches one record. What is the result of compiling and executing this code? 

A. The code prints Error. 

B. The code prints the employee ID. 

C. Compilation fails due to an error at line 13. 

D. Compilation fails due to an error at line 14. 

Answer: A 


The code compiles fine. 

A: prints Error: rs.next() fehlt !! Fehlermeldung: Before start of result set mit rs.next() Aufruf : The code would run fine. public int getInt(String columnName) throws SQLException Retrieves the value of the designated column in the current row of this ResultSet object as an int in the Javaprogramming language 

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

A. callable () 

B. executable () 

C. call () 

D. run () 

E. start () 

Answer: C 


public interface Callable<V> 

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

method with noarguments called call. 


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. 



Real 1z0-804 guide:

Q17. Given: And the commands: 

javac Test.java 

java ea Test 

What is the result? 

A. Compilation fails 

B. Standard Edition Enterprise Edition Micro Edition 

C. Standard Edition class java.lang.AssertionError Micro Edition 

D. Standard Edition is printed and an Assertion Error is thrown 

Answer: D 


javac Test.java 

will compile the program. 

As for command line: 

java ea Test 

First the code will produce the output: 

Standard Edition 

See Note below. 

The ea option will enable assertions. This will make the following line in the switch 

statement to be run: 

default: assert false; 

This will throw an assertion error. This error will be caught. An the class of the assertion 

error (classjava.lang.AssertionError) will be printed by the following line: 


Note:The java tool launches a Java application. It does this by starting a Java runtime 

environment, loading aspecified class, and invoking that class's main method. The method 

declaration must look like the following: 

public static void main(String args[]) 

Paramater ea: 

-enableassertions[:<package name>"..." | :<class name> ] -ea[:<package name>"..." | 

:<class name> ] 

Enable assertions. Assertions are disabled by default. With no arguments, 

enableassertions or -ea enablesassertions. 

Note 2: 

An assertion is a statement in the JavaTM programming language that enables you to test 

your assumptionsabout your program. 

Each assertion contains a boolean expression that you believe will be true when the 

assertion executes. If it isnot true, the system will throw an error. 

public class AssertionError extends Error 

Thrown to indicate that an assertion has failed. 

Note 3: 

The javac command compiles Java source code into Java bytecodes. You then use the 

Java interpreter - the 

java command - to interprete the Java bytecodes. 

Reference:java - the Java application launcher 

Reference:java.langClass AssertionError 

Q18. Given the code fragment: 

What change should you make to apply good coding practices to this fragment? 

A. Add nested try-with-resources statements for the statement and ResultSet declarations. 

B. Add the statement and ResultSet declarations to the try-with-resources statement. 

C. Add a finally clause after the catch clause. 

D. Rethrow SQLException. 

Answer: C 


The finally block always executes when the try block exits. This ensures that the finally block is executed evenif an unexpected exception occurs. But finally is useful for more than just exception handling -- it allows theprogrammer to avoid having cleanup code accidentally bypassed by a return, continue, or break.Putting cleanup code in a finally block is always a good practice, even when no exceptions areanticipated. 

Q19. Given: 

Which two are true? 

A. Thread is printed 

B. Runnable is printed 

C. No output is produced 

D. No new threads of execution are started within the main method 

E. One new thread of execution is started within the main method 

F. Two new threads of exclusion are started within the main method 

Answer: C,D 

Q20. Given: 

import java.util.concurrent.atomic.AtomicInteger; 

public class AtomicCounter { 

private AtomicInteger c = new AtomicInteger(0); 

public void increment() { 

// insert code here 

Which line of code, inserted inside the increment () method, will increment the value of c? 

A. c.addAndGet(); 

B. c++; 

C. c = c+1; 

D. c.getAndIncrement (); 

Answer: D 

Explanation: getAndIncrement 

public final int getAndIncrement() 

Atomically increment by one the current value.