It is more faster and easier to pass the Oracle 1Z0-804 exam by using Free Oracle Java SE 7 Programmer II Exam questuins and answers. Immediate access to the Updated 1Z0-804 Exam and find the same core area 1Z0-804 questions with professionally verified answers, then PASS your exam with a high score now.

Q16. Given that myfile.txt contains: 

What is the result? 

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 

Answer:

Explanation: 

For each line in the file myfile.text the line number and the line is written into newfile.txt. 


Q17. To provide meaningful output for: 

System.out.print( new Item ()): 

A method with which signature should be added to the Item class? 

A. public String asString() 

B. public Object asString() 

C. public Item asString() 

D. public String toString() 

E. public object toString() 

F. public Item toString() 

Answer:

Explanation: 

Implementing toString method in java is done by overriding the Object's toString method. 

The javatoString() method is used when we need a string representation of an object. It is 

defined in Object class. Thismethod can be overridden to customize the String 

representation of the Object. 

Note: 

Below is an example shown of Overriding the default Object toString() method. The 

toString() method must bedescriptive and should generally cover all the contents of the 

object. 

class PointCoordinates { 

private int x, y; 

public PointCoordinates(int x, int y) { 

this.x = x; 

this.y = y; 

public int getX() { 

return x; 

public int getY() { 

return y; 

// Custom toString() Method. 

public String toString() { 

return "X=" + x + " " + "Y=" + y; 

}} 


Q18. Given: 

ConcurrentMap <String, String> PartList = new ConcurrentMap<>(); 

Which fragment puts a key/value pair in partList without the responsibility of overwriting an existing key? 

A. partList.out(key,"Blue Shirt"); 

B. partList.putIfAbsent(key,"Blue Shirt"); 

C. partList.putIfNotLocked (key,"Blue Shirt"); 

D. partList.putAtomic(key,"Blue Shirt") 

E. if (!partList.containsKey(key)) partList.put (key,"Blue Shirt"); 

Answer:

Explanation: 

putIfAbsent(K key, V value) 

If the specified key is not already associated with a value, associate it with the given value. 

Reference:java.util.concurrent,Interface ConcurrentMap<K,V> 


Q19. Given: 

Which statement will iterate through Direction? 

A. for (Direction d : Direction.values()){ // 

B. for (Direction d : Direction.asList()){ 

// 

C. for (Direction d : Direction.iterator()){ 

// 

D. for (Direction d : Direction.asArray()){ 

// 

Answer:

Explanation: 

The static values() method of an enum type returns an array of the enum values. The 

foreach loop is a good 

way to go over all of them. 

//... Loop over all values. 

for (Direction d : Direction.values()){ 

System.out.println(d); // PrintsNORTH, EAST, ... 


Q20. Given: 

What is the result? 

A. John-.-George-.-Paul-.-Ringo 

B. John George Paul Ringo 

C. John -George -Paul -Ringo -

D. An exception is thrown at runtime 

E. Compilation fails 

Answer:

Explanation: 

The split() method is used to split a string into an array of substrings, and returns the new array. regex: - followed by two characters 


Q21. 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. 


Q22. Given: 

What two changes should you make to apply the DAO pattern to this class? 

A. Make the Customer class abstract. 

B. Make the customer class an interface. 

C. Move the add, delete, find, and update methods into their own implementation class. 

D. Create an interface that defines the signatures of the add, delete, find, and update methods. 

E. Make the add, delete, and find, and update methods private for encapsulation. 

F. Make the getName and getID methods private for encapsulation. 

Answer: C,D 

Explanation: 

C:The methods related directly to the entity Customer is moved to a new class. 

D: Example (here Customer is the main entity): 

public class Customer { 

private final String id; 

private String contactName; 

private String phone; 

public void setId(String id) { this.id = id; } 

102 

public String getId() { return this.id; } public void setContactName(String cn) { this.contactName = cn;} public String getContactName() { return this.contactName; } public void setPhone(String phone) { this.phone = phone; } public String getPhone() { return this.phone; } } public interface CustomerDAO { public void addCustomer(Customer c) throws DataAccessException; public Customer getCustomer(String id)throws DataAccessException; public List getCustomers() throws DataAccessException; public void removeCustomer(String id) throws DataAccessException; public void modifyCustomer(Customer c) throws DataAccessException; } Note: DAO Design Pattern *Abstracts and encapsulates all access to a data source *Manages the connection to the data source to obtainand store data *Makes the code independent of the data sources and data vendors (e.g. plain-text, xml, LDAP, MySQL, Oracle, DB2) 

D:\Documents and Settings\useralbo\Desktop\1.jpg 


Q23. Given: 

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. 

Answer:


Q24. Given: 

What is the result? 

A. Event Quiz 

B. Event Event 

C. Quiz Quiz 

D. Quiz Event 

E. Compilation fails 

Answer:


Q25. 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; } 


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


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

Explanation: 

error: incompatible types e = new Exception(); required: RuntimeException found: Exception 


Q28. Given: 

And the commands: javac Counter.java java ea Counter 

What is the result? 

A. 2 

B. 3 

C. NullPointException is thrown at runtime 

D. AssertionError is thrown at runtime 

E. Compilation fails 

Answer:

Explanation: 

The command line javac Counter.java 

Willcompile the code. 

The command line java ea Counter 

Willrun the cod with assertions enabled. 

Assertion is true because getCount(arr) = 3 and Length of array is 4 

The following line: 

assert (getCount(arr) < arr.length); 

where the Boolean expression getCount(arr) < arr.length will evaluate to false, will ensure 

that anAssertionError is thrown at runtime. 

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

the Java interpreter -the java command - to interprete the Java bytecodes. 

Note 2: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 3: 

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. 


Q29. Given the code fragment: 

Assume the method printNums is passed a valid array containing data. Why is this method not producingoutput on the console? 

A. There is a compilation error. 

B. There is a runtime exception. 

C. The variable number is not initialized. 

D. Standard error is mapped to another destination. 

Answer:

Explanation: 

The code compiles fine. 

The code runs fine. 

The errorstream can be redirected. 

Note: 

System.out.println -> Sends the output to a standard output stream. Generally monitor. 

System.err.println -> Sends the output to a standard error stream. Generally monitor. err is 

the "standard" erroroutput stream. This stream is already open and ready to accept output 

data. 

Typically this stream corresponds to display output or another output destination specified 

by the hostenvironment or user. By convention, this output stream is used to display error 

messages or other informationthat should come to the immediate attention of a user even if the principal output stream, the value of thevariable out, has been redirected to a file or other destination that is typically not continuously monitored. 

Reference:java.lang.System 


Q30. Given: 

What is the result? 

A. false \sales\quarter\ . . \qtrlreport.txt 

B. false \quarter\ . . \qtrlreport.txt 

C. true . . \ . . \ . . \ annualreport.txt 

D. true \ . . \ . . \annualreport.txt 

Answer:

Explanation: 

( richtig !! import java.nio.file.Path; import java.nio.file.Paths; ) original-Aufgabe war ( falsch >> import java.io.file.Path; import java.io.file.Paths; ) The relativize method that can be used to construct a relative path between two paths. relativize Path relativize(Path other) Constructs a relative path between this path and a given path. Parameters:other - the path to relativize against this path Returns:the resulting relative path, or an empty path if both paths are equal Note: Relativization is the inverse of resolution. This method attempts to construct a relative path that when resolvedagainst this path, yields a path that locates the same file as the given path. For18example, on UNIX, if this path is "/a/b" and the given path is "/a/b/c/d" then the resulting relative path would be"c/d". Where this path and the given path do not have a root component, then a relative path can beconstructed. A relative path cannot be constructed if only one of the paths have a root component. Where bothpaths have a root component then it is implementation dependent if a relative path can be constructed. If thispath and the given path are equal then an empty path is returned. For any two normalized paths p and q, where q does not have a root component,p.relativize(p.resolve(q)).equals(q) When symbolic links are supported, then whether the resulting path, when resolved against this path, yields apath that can be used to locate the same file as other is implementation dependent. For example, if this path is"/a/b" and the given path is "/a/x" then the resulting relative path may be "../x". If "b" is a symbolic link then isimplementation dependent if "a/b/../x" would locate the same file as "/a/x".