Examcollection 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:
What is the result?
A. peach orange apple
B. peach orange
C. apple orange
D. The program does not compile.
E. The program generates an exception at runtime.
Answer: D
Explanation:
int compare(T obj1, T obj2) 0 if equal positive if obj1 greater negative if obj2 greater The compiler has a problem with the line: public boolean compare(String s1, String s2) { return s1.length() > s2.length(); error: <anonymous comparetest.CompareTest$1> is not abstract and does not override abstract method compare(String,String) in Comparator
new Comparator<String>() {
Error: compare(String,String) in <anonymous comparetest.CompareTest$1> cannot
implement compare(T,T)
in Comparator
public boolean compare(String s1, String s2) {
return type boolean is not compatible with int
where T is a type-variable:
T extends Object declared in interface Comparator
Q2. Given the cache class:
A. 101
B. Compilation fails at line 1.
C. Compilation fails at line 2.
D. Compilation fails at line 3.
Answer: B
Explanation:
Compilation failure at line:1 Incorrect number of arguments for type Cache<T>; it cannot be parameterized with arguments <>illegal start of typetype cache.Cache does not take parameters.
Q3. The default file system includes a logFiles directory that contains the following files:
Log-Jan 2009
log_0l_20l0
log_Feb20l0
log_Feb2011
log_10.2012
log-sum-2012
How many files does the matcher in this fragment match?
PathMatcher matcher = FileSystems.getDefault ().getPathMatcher ("glob: *???_*1?" );
A. One
B. Two
C. Three
D. Four
E. Five
F. Six
Answer: B
Explanation:
The pattern to match is *???_*1? (regex ".*..._.*1.")
This means at least three characters before the symbol _ , followed by any amount of
characters. The next tolast character must be 1. The last character can by any character.
The following file names match this pattern:
log_Feb2011
log_10.2012 Trap !! l is not 1 !!
Q4. Given: What is the result?
A. Null
B. class java.lang.ArraylndexOutOfBoundsException
C. class java.lang.NullPointerException
D. class java.lang.Exception
E. Compilation fails.
Answer: E
Explanation:
error: incompatible types e = new Exception(); required: RuntimeException found: Exception
Q5. Given the code fragment:
Assume that the SQL queries return records. What is the result of compiling and executing this code fragment?
A. The program prints employee IDs
B. The program prints customer IDs
C. The program prints Error
D. Compilation fails on line ***
Answer: C
Explanation:
!!! The given Code prints Error -- the second query clears the ResultSet !? ErrorMessage: Operation notallowed after ResultSet closed
It would print A, if second Query i set to rs = stmt.executeQuery("SELECT ID FROM Customer"); // Line *** It would print B, if Line *** is missing. // The program compiles and runs fine. Both executeQuery statements will run. The first executeQuery statement (ResultSet rs = stmt.executeQuery(query);) will set the rs Resultset. It will be used in the while loop. EmployIDswill be printed. Note: Executes the given SQL statement, which returns a single ResultSet object. Parameters:sql - an SQL statement to be sent to the database, typically a static SQL SELECT statement Returns:a ResultSet object that contains the data produced by the given query; never null
Q6. Given: What is the result?
A. Compilation fails at line 9
B. Compilation fails at line 10
C. Compilation fails at line 5
D. Compilation fails at line 3
E. Compilation succeeds
Answer: B
Q7. Given the code format:
SimpleDateFormat sdf;
Which code statements will display the full text month name?
A. sdf = new SimpleDateFormat ("mm", Locale.UK); System.out.println("Result:", sdf.format(new date()));
B. sdf = new SimpleDateFormat ("MM", Locale.UK); System.out.println("Result:", sdf.format(new date()));
C. sdf = new SimpleDateFormat ("MMM", Locale.UK); System.out.println("Result:", sdf.format(new date()));
D. sdf = new SimpleDateFormat ("MMMM", Locale.UK); System.out.println("Result:", sdf.format(new date()));
Answer: D
Explanation:
Typical output would be Current Month in M format: 2 Current Month in MM format: 02 Current Month in MMM format: Feb Current Month in MMMM format: February
Q8. Which two actions can be used in registering a JDBC 3.0 driver?
A. Add the driver class to the META-INF/services folder of the JAR file.
B. Set the driver class name by using the jdbc.drivers system property.
C. Include the JDBC driver class in a jdbcproperties file.
D. Use the java.lang.class.forName method to load the driver class.
E. Use the DriverManager.getDriver method to load the driver class.
Answer: A,D
Explanation:
A: if your JDBC Driver is NOT JDBC 4-compliant then we can update the driver using "jar"-utility by adding the "META-INF /services/java.sql.Driver" inside it. as following: D:Dynamic loading of Java classes at runtime provides tremendous flexibility in the development of enterprisesystems. It provides for the basis of "application servers", and allows even simpler, lighter-weight systems toaccomplish some of the same ends. Within Java, dynamic-loading is typically achieved by calling the forNamemethod on the class java.lang.ClassAn example provided by the standard Java SE API is the ServiceLoader. Amongothers, the JDBC 4.0compatible drivers implement this. This way just dropping the JDBC driver JAR file folder will automatically loadthe driver class during Java application's startup/initialization without the need for any manual Class.forName("com.example.Driver") line in your code.
Q9. Which code fragment correctly appends "Java 7" to the end of the file /tmp/msg.txt?
A. FileWriter w = new FileWriter("/tmp/msg.txt");
append("Java 7");
close();
B. FileWriter w = new FileWriter("/tmp/msg.txt", true);
append("Java 7");
close();
C. FileWriter w = new FileWriter("/tmp/msg.txt", FileWriter.MODE_APPEND);
append("Java 7");
close();
D. FileWriter w = new FileWriter("/tmp/msg.txt", Writer.MODE_APPEND);
append("Java 7");
close();
Answer: B
Explanation:
FileWriter(File file, boolean append)
A: clears the file and append "Java7"
Constructs a FileWriter object given a File object.
If the second argument is true, then bytes will be written to the end of the file rather than
the beginning.Parameters:
file - a File object to write toappend - if true, then bytes will be written to the end of the file
rather than the beginning
Q10. Given the following incorrect program:
Which two changes make the program work correctly?
A. Results must be retrieved from the newly created MyTask instances and combined.
B. The threshold value must be increased so that the overhead of task creation does not dominate the cost ofcomputation.
C. The midpoint computation must be altered so that it splits the workload in an optimal manner.
D. The compute () method must be changed to return an Integer result.
E. The compute () method must be enhanced to (fork) newly created tasks.
F. The myTask class must be modified to extend RecursiveAction instead of RecursiveTask
Answer: A,D
Explanation:
Note 1: A RecursiveTask is a recursive result-bearing ForkJoinTask. Note 2: The invokeAll(ForkJoinTask<?>… tasks) forks the given tasks, returning when isDone holds for eachtask or an (unchecked) exception is encountered, in which case the exception is rethrown. Note 3: Using the fork/join framework is simple. The first step is to write some code that performs a segmentof the work. Your code should look similar to this: if (my portion of the work is small enough) do the work directly else split my work into two pieces invoke the two pieces and wait for the results Wrap this code as a ForkJoinTask subclass, typically as one of its more specialized types RecursiveTask (which can return a result) or RecursiveAction.