Oracle 1Z0-804 Online Practice
Questions and Exam Preparation
1Z0-804 Exam Details
Exam Code
:1Z0-804
Exam Name
:Java SE 7 Programmer II
Certification
:Oracle Certifications
Vendor
:Oracle
Total Questions
:150 Q&As
Last Updated
:Dec 08, 2021
Oracle 1Z0-804 Online Questions &
Answers
Question 11:
Which method would you supply to a class implementing the Callable interface?
A. callable () B. executable () C. call () D. run () E. start ()
C. call ()
public interface Callable
A task that returns a result and may throw an exception. Implementors define a single method with no arguments called call.
Note:
Interface Callable
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 are potentially executed by another thread. A Runnable, however, does not return a result and cannot throw a checked exception.
The Executors class contains utility methods to convert from other common forms to Callable classes.
Reference: java.util.concurrent
Question 12:
Given the code fragment:
public class ReadFile01 {
public static void main(String[] args) {
String fileName = "myfile.txt";
try (BufferedReader buffIn = // Line 4
new BufferedReader(new FileReader(fileName))) {
String line = ""; int count = 1;
line = buffIn.readLine(); // Line 7
do {
line = buffIn.readLine();
System.out.println(count + ": " + line);
} while (line != null);
} catch (IOException | FileNotFoundException e) {
System.out.println("Exception: " + e.getMessage()); } } } What is the result, if the file myfile.txt does not exist?
A. A runtime exception is thrown at line 4 B. A runtime exception is thrown at line 7 C. Creates a new file and prints no output D. Compilation fails
A. A runtime exception is thrown at line 4
There will be a FileNotFoundException at line 4.
Question 13:
Which code fragment demonstrates the proper way to handle JDBC resources?
A. No message is printed B. Petit C. D. A runtime error is produced
D. A runtime error is produced
There is no Spanish resource bundle. The following runtime error will occur:
Exception in thread "main" java.util.MissingResourceException: Can't find bundle for base name MessageBundle, locale es_ES
Question 15:
Given the code fragment:
public class Base {
BufferedReader br;
String record;
public void process() throws FileNotFoundException {
br = new BufferedReader(new FileReader("manual.txt"));
}
}
public class Derived extends Base {
// insert code here. Line ***
public static void main(String[] args) {
try {
new Derived().process();
} catch (Exception e) { } }
}
Which code fragment inserted at line ***, enables the code to compile?
A. public void process () throws FileNotFoundException, IOException { super.process (); while ((record = br.readLine()) != null) { System.out.println(record); } } B. public void process () throws IOException { super.process (); while ((record = br.readLine()) != null) { System.out.println(record); } } C. public void process () throws Exception { super.process (); while ((record = br.readLine()) != null) { System.out.println(record); } } D. public void process (){ try { super.process (); while ((record = br.readLine()) != null) { System.out.println(record); } } catch (IOException | FileNotFoundException e) { } } E. public void process (){ try { super.process (); while ((record = br.readLine()) != null) { System.out.println(record); } } catch (IOException e) {} }
E. public void process (){ try { super.process (); while ((record = br.readLine()) != null) { System.out.println(record); } } catch (IOException e) {} }
Incorrect answer:
D: exception java.io.FileNotFoundException has already been caught
Alternatives in a multi-catch statement cannot be related to subclassing Alternative java.io. FileNotFoundException is a subclass of alternative java.io.IOException
Question 16:
Given the cache class:
public class Cache {
private T t;
public void setValue (T t) { this.t=t; }
public T getValue() {return t; }
}
What is the result of the following?
Cache<> c = new Cache(); // Line 1
A. SetValue(100); // Line 2 System.out.print(c.getValue().intValue() +1); // Line 3 B. 101 C. Compilation fails at line 1. D. Compilation fails at line 2. E. Compilation fails at line 3.
B. 101
Compilation failure at line:
illegal start of type type cache.Cache does not take parameters.
Question 17:
Which type of ExecutorService supports the execution of tasks after a fixed delay?
A. DelayedExecutorService B. ScheduledExecutorService C. TimedExecutorService D. FixedExecutorService E. FutureExecutorService
B. ScheduledExecutorService
The ScheduledExecutorService interface supplements the methods of its parent ExecutorService with schedule, which executes a Runnable or Callable task after a specified delay. In addition, the interface defines scheduleAtFixedRate and scheduleWithFixedDelay, which executes specified tasks repeatedly, at defined intervals.
Note: The java.util.concurrent package defines three executor interfaces:
*
Executor, a simple interface that supports launching new tasks.
*
ExecutorService, a subinterface of Executor, which adds features that help manage the lifecycle, both of the individual tasks and of the executor itself.
*
ScheduledExecutorService, a subinterface of ExecutorService, supports future and/or periodic execution of tasks.
Reference: The Java Tutorials, Executor Interfaces
Question 18:
Which three statements are correct about thread's sleep method?
A. The sleep (long) method parameter defines a delay in milliseconds. B. The sloop (long) method parameter defines a delay in microseconds. C. A thread is guaranteed to continue execution after the exact amount of time defined in the sleep (long) parameter. D. A thread can continue execution before the amount of time defined in the sleep (long) parameter. E. A thread can continue execution after the amount of time defined in the sleep(long) parameter F. Only runtime exceptions are thrown by the sleep method. G. A thread loses all object monitors (lock flags) when calling the sleep method.
A. The sleep (long) method parameter defines a delay in milliseconds. C. A thread is guaranteed to continue execution after the exact amount of time defined in the sleep (long) parameter. E. A thread can continue execution after the amount of time defined in the sleep(long) parameter
public static void sleep(long millis)
throws InterruptedException
Causes the currently executing thread to sleep (temporarily cease execution) for the specified number of milliseconds (A, not B). The thread does not lose ownership of any monitors (not G).
Parameters:
millis - the length of time to sleep in milliseconds.
Throws:
InterruptedException - if another thread has interrupted the current thread. The interrupted status of the current thread is cleared when this exception is thrown.
Question 19:
Given:
class A {
int a = 5;
String doA() { return "a1"; }
protected static String doA2 () { return "a2"; }
}
class B extends A {
int a = 7;
String doA() { return "b1"; }
public static String doA2() { return "b2"; }
void go() {
A myA = new B();
System.out.print(myA.doA() + myA.doA2() + myA.a);
}
public static void main (String[] args) { new B().go(); }
}
Which three values will appear in the output?
A. 5 B. 7 C. a1 D. a2 E. b1 F. b2
B. 7 E. b1 F. b2
Question 20:
Given:
interface Books {
//insert code here
}
Which fragment, inserted in the Books interface, enables the code to compile?
A. public abstract String type; public abstract String getType(); B. public static String type; public abstract String getType(); C. public String type = "Fiction"; public static String getType(); D. public String type = "Fiction"; public abstract String getType();
D. public String type = "Fiction"; public abstract String getType();
Nowadays, the certification exams become more and more important and required by more and more
enterprises when applying for a job. But how to prepare for the exam effectively? How to prepare
for the exam in a short time with less efforts? How to get a ideal result and how to find the
most reliable resources? Here on Vcedump.com, you will find all the answers.
Vcedump.com provide not only Oracle exam questions,
answers and explanations but also complete assistance on your exam preparation and certification
application. If you are confused on your 1Z0-804 exam preparations
and Oracle certification application, do not hesitate to visit our
Vcedump.com to find your solutions here.