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 21:
Which two demonstrate the valid usage of the keyword synchronized?
A. interface ThreadSafe { synchronized void doIt(); } B. abstract class ThreadSafe { synchronized abstract void doIt(); } C. class ThreadSafe { synchronized static void soIt () {} } D. enum ThreadSafe { ONE, TWO, Three; Synchronized final void doIt () {} }
B. abstract class ThreadSafe { synchronized abstract void doIt(); } C. class ThreadSafe { synchronized static void soIt () {} }
The Java programming language provides two basic synchronization idioms:
synchronized methods and synchronized statements.
Example:
To make a method synchronized, simply add the synchronized keyword to its declaration:
public class SynchronizedCounter {
private int c = 0;
public synchronized void increment() {
c++;
}
public synchronized void decrement() {
c--;
}
public synchronized int value() {
return c;
}
}
Incorrect:
A: An interface in the Java programming language is an abstract type that is used to specify an interface (in the generic sense of the term) that classes must implement.
Interfaces are declared using the interface keyword, and may only contain method signature and constant declarations (variable declarations that are declared to be both static and final). An interface may never contain method definitions.
D: An enum type is a special data type that enables for a variable to be a set of predefined constants. The variable must be equal to one of the values that have been predefined for it.
Common examples include compass directions (values of NORTH, SOUTH, EAST, and WEST) and the days of the week.
Given: final class FinalShow { // Line 1 final String location; // Line 2 FinalShow(final String loc) { // Line 3 location = loc; // Line 4 } // Line 5 FinalShow(String loc, String title) { // Line 6 location = loc; // Line 7 loc = "unknown"; // Line 8 } // Line 9 } // Line 10 What is the result?
A. Compilation succeeds. B. Compilation fails due to an error on line 1. C. Compilation fails due to an error on line 2. D. Compilation fails due to an error on line 3. E. Compilation fails due to an error on line 4. F. Compilation fails due to an error on line 8.
A. Compilation succeeds.
Question 24:
Given:
public class MarkOutOfBoundsException extends ArrayIndexOutOfBoundsException {
public class Test {
public void verify(int[] arr)
throws ArrayIndexOutOfBoundsException {
for (int i = 1; i <= 3; i++) {
if(arr[i] > 100)
throw new MarkOutOfBoundsException();
System.out.println(arr[i]);
}
}
public static void main(String[] args) {
int[] arr = {105,78,56};
try {
new Test().verify(arr);
} catch (ArrayIndexOutOfBoundsException |
MarkOutOfBoundsException e) {
System.out.print(e.getClass());
}
}
}
What is the result?
A. Compilation fails. B. 78 class java.lang.Array.IndexOutOfBoundException C. class MarkOutOfBoundException D. class java.lang.arrayIndexOutOfBoundException
A. Compilation fails.
Question 25:
Given:
class Plant {
abstract String growthDirection();
}
class Embryophyta extends Plant {
String growthDirection() { return "Up " }
}
public class Garden {
public static void main(String[] args) {
Embryophyta e = new Embryophyta();
Embryophyta c = new Carrot();
System.out.print(e.growthDirection() +
A. growthDirection()); } } What is the result? B. Up Down C. Up Up D. Up null E. Compilation fails F. An exception is thrown at runtime
E. Compilation fails
Exception in thread "main" java.lang.ExceptionInInitializerError at garden.Garden.main Caused by: java.lang.RuntimeException: Uncompilable source code - garden.Plant is not abstract and does not override abstract method growthDirection() in garden.Plant
Question 26:
Given:
class Product {
private int id;
public Product (int id) {
this.id = id;
}
public int hashCode() {
return id + 42;
}
public boolean equals (Object obj) {
return (this == obj) ? true : super.equals(obj);
}
}
public class WareHouse {
public static void main(String[] args) {
Product p1 = new Product(10);
Product p2 = new Product(10);
Product p3 = new Product(20);
System.out.print(p1.equals(p2) + " ");
System.out.print(p1.equals(p3) );
}
}
What is the result?
A. false false B. true false C. true true D. Compilation fails E. An exception is thrown at runtime
D. Compilation fails
Hint for line: public class Warehouse {
class WareHouse is public, should be declared in a file named WareHouse.java.
Compilation result:
Error: Main method not found in class product.Product, please define the main method as:
public static void main(String[] args)
Java Result: 1
Question 27:
An application is waiting for notification of changes to a tmp directory using the following code statements:
Path dir = Paths.get("tmp")
WatchKey key = dir.register (watcher, ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY) ; In the tmp directory, the user renames the file testA to testB, Which statement is true?
A. The events received and the order of events are consistent across all platforms. B. The events received and the order of events are consistent across all Microsoft Windows versions. C. The events received and the order of events are consistent across all UNIX platforms. D. The events received and the order of events are platform dependent.
A. The events received and the order of events are consistent across all platforms.
Most file system implementations have native support for file change notification. The Watch Service API takes advantage of this support where available. However, when a file system does not support this mechanism, the Watch Service will poll the file system, waiting for events.
Note: WatchKey : When a Watchable entity is registered with a WatchService a key which is a WatchKey is generated. Initially the key is in ready state waiting to be notified of any events on the Watchable entity. Once an event occurs the key goes into signaled state and allows to access the events using its pollEvents method. After processing the poll events the key has to be reset by invoking its reset method.
Reference: The Java Tutorials, Watching a Directory for Changes
Question 28:
Give:
class Fibonacci extends RecursiveTask {
final int n;
Fibonacci(int n) { this.n = n; }
Integer compute() {
if (n <= 1)
return n;
Fibonacci f1 = new Fibonacci(n - 1);
f1.fork();
Fibonacci f2 = new Fibonacci(n - 2);
return f2.compute() + f1.join(); // Line X
}
}
Suppose that line X is replace with:
return f1.join()+f2.compute() ; // Line X
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 single-threaded. 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.
D. The program goes into an infinite loop.
join()does not proceed until the task's result has been computed. Here we start to wait before doing the computing. The code will not finish.
Question 29:
Given the incomplete pseudo-code for a fork/join framework application: submit(Data) { if(Data.size < SMALL_ENOUGH) { _________________(Data); // line x } else { List x = _________________(Data); // line Y for(Data d: x ______________(d); // line z } } And given the missing methods: process, submit, and splitInHalf Which three insertions properly complete the pseudo-code?
A. Insert submit at line X. B. Insert splitInHalf at line X. C. Insert process at line X. D. Insert process at line Y. E. Insert splitInHalf at line Y. F. Insert process at line Z. G. Insert submit at line Z.
C. Insert process at line X. E. Insert splitInHalf at line Y. G. Insert submit at line Z.
C: If data is small enough then process it. Line X
E: If data is not small enough then split it half. Line Y
G: After the data has been split (line Y) then recursively submit the splitted data (Line z).
Question 30:
Which two codes correctly represent a standard language locale code?
A. ES B. FR C. U8 D. Es E. fr F. u8
A. ES D. Es
Language codes are defined by ISO 639, an international standard that assigns two- and three-letter codes to most languages of the world.
Locale uses the two-letter codes to identify the target language.
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.