1Z0-804 | The Secret of Oracle 1Z0-804 practice test


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

Q82. Given: 

Which two are true about the lines labeled A through D? 

A. The code compiles and runs as is. 

B. If only line A is removed, the code will compile and run. 

C. If only line B is removed, the code will compile and run. 

D. If only line D is removed, the code will compile and run. 

E. Line C is optional to allow the code to compile and run. 

F. Line C is mandatory to allow the code to compile andrun. 

Answer: A,E Explanation: 

A: The code will compile. The abstract method doDock() is implemented fine, and doFloat() isoverridden. 

E: Line C overrides the implementation of doFloat(). This is optional. 

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

Q84. View the exhibit: 

Given the code fragment: 

What is the result? 

A. Compilation fails 

B. 6 

C. 4 

D. 1 

E. 3 

F. Not possible to answer due to missing exhibit. 

Answer:

Explanation: 

C: 4 Falls ge.ndert zu: return FileVisitResult.CONTINUEsonst A: weil CONTINUE als Konstante unbekannt Note: TheFileSystems.getDefault() returns the default FileSystem. The default file system creates objects thatprovide access to the file systems accessible to the Java virtual machine. The working directory of the filesystem is the current user directory, named by the system property user.dir. 

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

Answer: B,D 

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 

Q86. The two methods of code reuse that aggregate the features located in multiple classes are ____________ ? 

A. Inheritance 

B. Copy and Paste 

C. Composition 

D. Refactoring 

E. Virtual Method Invocation 

Answer: A,C 

Explanation: 

A: Inheritance is a way of reusing code and building bigger more functional objects from a 

basic object. 

The original little object, the parent, is called the super-class. The more functional object 

that inherits from it iscalled the sub-class . 

C: When your goal is code reuse, composition provides an approach that yields easier-to-change code. 

Q87. Which two properly implement a Singleton pattern? 

A. class Singleton { 

private static Singleton instance; 

private Singleton () {} 

public static synchronized Singleton getInstance() { 

if (instance == null) { 

instance = new Singleton (); 

return instance; 

B. class Singleton { 

private static Singleton instance = new Singleton(); 

protected Singleton () {} 

public static Singleton getInstance () { 

return instance; 

C. class Singleton { 

Singleton () {} 

private static class SingletonHolder { 

private static final Singleton INSTANCE = new Singleton (); 

public static Singleton getInstance () { 

return SingletonHolder.INSTANCE; 

D. enum Singleton { 

INSTANCE; 

Answer: A,D 

Explanation: 

A: Here the method for getting the reference to the SingleTon object is correct. 

B: The constructor should be private 

C: The constructor should be private 

Note: Java has several design patterns Singleton Pattern being the most commonly used. 

Java Singletonpattern belongs to the family of design patterns, that govern the instantiation process. This design patternproposes that at any time there can only be one instance of a singleton (object) created by the JVM. 

The class's default constructor is made private, which prevents the direct instantiation of the object by others(Other Classes). A static modifier is applied to the instance method that returns the object as it then makes thismethod a class level method that can be accessed without creating an object. OPTION A == SHOW THE LAZY initialization WITHOUT DOUBLE CHECKED LOCKING TECHNIQUE ,BUT ITS CORRECT OPTION D == Serialzation and thraead-safety guaranteed and with couple of line of code enum Singletonpattern is best way to create Singleton in Java 5 world. AND THERE ARE 5 WAY TO CREATE SINGLETON CLASS IN JAVA 1>>LAZY LOADING (initialization) USING SYCHRONIZATION 2>>CLASS LOADING (initialization) USINGprivate static final Singleton instance = new Singleton(); 3>>USING ENUM 4>>USING STATIC NESTED CLASS 5>>USING STATIC BLOCK AND MAKE CONSTRUCTOR PRIVATE IN ALL 5 WAY. 

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

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

Q90. Which is a factory method from the java.text.NumberFormat class? 

A. format (long number) 

B. getInstance() 

C. getMaxiraumFractionDigits () 

D. getAvailableLocales () 

E. isGroupingUsed() 

Answer:

Explanation: 

To obtain a NumberFormat for a specific locale, including the default locale, call one ofNumberFormat's factory methods, such as getInstance(). Reference:java.textClass DecimalFormat