Pass4sure 1Z0-804 Questions are updated and all 1Z0-804 answers are verified by experts. Once you have completely prepared with our 1Z0-804 exam prep kits you will be ready for the real 1Z0-804 exam without a problem. We have Down to date Oracle 1Z0-804 dumps study guide. PASSED 1Z0-804 First attempt! Here What I Did.
Q11. 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: B
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.
Q12. 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: D
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;
}}
Q13. Given a language code of fr and a country code of FR, which file name represents a resource bundle file namethat is not the default?
A. MessageBundle_fr_FR.properties
B. MessageBundle_fr_FR.profile
C. MessageBundle_fr_FR.xinl
D. MessageBundle__fr__FR.Java
E. MessageBundle__fr__FR.Locale
Answer: A
Explanation:
The default file is MessageBundle.properties. The non-default file name is
MessageBundle_fr_FR.properties
Note 0:.properties is a file extension for files mainly used in Java related technologies to
store the configurableparameters of an application. They can also be used for storing
strings for Internationalization and localization;these are known as Property Resource
Bundles. Each parameter is stored as a pair of strings, one storing thename of the
parameter (called the key), and the other storing the value.Note 1:You can obtain an
instance of ResourceBundle by calling its static getBundle method.public static
ResourceBundle getBundle(java.lang.String baseName) public static ResourceBundle
getBundle(java.lang.String baseName, Locale locale) For example:
ResourceBundle rb = ResourceBundle.getBundle("MyResources", Locale.US); This will
load theResourceBundle object with the values in the corresponding properties file.1.If a
suitable properties file is not found, the ResourceBundle object will use the default
properties file, whichwill be the one whose name equals the base name and has the
properties extension. In this case, the defaultfile would be MyResources.properties. 2.If this
file is not found, a java.util.MissingResourceException will bethrown.
Note2:java.util.ResourceBundle class enables you to choose and read the properties file
specific to the user'slocale and look up the values.
A ResourceBundle object has a base name. In order for a ResourceBundle object to pick
up a properties file,the filename must be composed of the ResourceBundle base name,
followed by an underscore, followed bythe language code, and optionally followed by
another underscore and the country code.
The format for the properties file name is as follows:
basename_languageCode_countryCode
For example, suppose the base name is MyResources and you define the following three
locales:
US-en DE-de CN-zh Then you would have these three properties files: MyResources_en_US.properties MyResources_de_DE.properties MyResources_zh_CN.properties
Reference:Reading Properties Files using ResourceBundle
Q14. Which four are true about enums?
A. An enum is typesafe.
B. An enum cannot have public methods or fields.
C. An enum can declare a private constructor.
D. All enums implicitly implement Comparable.
E. An enum can subclass another enum.
F. An enum can implement an interface.
Answer: A,C,D,F Explanation:
C: The constructor for an enum type must be package-private or private access. Reference: Java Tutorials,Enum Types
Q15. Given: What is the result?
A. 1
B. 0
C. 2
D. Compilation fails
E. An exception is thrown at runtime
Answer: E
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.
Q16. 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: E
Explanation:
error: incompatible types e = new Exception(); required: RuntimeException found: Exception
Q17. Given the code fragment:
Assume that the SQL query matches one record. What is the result of compiling and executing this code?
A. The code prints Error.
B. The code prints the employee ID.
C. Compilation fails due to an error at line 13.
D. Compilation fails due to an error at line 14.
Answer: A
Explanation:
The code compiles fine.
A: prints Error: rs.next() fehlt !! Fehlermeldung: Before start of result set mit rs.next() Aufruf : The code would run fine. public int getInt(String columnName) throws SQLException Retrieves the value of the designated column in the current row of this ResultSet object as an int in the Javaprogramming language
Q18. ITEM Table
*
ID, INTEGER: PK
*
DESCRIP, VARCHAR(100)
*
PRICE, REAL
*
QUALITY, INTEGER
And given the code fragment (assuming that the SQL query is valid):
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
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.
Q19. Given the following files in doc directory: -Index.htm
-Service.html
-Logo.gif
-Title.jpg
And the code fragment:
What is the result, if doc is present in the current directory?
A. No output is produced.
B. index.htm
C. index.htm userguide.txt logo.gif
D. index.htm service.html userguide.txt logo.gif
Answer: A
Explanation:
The Glob search expression is defined through "glob:*.htm, html, xml" The correct answer is A The glob is trying to match all the string. The correct way is
glob:*.{htm,html,xml}
and then would be found:
Index.htm
Service.html
Q20. Which code fragment demonstrates the proper way to handle JDBC resources?
A. try {
ResultSet rs = stmt.executeQuery (query);
statement stmt = con.createStatement();
while (rs.next()) (/* . . . */)
} catch (SQLException e) {}
B. try {
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery (query);
while (rs.next()) (/* . . . */)
} catch (SQLException e) {}
C. try {
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery (query);
while (rs.next()) (/* . . . */)
} finally {
rs.close();
stmt.close();
}
D. try {
ResultSet rs = stmt.executeQuery (query);
Statement stmt = con.createStatement();
while (rs.next()) (/* . . . */)
} finally {
rs.close();
stmt.close();
}
Answer: C