Shortcuts To 1Z0-804(1 to 15)

1Z0-804 Royal Pack Testengine pdf

100% Actual & Verified — 100% PASS

Unlimited access to the world's largest Dumps library!

Download 1Z0-804 Dumps Free

we provide Realistic Oracle 1Z0-804 practice question which are the best for clearing 1Z0-804 test, and to get certified by Oracle Java SE 7 Programmer II Exam. The 1Z0-804 Questions & Answers covers all the knowledge points of the real 1Z0-804 exam. Crack your Oracle 1Z0-804 Exam with latest dumps, guaranteed!


If you would certainly such as to recognize more concerning 1Z0-804 exam, call us or merely visit us at our internet 2PASSEASY.COM site.

Q1. 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 = “”; 

….. 


Q2. Given: And the commands: 

javac Test.java 

java ea Test 

What is the result? 

A. Compilation fails 

B. Standard Edition Enterprise Edition Micro Edition 

C. Standard Edition class java.lang.AssertionError Micro Edition 

D. Standard Edition is printed and an Assertion Error is thrown 

Answer:

Explanation: 

javac Test.java 

will compile the program. 

As for command line: 

java ea Test 

First the code will produce the output: 

Standard Edition 

See Note below. 

The ea option will enable assertions. This will make the following line in the switch 

statement to be run: 

default: assert false; 

This will throw an assertion error. This error will be caught. An the class of the assertion 

error (classjava.lang.AssertionError) will be printed by the following line: 

System.out.println(e.getClass()); 

Note:The java tool launches a Java application. It does this by starting a Java runtime 

environment, loading aspecified class, and invoking that class's main method. The method 

declaration must look like the following: 

public static void main(String args[]) 

Paramater ea: 

-enableassertions[:<package name>"..." | :<class name> ] -ea[:<package name>"..." | 

:<class name> ] 

Enable assertions. Assertions are disabled by default. With no arguments, 

enableassertions or -ea enablesassertions. 

Note 2: 

An assertion is a statement in the JavaTM programming language that enables you to test 

your assumptionsabout your program. 

Each assertion contains a boolean expression that you believe will be true when the 

assertion executes. If it isnot true, the system will throw an error. 

public class AssertionError extends Error 

Thrown to indicate that an assertion has failed. 

Note 3: 

The javac command compiles Java source code into Java bytecodes. You then use the 

Java interpreter - the 

java command - to interprete the Java bytecodes. 

Reference:java - the Java application launcher 

Reference:java.langClass AssertionError 


Q3. Given the code fragment: 

Why is there no output when otherMethod is called? 

A. An exception other than IOException is thrown. 

B. Standard error is not mapped to the console. 

C. There is a compilation error. 

D. The exception is suppressed. 

Answer:

Explanation: 

C: wenn printStackTrace() ohne Referenz auf das Exception object aufgerufen 

A : java.io.FileNotFoundException: wenn e.printStackTrace(); 

The code compiles fine 

The line 

FileInputStream fis = new FileInputStream(file)) 

will fail at runtime since file is an empty string. 

Note: 

public void printStackTrace() 

Prints this throwable and its backtrace to the standard error stream. 


Q4. How many Threads are created when passing task to an Executor instance? 

A. A new Thread is used for each task. 

B. A number of Threads equal to the number of CPUs Is used to execute tasks. 

C. A single Thread Is used to execute all tasks. 

D. A developer-defined number of Threads is used to execute tasks. 

E. A number of Threads determined by system load is used to execute tasks. 

F. The method used to obtain the Executor determines how many Threads are used to execute tasks. 

Answer:

Explanation: 

The Executor interface provides a single method, execute, designed to be a drop-in replacementfor a common thread-creation idiom. If r is a Runnable object, and e is an Executor object you can replace(new Thread(r)).start(); 

with e.execute(r); However, the definition of execute is less specific. The low-level idiom creates a new thread and launches it immediately. Depending on the Executor implementation, execute may do the same thing, but is more likely to use an existing worker thread to run r, or to place r in a queue to wait for a worker thread to become available. 

Reference: The Java Tutorial,The Executor Interface 


Q5. Given three resources bundles with these values set for menu1: (the default resource bundle in US English.) 

English US Resource Bundle Menu1 = small French Resource Bundle Menu1 = petit Chinese Resource Bundle Menu1 = And given the code fragment: Locale.setDefault(new Locale("es", "ES")); // Set default to Spanish and Spain 

Locale loc1 = Locale.getDefault(); 

ResourceBundle message = ResourceBundle.getBundle("MessageBundle", loc1); 

System.out.println(message.getString("menu1")); 

What is the result? 

A. No message is printed 

B. petit 

C. small 

D. A runtime error is produced 

Answer:

Explanation: Compiles fine, but runtime error when trying to access the Spanish Resource bundle (which doesnot exist): Exception in thread "main" java.util.MissingResourceException: Can't find bundle for base name messageBundle, locale es_ES 


Q6. Assuming the port statements are correct, which two (three?) code fragments create a one-byte file? 

A. OutputStream fos = new FileOutputStream(new File("/tmp/data.bin")); OutputStream bos = new BufferedOutputStream(fos); DataOutputStream dos = new DataOutputStream(bos); dos.writeByte(0); dos.close(); 

B. OutputStream fos = new FileOutputStream ("/tmp/data.bin"); 

DataOutputStream dos = new DataOutputStream(fos); 

dos.writeByte(0); 

dos.close(); 

C. OutputStream fos = new FileOutputStream (new File ("/tmp/data.bin")); 

DataOutputStream dos = new DataOutputStream(fos); 

dos.writeByte(0); 

dos.close(); 

