Oracle 1Z0-804 Dumps Questions 2021
Proper study guides for 1Z0-804 Java SE 7 Programmer II Exam certified begins with preparation products which designed to deliver the by making you pass the 1Z0-804 test at your first time. Try the free right now.
Online 1Z0-804 free questions and answers of New Version:
NEW QUESTION 1
Given:
String s = new String("3");
System.out.print(1 + 2 + s + 4 + 5);
What is the result?
- A. 12345
- B. 3345
- C. 1239
- D. 339
- E. Compilation fails.
Answer: B
Explanation: 1 and 2 are added.
Then the string s is concatenated.
Finally 3 and 4 are concatenated as strings.
NEW QUESTION 2
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: AC
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.
NEW QUESTION 3
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: AD
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.
NEW QUESTION 4
What are two differences between Callable and Runnable?
- A. A Callable can return a value when executing, but a Runnable cannot.
- B. A Callable can be executed by a ExecutorService, but a Runnable cannot.
- C. A Callable can be passed to a Thread, but a Runnable cannot.
- D. A Callable can throw an Exception when executing, but a Runnable cannot.
Answer: AD
Explanation: The Callable interface is similar to Runnable, in that both are designed for classes whose instances arepotentially executed by another thread. A Runnable, however, does not return a result and cannot throw achecked exception.
NEW QUESTION 5
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.
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.
NEW QUESTION 6
Given two classes in separate files:
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.*;
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
NEW QUESTION 7
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: AE
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.
NEW QUESTION 8
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: CD
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 SettingsuseralboDesktop1.jpg
NEW QUESTION 9
Given:
What is the result?
- A. p001 Widget p002 X-Large Widget
- B. p002 Large Widget p001 Widget
- C. p002 X-large Widget p001 Widget
- D. p001 Widget p002 Large Widget
- E. compilation fails
Answer: A
Explanation: Compiles fine. Output is: P001 Widget
P002 X-Large Widget
Line: partList.put("P002", "X-Large Widget"); >> overwrites >> line:partList.put("P002", "Large Widget");
put
V put(K key, V value)
Associates the specified value with the specified key in this map (optional operation). If the map previouslycontained a mapping for the key, the old value is replaced by the specified value. (Amap m is said to contain amapping for a key k if and only if m.containsKey(k) would return true.)
Parameters:
key - key with which the specified value is to be associated value - value to be associated with the specified key
Returnsthe previous value associated with key, or null if there was no mapping for key. (A null return can alsoindicate that the map previously associated null with key, if the implementation supports null values.)
NEW QUESTION 10
Which is a factory method from the java.text.NumberFormat class?
- A. format (long number)
- B. getInstance()
- C. getMaxiraumFractionDigits ()
- D. getAvailableLocales ()
- E. isGroupingUsed()
Answer: B
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
NEW QUESTION 11
Which code example specifies valid keys menu1 and menu2 with values of File Menu and View Menu?
- A. <key name ="menu1">File Menu</key><key name ="menu1">View Menu</key>
- B. <key> menu1</key><File Menu>File Menu </value><key> menu1</key><File Menu>View Menu </value>
- C. menu1m File menu, menu2, view menu
- D. menu1 = File Menu menu2 = View Menu
Answer: D
Explanation: A properties file is a simple text file. You can create and maintain a properties file with just aboutany text editor.
You should always create a default properties file. The name of this file begins with the base name of your
ResourceBundle and ends with the .properties suffix. In the PropertiesDemo program the base name is
LabelsBundle. Therefore the default properties file is called LabelsBundle.properties. The following examplefilecontains the following lines:
# This is the default LabelsBundle.properties file s1 = computer
s2 = disk
s3 = monitor s4 = keyboard
Note that in the preceding file the comment lines begin with a pound sign (#). The other lines contain key-valuepairs. The key is on the left side of the equal sign and the value is on the right. For instance, s2 is the key thatcorresponds to the value disk. The key is arbitrary. We could have called s2 something else, like msg5 ordiskID. Once defined, however, the key should not change because it is referenced in the source code. Thevalues may be changed. In fact, when your localizers create new properties files to accommodate additionallanguages, they will translate the values into various languages.
NEW QUESTION 12
Which class(es) safely protects the doIt () method from concurrent thread access?
- A. Option A
- B. Option B
- C. Option C
- D. Option D
Answer: AD
Explanation: only A und D possible
It should be pointed out that: public void blah() { synchronized (this) {
// do stuff
}}
is semantically equivalent to: public synchronized void blah() {
// do stuff
}
Incorrect ____________B: A constructor cannot be synchronized. () Object cannot be resolved to a type C: in static context (static void main !) no reference to this possible
NEW QUESTION 13
Given:
What is the result?
- A. Pastel Enamel Fresco Gouache
- B. Pastel*Enamel Fresco*Gouache
- C. Pastel Enamel Fresco Gouache
- D. Pastel Enamel, Fresco Gouache
Answer: B
Explanation: regex explanation:
, = ,
= masks the following
s = A whitespace character: [ t n x0B f r ]
* = Greedy Quantifier: zero or more times
Delimiter: comma + zero or more whitespace characters
NEW QUESTION 14
Given:
What is the result?
- A. Three
- B. One
- C. Compilation fails.
- D. The program runs, but prints no output.
Answer: A
Explanation: push
void push(E e)
Pushes an element onto the stack represented by this deque (in other words, at the head of this deque) if it ispossible to do so immediately without violating capacity restrictions, returning true upon success and throwingan IllegalStateException if no space is currently available.
This method is equivalent to addFirst(E). pop
E pop()
Pops an element from the stack represented by this deque. In other words, removes and returns the firstelement of this deque.
This method is equivalent to removeFirst(). Returns:
the element at the front of this deque (which is the top of the stack represented by this deque)
Throws:
NoSuchElementException - if this deque is empty
NEW QUESTION 15
Given the code fragment:
What is the result?
- A. Null B D
- B. Null B null D
- C. B D
- D. D
- E. An exception is thrown at runtime
Answer: C
NEW QUESTION 16
Given the classes:
What is the result?
- A. John Harry
- B. unknown Harry
- C. john unknown
- D. unknown unknown
- E. Compilation fails.
- F. An exception is thrown at runtime.
Answer: B
Explanation: getName() is missing in John, hence Pupils getName() is invoked and the String in Pupils scope returned.
NEW QUESTION 17
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: D
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
NEW QUESTION 18
Given:
What is the result?
- A. Event Quiz
- B. Event Event
- C. Quiz Quiz
- D. Quiz Event
- E. Compilation fails
Answer: E
NEW QUESTION 19
Given:
Which two are true?
- A. Thread is printed
- B. Runnable is printed
- C. No output is produced
- D. No new threads of execution are started within the main method
- E. One new thread of execution is started within the main method
- F. Two new threads of exclusion are started within the main method
Answer: CD
NEW QUESTION 20
Given:
Which two statements are true about the writer class?
- A. It compiles without any changes.
- B. It compiles if the code void write (String s); is added at line***.
- C. It compiles if the code void write (); is added at line ***.
- D. It compiles if the code void write (string s) { } is added at line ***.
- E. It compiles if the code write () {}is added at line ***.
Answer: A
Explanation: An abstract class does not need to implement the interface methods.
100% Valid and Newest Version 1Z0-804 Questions & Answers shared by Certleader, Get Full Dumps HERE: https://www.certleader.com/1Z0-804-dumps.html (New 150 Q&As)