A. getName (0): C:\ subpath (0, 2): C:\education\report.txt B. getName(0): C:\ subpth(0, 2): C:\education C. getName(0): education subpath (0, 2): education\institute D. getName(0): education subpath(0, 2): education\institute\student E. getName(0): report.txt subpath(0, 2): insritute\student
C. getName(0): education subpath (0, 2): education\institute
Example:
Path path = Paths.get("C:\\home\\joe\\foo");
getName(0)
-> home
subpath(0,2)
Reference: The Java Tutorial, Path Operations
Question 32:
Which statement declares a generic class?
A. public class Example < T >{ } B. public class { } C. public class Example { } D. public class Example (Generic){ } E. public class Example (G) { } F. public class Example { }
A. public class Example < T >{ }
Question 33:
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.
F. The method used to obtain the Executor determines how many Threads are used to execute tasks.
The Executor interface provides a single method, execute, designed to be a drop-in replacement for 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
Question 34:
Given this error message when running your application:
Exception in thread "main" java.util.MissingResourceException: Can't find bundle for base name MessageBundle, locale And given that the MessageBundle.properties file has been created, exists on your disk, and is properly formatted. What is the cause of the error message?
A. The file is not in the environment path. B. The file is not in the classpath. C. The file is not in the javapath. D. You cannot use a file to store a ResourceBundle.
D. You cannot use a file to store a ResourceBundle.
ResourceBundle.getBundle is using a resource name; it isn't called ResourceBundle for nothing. You can create a custom ClassLoader and use that to load the data.
Question 35:
Given:
public class DoubleThread {
public static void main(String[] args) {
Thread t1 = new Thread() {
public void run() {
System.out.print("Greeting");
}
};
Thread t2 = new Thread(t1); // Line 9
t2.run();
}
}
Which two are true?
A. A runtime exception is thrown on line 9. B. No output is produced. C. Greeting is printed once. D. Greeting is printed twice. E. No new threads of execution are started within the main method. F. One new thread of execution is started within the main method. G. Two new threads of execution are started within the main method.
C. Greeting is printed once. E. No new threads of execution are started within the main method.
Thread t2 is executed. Execution of T2 starts executionen of t1. Greeting is printed during the execution of t1.
Question 36:
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()
D. public String toString()
Implementing toString method in java is done by overriding the Object's toString method. The java toString() method is used when we need a string representation of an object. It is defined in Object class. This method 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 be descriptive 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;
}
}
Question 37:
Given:
import java.util.concurrent.atomic.AtomicInteger;
public class AtomicCounter {
private AtomicInteger c = new AtomicInteger(0);
public void increment() {
// insert code here
}
}
Which line of code, inserted inside the increment () method, will increment the value of c?
A. c.addAndGet(); B. c++; C. c = c+1; D. c.getAndIncrement ();
D. c.getAndIncrement ();
getAndIncrement
public final int getAndIncrement()
Atomically increment by one the current value.
Reference: java.util.concurrent.atomic
Question 38:
Given:
public class Test { Integer x; // line 2 public static void main(String[] args) { new Test().go(5); } void go(Integer i) { // line 6 System.out.print(x + ++i); // line 7 } } What is the result?
A. 5 B. 6 C. An exception is thrown at runtime D. Compilation fails due to an error on line 6 E. Compilation fails due to an error on line 7
C. An exception is thrown at runtime
The code compile finem but a java.lang.NullPointerException is thrown at runtime.
X has no value. The code would run if line 2 was changed to: Integer x = 3;
Question 39:
Given:
public enum Direction {
NORTH, EAST, SOUTH, WEST
}
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()){ // }
A. for (Direction d : Direction.values()){ // }
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); // Prints NORTH, EAST, ...
}
Question 40:
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
B. interfaces D. abstract classes
*
When To Use Interfaces
An interface allows somebody to start from scratch to implement your interface or implement your interface in some other code whose original or primary purpose was quite different from your interface. To them, your interface is only incidental, something that have to add on to the their code to be able to use your package. The disadvantage 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 and provides some tools useful for a full implementation. The catch is, code using it must use your class as the base. That may be highly inconvenient if the other programmers wanting to use your package have already developed 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 your abstract class if they choose. The only drawback of doing that is calling methods via their interface name is slightly slower than calling them via their abstract class name.
Nowadays, the certification exams become more and more important and required by more and more
enterprises when applying for a job. But how to prepare for the exam effectively? How to prepare
for the exam in a short time with less efforts? How to get a ideal result and how to find the
most reliable resources? Here on Vcedump.com, you will find all the answers.
Vcedump.com provide not only Oracle exam questions,
answers and explanations but also complete assistance on your exam preparation and certification
application. If you are confused on your 1Z0-804 exam preparations
and Oracle certification application, do not hesitate to visit our
Vcedump.com to find your solutions here.