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 121:
Which code fragment correctly appends "Java 7" to the end of the file /tmp/msg.txt?
A. Filewriter w = new FileWriter("/tmp/msg.txt"); B. append("Java 7"); C. close(); D. Filewriter w = new FileWriter("/tmp/msg.txt", true); E. append("Java 7"); F. close(); G. Filewriter w = new FileWriter("/tmp/msg.txt", FileWriter.MODE_APPEND); H. append("Java 7"); I. close(); J. Filewriter w = new FileWriter("/tmp/msg.txt", Writer.MODE_APPEND);
B. append("Java 7");
FileWriter(File file, boolean append)
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 to append - if true, then bytes will be written to the end of the file rather than the beginning
Question 122:
Given the code fragment:
What is the result, if the file salesreport.dat does not exist?
A. Compilation fails only at line 6 B. Compilation fails only at line 13 C. Compilation fails at line 6 and 13 D. Class java.io.IOException E. Class java.io.FileNotFoundException
D. Class java.io.IOException
Compilation works fine.
There will be a runtime error at line 6 (as the file salesreport.dat) does not exist.
This will be caught as an IOException at line 17.
Question 123:
Given the code fragment:
1.
path file = path.get (args.[0])
2.
try {
3.
} / / statements here
4.
catch (IOException) i ) {
5.
}
And a DOS-based file system:
Which option, containing statement(s), inserted at line 3, creates the file and sets its attributes to hidden and read-only?
A. DOSFileAttributes attrs = Files.setAttribute(file, "dos:hidden", "dos: readonly") Files.createFile(file, attrs) B. Files.craeteFile(file); Files.setAttribute(file, "dos:hidden", "dos:readonly"); C. Files.createFile(file, "dos:hidden", "dos:readonly"); D. Files.createFile(file); Files.setAttribute(file, "dos:hidden", true); Files.setAttribute(file, "dos:readonly", true);
D. Files.createFile(file); Files.setAttribute(file, "dos:hidden", true); Files.setAttribute(file, "dos:readonly", true);
You can set a DOS attribute using the setAttribute(Path, String, Object, LinkOption...) method, as follows:
Path file = ...;
Files.setAttribute(file, "dos:hidden", true);
Note:
setAttribute
public static Path setAttribute(Path path,
String attribute,
Object value,
LinkOption... options)
throws IOException
Sets the value of a file attribute.
Reference: Interface DosFileAttribute
Question 124:
Given the following code fragment:
10.
p1 = paths.get("report.txt");
11.
p2 = paths.get("company");
12.
/ / insert code here
Which code fragment, when inserted independently at line 12, move the report.txt file to the company directory, at the same level, replacing the file if it already exists?
A. Files.move(p1, p2, StandardCopyOption.REPLACE_EXISTING, StandardCopyOption.ATOMIC_MOVE); B. Files.move(p1, p2, StandardCopyOption.REPLACE_Existing, LinkOption.NOFOLLOW_LINKS); C. Files.move (p1, p2, StandardCopyOption.REPLACE_EXISTING, LinkOption.NOFOLLOW_LINKS); D. Files.move(p1, p2, StandardCopyOption.REPLACE_EXISTING, StandardCopyOption.copy_ATTRIBUTES, StandrardCopyOp) E. Files.move (p1, p2 StandardCopyOption.REPLACE_EXISTING, StandardCopyOption.copy_ATTRIBUTES, LinkOption.NOF)
A. Files.move(p1, p2, StandardCopyOption.REPLACE_EXISTING, StandardCopyOption.ATOMIC_MOVE);
Moving a file is equally as straight forward ?move(Path source, Path target, CopyOption... options);
The available StandardCopyOptions enums available are:
StandardCopyOption.REPLACE_EXISTING
StandardCopyOption.ATOMIC_MOVE
If Files.move is called with StandardCopyOption.COPY_ATTRIBUTES an UnsupportedOperationException is thrown.
Question 125:
Given the fragment:
If thread a and thread b are running, but not completing, which two could be occurring?
A. livelock B. deadlock C. starvation D. loose coupling E. cohesion
A. livelock B. deadlock
A: A thread often acts in response to the action of another thread. If the other thread's action is also a response to the action of another thread, then livelock may result. A thread often acts in response to the action of another thread. If the other thread's action is also a response to the action of another thread, then livelock may result.
B: Deadlock describes a situation where two or more threads are blocked forever, waiting for each other.
Question 126:
Which concept allows generic collections to interoperate with java code that defines collections that use raw types?
A. bytocode manipulation B. casting C. autoboxing D. auto-unboxing E. type erasure
C. autoboxing
Autoboxing, introduced in Java 5, is the automatic conversion the Java compiler makes between the primitive (basic) types and their corresponding object wrapper classes (eg, int and Integer, double and Double, etc). The underlying code that is generated is the same, but autoboxing provides a sugar coating that avoids the tedious and hard-to-read casting typically required by Java Collections, which can not be used with primitive types.
Question 127:
Given:
public class Print01 {
public static void main(String[] args) {
double price = 24.99;
int quantity = 2;
String color = "Blue";
// insert code here. Line ***
}
}
Which two statements, inserted independently at line ***, enable the program to produce the following output:
We have 002 Blue pants that cost $24.99.
A. System.out.printf("We have %03d %s pants that cost $%3.2f.\n", quantity, color, price); B. System.out.printf("We have $03d $s pants that cost $$3.2f.\n", quantity, color, price); C. String out = String.format ("We have %03d %s pants that cost $%3.2f.\n", quantity, color, price); System.out.println(out); D. String out = System.out.format("We have %03d %s pants that cost $%3.2f.", quantity, color, price); System.out.println(out); E. System.out.format("We have %s %s pants that cost $%s.\n", quantity, color, price);
A. System.out.printf("We have %03d %s pants that cost $%3.2f.\n", quantity, color, price); C. String out = String.format ("We have %03d %s pants that cost $%3.2f.\n", quantity, color, price); System.out.println(out);
A. new file.txt contains: 1: First 2: Second 3: Third B. new file.txt contains: 1: First 2: Second 3: Third C. newfile.txt is empty D. an exception is thrown at runtime E. compilation fails
A. new file.txt contains: 1: First 2: Second 3: Third
For each line in the file myfile.text the line number and the line is written into newfile.txt.
Question 129:
Given the code fragment:
public class IsContentSame {
public static boolean isContentSame() throws IOException {
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.
C. An unsupportedoperationException is thrown at runtime.
Assuming there is a file D:\\faculty\\report.txt then this file will be copied and will be replacing C:\\student\\report.txt.
Question 130:
Given the following files in doc directory: And the code fragment:
What is the result, if doc is present in the current directory?
A. No output is produced. B. index.htm C. index.htm userguide.txt logo.gif D. index.htm service.html userguide.txt logo.gif
B. index.htm
The Glob search expression is defined through "glob:*.htm, html, xml" Only the file name index.htm matches this pattern.
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.