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 Apr 1Z0-804 Study Guide Questions:
Q1. Given the class?
What is the result?
A. Jane Doe John Doe Joe Shmoe
B. John Doe Jane Doe Joe Shmoe
C. Joe Shmoe John Doe Jane Doe
D. Joe Shmoe Jane Doe John Doe
E. Jane Doe Joe Shmoe John Doe
F. John Doe Joe Shmoe Jane Doe
Answer: A
Explanation: The list will be sorted alphabetically (Lastname / Firstname). first sorted by Lastname if Lastname equals, sorted by firstname Output will be: Jane Doe John Doe Joe Shmoe
Q2. Given the code fragment:
What is the result of the employees table has no records before the code executed?
A. 1 Sam
B. 4 Jack
C. 3 John 4 Jack
D. 1 Sam 3 John 4 Jack
Answer: C
Explanation:
AutoCommit is set to false. The two following statements will be within the same
transaction.
stmt.executeUpdate("insert into employees values(1,'Sam')");
stmt.executeUpdate("insert into employees values(2,'Jane')");
These two statements are rolled-back through (the savepoint is ignored! the savepoint
must be specified (e.g.
conn.rollback(save1); ) in the rollback if you want to rollback to the savepoint):
conn.rollback() ;
The next two insert statements are executed fine. Their result will be in the output.
Q3. Given the Greetings.properties file, containing:
What is the result?
A. Compilation fails
B. HELLO_MSG
C. GOODGYE_NSG
D. Hello, everyone!
E. Goodbye everyone!
Answer: A
Explanation:
The code will not compile.
The problem is the following line:
System.out.println(resource.getObject(1));
In particular getObject(1) throws the following error:
Exception in thread "main" java.lang.RuntimeException: Uncompilable source code -Erroneous sym type:
<any>.loadResourceBundle
Note:getObject(String key) !!! String keyGets an object for the given key from this resource
bundle or one of its parents.
Replace ocpjp 8 designated by oracle as 1z0-804:
Q4. Which two codes correctly represent a standard language locale code?
A. ES
B. FR
C. U8
D. Es
E. fr
F. u8
Answer: A,B
Explanation:
Language codes are defined by ISO 639, an international standard that assigns two- and three-letter codes tomost languages of the world. Locale uses the two-letter codes to identify the target language.
Q5. Sam has designed an application. It segregates tasks that are critical and executed frequently from tasks thatare non critical and executed less frequently. He has prioritized these tasks based on their criticality andfrequency of execution. After close scrutiny, he finds that the tasks designed to be non critical are rarely gettingexecuted.
From what kind of problem is the application suffering?
A. race condition
B. starvation
C. deadlock
D. livelock
Answer: C
Explanation:
Starvation describes a situation where a thread is unable to gain regular access to sharedresources and is unable to make progress. This happens when shared resources are made unavailable forlong periods by "greedy" threads. For example, suppose an object provides a synchronized method that oftentakes a long time to return. If one thread invokes
this method frequently, other threads that also need frequentsynchronized access to the same object will often be blocked. Reference: The Java Tutorial, Starvation and Livelock
Q6. Given the code fragment:
Which two try statements, when inserted at line ***, enable the code to successfully move the file info.txt to thedestination directory, even if a file by the same name already exists in the destination directory?
A. try (FileChannel in = new FileInputStream (source). getChannel(); FileChannel out =
new FileOutputStream
(dest).getChannel()) { in.transferTo(0, in.size(), out);
B. try ( Files.copy(Paths.get(source),Paths.get(dest));
Files.delete (Paths.get(source));
C. try ( Files.copy(Paths.get(source),
Paths.get(dest),StandardCopyOption.REPLACE_EXISTING); Files.delete
(Paths.get(source));
D. try (Files.move(Paths.get(source),Paths.get(dest));
E. try(BufferedReader br = Files.newBufferedReader(Paths.get(source),
Charset.forName("UTF- 8"));
BufferedWriter bw = Files.newBufferedWriter(Paths.get(dest), Charset.forName("UTF-8"));
String record =
"";
while ((record = br.readLine()) ! = null) {
bw.write(record);
bw.newLine();
}
Files.delete(Paths.get(source));
Answer: C,E
Explanation:
A: copies only, don’t move operation
B,C,D (no try-with-resource !) syntax change to: try { …
B: throws FileAlreadyExistsException
C: correct if syntax change to : StandardCopyOption.REPLACE_EXISTING (before
REPLACE_Existing)
D: throws FileAlreadyExistsException
E: works properly if the sourcefile has the correct format, utf-8 here (else throws
MalformedInputException)
AND syntax is corrected to:
try ( BufferedReader br = Files.newBufferedReader(Paths.get(source),
Charset.forName(“UTF-8));
BufferedWriter bw = Files.newBufferedWriter(Paths.get(dest), Charset.forName(“UTF-8));
){
String record = “”;
…..
Approved book for 1z0-804:
Q7. Select four examples that initialize a NumberFormat reference using a factory.
A. NumberFormat nf1 = new DecimalFormat();
B. NumberFormat nf2 = new DecimalFormat("0.00") ; C. NumberFormat nf3 = NumberFormat.getInstance();
D. NumberFormat nf4 = NumberFormat.getIntegerInstance();
E. NumberFormat nf5 = DecimalFormat.getNumberInstance ();
F. NumberFormat nf6 = NumberFormat.getCurrencyInstance () ;
Answer: C,D,E,F
Explanation:
getInstance
public static finalNumberFormatgetInstance()
Returns the default number format for the current default locale. The default format is one
of the styles
provided by the other factory methods: getNumberInstance(E), getIntegerInstance(D),
getCurrencyInstance(F)
or getPercentInstance. Exactly which one is locale dependant.
C: To obtain a NumberFormat for a specific locale, including the default locale, call one of NumberFormat'sfactory methods, such as getInstance(). E:To obtain standard formats for a given locale, use the factory methods on NumberFormat such asgetNumberInstance. These factories will return the most appropriate sub-class of NumberFormat for a givenlocale. F:To obtain standard formats for a given locale, use the factory methods on NumberFormat such asgetInstance or getCurrencyInstance.
Reference:java.textClass NumberFormat
Q8. Which two are valid initialization statements?
A. Map<String, String> m = new SortedMap<String, String>();
B. Collection m = new TreeMap<Object, Object>();
C. HashMap<Object, Object> m = new SortedMap<Object, Object>();
D. SortedMap<Object, Object> m = new TreeMap<Object, Object> ();
E. Hashtable m= new HashMap();
F. Map<List, ArrayList> m = new Hashtable<List, ArrayList>();
Answer: D,F
Q9. Which code fragment is required to load a JDBC 3.0 driver?
A. DriverManager.loadDriver ("org.xyzdata.jdbc.NetworkDriver");
B. Class.forName("org.xyzdata.jdbc-NetworkDriver");
C. Connection con = Connection.getDriver ("jdbc:xyzdata://localhost:3306/EmployeeDB");
D. Connection con = DriverManager.getConnection ("jdbc:xyzdata://localhost:3306/EmployeeDB");
Answer: B
Explanation:
In previous versions (prior to 4.0) of JDBC, to obtain a connection, you first had to initialize
your JDBCdriver by calling the method Class.forName. This methods required an object of
type java.sql.Driver.
Note:
DriverManager: This fully implemented class connects an application to a data source,
which is specified by adatabase URL. When this class first attempts to establish a
connection, it automatically loads any JDBC 4.0drivers found within the class path. Note
that your application must manually load any JDBC drivers prior toversion 4.0.
Q10. Given:
What is the result?
A. Up Down
B. Up Up
C. Up null
D. Compilation fails
E. An exception is thrown at runtime
Answer: D Explanation:
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 doesnot override abstract method growthDirection() in garden.Plant