D. OutputStream fos = new FileOutputStream ("/tmp/data.bin"); fos.writeByte(0); 

fos.close(); 

Answer: A,B,C 

Explanation: 

B:Create DataOutputStream from FileOutputStream public static void main(String[] args) 

throws 

Exception { FileOutputStream fos = new FileOutputS tream("C:/demo.txt"); 

DataOutputStream dos = new 

DataOutputStream(fos); 

Note: 

The FileOutputStream class is a subclass of OutputStream. You can construct a 

FileOutputStream object by 

passing a string containing a path name or a File object. 

You can also specify whether you want to append the output to an existing file. 

public FileOutputStream (String path) 

public FileOutputStream (String path, boolean append) 

public FileOutputStream (File file) 

public FileOutputStream (File file, boolean append) 

With the first and third constructors, if a file by the specified name already exists, the file 

will be overwritten. Toappend to an existing file, pass true to the second or fourth 

constructor. 

Note 2:public class DataOutputStreamextends FilterOutputStreamimplements DataOutput 

A data output stream lets an application write primitive Java data types to an output stream 

in a portable way. 

An application can then use a data input stream to read the data back in. 

Reference:java.io Class DataOutputStream 


Q7. Given the code fragment: What is the result when infected() is invoked? 

A. before try catch finally after 

B. before catch finally after 

C. before catch after 

D. before catch finally 

E. before catch 

Answer:

Explanation: 

The following line throws and exception: 

int i = 1/0; 

This exception is caught by: 

catch(Exception e) { 

System.out.print("catch "); 

throw e; 

Lastly, the finally statement is run as the finally block always executes when the try block 

exits. This ensuresthat the finally block is executed even if an unexpected exception 

occurs. 

Reference: Java Tutorial,The finally Block 


Q8. Give: 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 singlethreaded. 

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. 

Answer:

Explanation: 

join() does not proceed until the task's result has been computed. Here we start to wait beforedoing the computing. The code will not finish. 


Q9. Given the code fragment: SimpleDataFormat sdf; 

Which code fragment displays the three-character month abbreviation? 

A. SimpleDateFormat sdf = new SimpleDateFormat ("mm", Locale.UK); System.out.println 

("Result:" + 

sdf.format(new Date())); 

B. SimpleDateFormat sdf = new SimpleDateFormat ("MM", Locale.UK); System.out.println 

("Result:" + 

sdf.format(new Date())); 

C. SimpleDateFormat sdf = new SimpleDateFormat ("MMM", Locale.UK); 

System.out.println ("Result:" + 

sdf.format(new Date())); 

D. SimpleDateFormat sdf = new SimpleDateFormat ("MMMM", Locale.UK); 

System.out.println ("Result:" + 

sdf.format(new Date())); 

Answer:


Q10. Given: Which two are true? 

A. A runtime exception is thrown on line 9. 

B. No output is produced. 

C. Greeting is printed once. 

D. Greeting is printed twice. 

E. No new threads of execution are started within the main method. 

F. One new thread of execution is started within the main method. 

G. Two new threads of execution are started within the main method. 

Answer: C,E 

Explanation: 

Thread t2 is executed. Execution of T2 starts executionen of t1. Greeting is printed during theexecution of t1. 


Q11. Which two are true about Singletons? 

A. A Singleton must implement serializable. 

B. A Singleton has only the default constructor. 

C. A Singleton implements a factory method. 

D. A Singleton improves a class's cohesion. 

E. Singletons can be designed to be thread-safe. 

Answer: C,E 


Q12. Given: 

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%spants that cost $%s.\\n",quantity, color, price); 

Answer: A,C 


Q13. 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:


Q14. Given: What is the result? 

A. 1 

B. 0 

C. 2 

D. Compilation fails 

E. An exception is thrown at runtime 

Answer:

Explanation: Section: (none) 

Explanation 

The code compiles fine. 

java.lang.NullPointerException 

because only one element of list is initialized : element [0] 

elements [1] and [2] equals null 

alte Begründung: 

An exception is thrown at runtime due to data type comparison mismatch: 

Exception in thread "main" java.lang.ClassCastException: java.lang.String cannot be cast 

to java.lang.Integer 

at java.lang.Integer.compareTo(Integer.java:52) 

at java.util.Arrays.binarySearch0(Arrays.java:1481) 

at java.util.Arrays.binarySearch(Arrays.java:1423) 

at searchtext.SearchText.main(SearchText.java:22) 

Note:binarySearch 

public static int binarySearch(char[] a, 

char key)Searches the specified array of chars for the specified value using the binary 

search algorithm. The array mustbe sorted (as by the sort method, above) prior to making 

this call. If it is not sorted, the results are undefined. Ifthe array contains multiple elements 

with the specified value, there is no guarantee which one will be found. 

Parameters: 

a - the array to be searched. 

key - the value to be searched for. 

Returns: 

Indexof the search key, if it is contained in the list; otherwise, (-(insertion point) - 1). The 

insertionpoint is defined as the point at which the key would be inserted into the list: the 

index of the first elementgreater than the key, or list.size(), if all elements in the list are less 

than the specified key. Note that thisguarantees that the return value will be >= 0 if and 

only if the key is found. 


Q15. Which statement declares a generic class? 

A. public class Example < T > { } 

B. public class <Example> { } 

C. public class Example <> { } 

D. public class Example (Generic) { } 

E. public class Example (G) { } 

F. public class Example { } 

Answer:

Explanation: 

Example: 

public class Pocket<T> 

private T value; 

public Pocket() {} 

public Pocket( T value ) { this.value = value; } 

public void set( T value ) { this.value = value; } 

public T get() { return value; } 

public boolean isEmpty() { return value != null; } 

public void empty() { value = null; }