[Free] Download Latest (March 2016) Oracle 1Z0-804 Real Exam 31-40

Ensurepass

QUESTION 31

ITEM Table

 

* ID, INTEGER: PK

 

* DESCRIP, VARCHAR(100)

 

* PRICE, REAL

 

* QUALITY, INTEGER

 

And given the code fragment (assuming that the SQL query is valid):

 

clip_image002

 

What is the result of compiling and executing this code?

 

A.

An exception is thrown at runtime

B.

Compile fails

C.

The code prints Error

D.

The code prints information about Item 110

 

Correct Answer: C

Explanation:

Tricky:

Compiles successfully ! Not B !

D is correct, if Column Quantity instead of Quality Table Item Column Quality — System.out.println(“Quantity: ” + rs.getInt(“Quantity”)); wenn jedoch so gewollt: die Zeile gibt Error aus (die anderen funktionieren) !!! The connection conn is not defined. The code will not compile.

 

 

 

QUESTION 32

Given two classes in separate files:

 

clip_image004

&
nbsp;

Which two import statements can make the a.b.parent class compliable?

 

A.

import a.b.c.Parent;

B.

import a.b.c.Child;

C.

import a.b.c.*;

D.

import a.b.*;

E.

import a.*;

 

Correct Answer: BC

Explanation:

To import a specific member into the current file, put an import statement at the beginning of thefile before any type definitions but after the package statement, if there is one.C:To import all the types contained in a particular package, use the import statement with the asterisk (*)wildcard character.

Reference: The Java Tutorials,Using Package Members

 

 

QUESTION 33

A valid reason to declare a class as abstract is to:

 

A.

define methods within a parent class, which may not be overridden in a child class

B.

define common method signatures in a class, while forcing child classes to contain unique methodimplementations

C.

prevent instance variables from being accessed

D.

prevent a class from being extended

E.

define a class that prevents variable state from being stored when object Instances are serialized

F.

define a class with methods that cannot be concurrently called by multiple threads

 

Correct Answer: B

Explanation:

Note:An abstract method in Java is something like a pure virtual function in C++ (i.e., a virtualfunction that is declared = 0). In C++, a class that contains a pure virtual function is called an abstract classand cannot be instantiated. The same is true of Java classes that contain abstract methods.

Any class with an abstract method is automatically abstract itself and must be declared as such.

An abstract class cannot be instantiated.

A subclass of an abstract class can be instantiated only if it overrides each of the abstract methods of itssuperclass and provides an implementation (i.e., a method body) for all of them. Such a class is often called aconcrete subclass, to emphasize the fact that it is not abstract.

If a subclass of an abstract class does not implement all the abstract methods it inherits, that subclass is itselfabstract.static, private, and final methods cannot be abstract, since these types of methods cannot be overridden by asubclass. Similarly, a final class cannot contain any abstract methods.

A class can be declared abstract even if it does not actually have any abstract methods. Declaring such a classabstract indicates that the implementation is somehow incomplete and is meant to serve as a superclass forone or more subclasses that will complete the implementation. Such a class cannot be instantiated.

 

 

QUESTION 34

When using the default file system provider with a JVM running on a DOS-based file system, which statementis true?

 

A.

DOS file attributes can be read as a set in a single method call.

B.

DOS file attributes can be changed as a set in a single method call.

C.

DOS file attributes can be modified for symbolic links and regular files.

D.

DOS file attributes can be modified in the same method that creates the file.

 

Correct Answer: A

Explanation:

File attributes associated with a file in a file system that supports legacy “DOS” attributes.

Usage Example:

Path file = …

DosFileAttributes attrs = Files.readAttributes(file, DosFileAttributes.class);

Note:

The methodreadAttributes() reads a file’s attributes as a bulk operation.

 

 

QUESTION 35

Given the Greetings.properties file, containing:

 

clip_image006

 

What is the result?

 

A.

Compilation fails

B.

HELLO_MSG

C.

GOODGYE_NSG

D.

Hello, everyone!

E.

Goodbye everyone!

 

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

 

 

QUESTION 36

Which two forms of abstraction can a programmer use in Java?

 

A.

enums

B.

interfaces

C.

primitives

D.

abstract classes

E.

concrete classes

F.

primitive wrappers

 

Correct Answer: BD

Explanation:

When To Use Interfaces

An interface allows somebody to start from scratch to implement your interface or implement your interface insome other code whose original or primary purpose was quite different from your interface. To them, yourinterface is only incidental, something that have to add on to thetheir code to be able to use your package. Thedisadvantage is every method in the interface must be public. You might not want to expose everything.

 

*When To Use Abstract classes

An abstract class, in contrast, provides more structure. It usually defines some default implementations andprovides some tools useful for a full implementation. The catch is, code using it must use your class as thebase. That may be highly inconvenient if the other programmers wanting to use your package have alreadydeveloped their own class hierarchy independently. In Java, a class can inherit from only one base class.*When to Use Both

You can offer the best of both worlds, an interface and an abstract class. Implementors can ignore yourabstract class if they choose. The only drawback of doing that is calling methods via their interface name isslightly slower than calling them via their abstract class name.

Reference: http://mindprod.com/jgloss/interfacevsabstract.html

 

 

 

 

QUESTION 37

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.

 

Correct Answer: AD

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.

 

 

QUESTION 38

Given the fragment:

 

clip_image008

 

Which two valid alternatives to line 3 would decouple this application from a specific implementation ofCustomerDAO?

 

A.

CustomerDAO custDao = CustomerDAO();

B.

CustomerDAO custDao = (CustomerDAO) new Object ();

C.

CustomerDAO custDao = CustomerDAO.getInstance();

D.

CustomerDAO custDao = (CustomerDAO) new CustomerDAOmemoryImp1();

E.

CustomerDAO custDao = customerDAOFactory.getInstance();

 

Correct Answer: CE

Explanation:

Note: In software development, the term”decoupling”is used to identify the separation of software blocks thatshouldn’t depend on each other. Some building blocks are generic and shouldn’t know details of others.

Special design techniques allow software designers to have as few dependencies as possible. This typicallyreduces the risk of malfunction in one part of a system when the other part changed. It also forces thedeveloper to focus on one thing at a time.

Decoupling lowers or minimizes Coupling.

 

 

QUESTION 39

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 () ;

 

Correct Answer: CDEF

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

 

 

QUESTION 40

Given:

 

clip_image009

 

What is the result?

 

A.

Null

B.

class java.lang.ArraylndexOutOfBoundsException

C.

class java.lang.NullPointerException

D.

class java.lang.Exception

E.

Compilation fails.

 

Correct Answer: E

Explanation:

error: incompatible types

e = new Exception();

required: RuntimeException

found: Exception

 

Free VCE & PDF File for Oracle 1Z0-804 Real Exam

Instant Access to Free VCE Files: CompTIA | VMware | SAP …
Instant Access to Free PDF Files: CompTIA | VMware | SAP …

This entry was posted in 1Z0-804 Real Exam (March 2016) and tagged , , , , , , , . Bookmark the permalink.