Professional Documents
Culture Documents
Java SE 8 Programmer II
Java 1Z0-809 Dumps Available Here at:
https://www.certification-questions.com/java-exam/1z0-809-dumps.html
Enrolling now you will get access to 425 questions in a unique set of 1Z0-
809 dumps
Question 1
Consider the following class:
getName();
}
//code here
}
Which of the following codes will make an instance of this class immutable?
Options:
E. All of Above.
Answer: A, C
Explanation:
D have a compile error since name variable is final.
Option C is private and doesn't change the name value.
https://www.certification-questions.com
Java 1Z0-809
Question 2
Given the following class:
Options:
E. None Of Above
Answer: C
Explanation:
nd D are incorrect as they are not functional interfaces, so C is the only valid option.
Exam Objective : Concurrency - Creating worker threads using Runnable and Callable.
Oracle Reference : https://docs.oracle.com/javase/tutorial/essential/concurrency/
Question 3
Given the following class:
1. class Singleton {
2. private int count = 0;
3. private Singleton(){};
4. public static final Singleton getInstance(){ return new Singleton(); };
5. public void add(int i){ count+=i; };
6. public int getCount(){ return count;};
https://www.certification-questions.com
Java 1Z0-809
7. }
8.
9. public class Program {
10. public static void main(String[] args) {
11. Singleton s1 = Singleton.getInstance();
12. s1.add(3);
13. Singleton s2 = Singleton.getInstance();
14. s2.add(2);
15. Singleton s3 = Singleton.getInstance();
16. s2.add(1);
17. System.out.println(s1.getCount()+s2.getCount()+s3.getCount());
18. }
19. }
Options:
A. 18
B. 7
C. 6
E. None of above
Answer: C
Explanation:
ngleton" is not a real singleton class, in fact at each "getInstance()" method invocation
a new object is created, so s1, s2, s3 count instance variable are 3, 2, 1, and then option C is correct.
Exam Objective : Java Class Design - Create and use singleton classes and immutable classes
Oracle Reference : https://docs.oracle.com/javase/tutorial/essential/concurrency/imstrat.html
Question 4
Given the following class:
https://www.certification-questions.com
Java 1Z0-809
8. return ""+(i+1);
9. }).reduce("", String::concat);
10.
11. System.out.println(s);
12. }
13. }
Options:
A. 4612663
B. 5713674
C. 3661264
Answer: B
Explanation:
s applying a map function to the stream generated from list. For each
Integer element "i" the function returns a new String with value i+1.
The stream is then reduced to a String by the concatenation "String::concat" function.
So Option B is correct, and A ,C, D, E are incorrect.
Exam Objective : Collections Streams, and Filters - Iterating through a collection using lambda syntax
Oracle Reference : https://docs.oracle.com/javase/8/docs/api/java/util/stream/package-summary.html
Question 5
Consider the following class:
https://www.certification-questions.com
Java 1Z0-809
13. }
14. }
Options:
A. 2
B. 3
D. An exception is thrown.
E. None of Above.
Answer: C
Explanation:
because the variable "e" is a generic "T" type so the compile has no
knowledge of method "compareTo". In order to make it compile line 2 needs to be changed in:
public static <T extends Comparable<T>> int count(T[] array, T elem) {
Exam Objective : Collections and Generics - Creating a custom generic class
Oracle Reference : https://docs.oracle.com/javase/tutorial/java/generics/methods.html
Question 6
Given the following class:
https://www.certification-questions.com
Java 1Z0-809
18. }
Options:
A. start initial
B. initial start
C. initial
Answer: E
Explanation:
annot declare static initializers in an anonymous class,
the compilation fails at line 6, so E is correct and A, B, C, D are incorrect.
Exam Objective : Interfaces and Lambda Expressions - Anonymous inner classes
Oracle Reference : https://docs.oracle.com/javase/tutorial/java/javaOO/anonymousclasses.html
Question 7
Consider the following class:
1. final class A{
2. private String s;
3. public A(String s){
4. this.s = s;
5. }
6. public String toString(){ return s; };
7. public void setA(String a){ this.s+= a; };
8. }
9.
10. public final class Immutable {
11. private final A a;
12. public Immutable(A a){
13. this.a = a;
14. }
15. public String toString(){ return a.toString();};
16. public static void main(String[] args){
17.
18. A a = new A("Bye");
19. Immutable im = new Immutable(a);
https://www.certification-questions.com
Java 1Z0-809
20. System.out.print(im);
21.
22. a.setA(" bye");
23. System.out.print(im);
24. }
25. }
Options:
A. Bye bye
B. Bye Bye
C. ByeBye bye
D. Compilation failure
E. None of Above
Answer: C
Explanation:
the class "immutable" to be an immutable class it needs to satisfy the following four properties:
1.Don't provide "setter" methods - methods that modify fields or objects reffered to by fields.
2. Make all fields final and private.
3. Don't allow subclasses to override methods. The simplest way to do this is to declare the class as final. A
more sophisticated approach is to
make the constructor private and construct instances in factory methods.
4. If the instance fields include references to mutable objects, don't allow those objects to be changed.
Properties 1,2,3 are satisfied, but unfortunately the last one is not, so the object "a" is mutable because it is
passed by
reference without making a protection copy of it.
So option C is correct and A,B,D,E are incorrect.
Exam Objective : Encapsulation and Subclassing - Making classes immutable.
Oracle Reference : https://docs.oracle.com/javase/tutorial/essential/concurrency/imstrat.html
Question 8
Given the following code:
1. // Code Here
2. @Override
3. public void run() {
4. for(int i = 0;i<10;i++)
5. System.out.print(i);
https://www.certification-questions.com
Java 1Z0-809
6. }
7. }
8.
9. public class Test {
10. public static void main(String args[]) {
11. Task t = new Task();
12. Thread thread = new Thread(t);
13. thread.start();
14. }
15. }
Options:
E. None Of Above
Answer: B
Explanation:
a Thread by passing an implementation of Runnable to a Thread constructor,
so the only correct option is B.
Exam Objective : Concurrency - Creating worker threads using Runnable and Callable.
Oracle Reference : https://docs.oracle.com/javase/tutorial/essential/concurrency/
Question 9
Consider the following class:
https://www.certification-questions.com
Java 1Z0-809
11. }
12. };
13.
14. ExecutorService executor = Executors.newSingleThreadExecutor();
15. Future<String> future = executor.submit(c);
16. try {
17. String result = future.wait();
18. System.out.println(result);
19. } catch (ExecutionException e) {
20. e.printStackTrace();
21. }
22. }
23. }
Options:
A. 0123456789
B. 12345678910
Answer: E
Explanation:
ng a Callable object with an anonymous class at line 5, the syntax is correct so
option C is incorrect.
Passing the object "c" to an executor will get as return type a Future to wait for thread ends.
But at line 17 method wait of Class Future doesn't exist so E is correct.
Exam Objective : Concurrency - Creating worker threads using Runnable and Callable.
Oracle Reference : https://docs.oracle.com/javase/tutorial/essential/concurrency/
Question 10
Which of the following are valid Executors factory methods?
https://www.certification-questions.com
Java 1Z0-809
Options:
A. I, II, III
C. I, IV, V
D. II, IV, V
E. All
Answer: D
Explanation:
ewSingleThreadExecutor" cannot accept parameters so I is incorrect, and
the method "newScheduledThreadPool" with parameters doesn't exist so III is incorrect.
Exam Objective : Concurrency - Using an ExecutorService to concurrently execute tasks.
Oracle Reference : https://docs.oracle.com/javase/tutorial/essential/concurrency/
Would you like to see more? Don't miss our 1Z0-809 PDF
file at:
https://www.certification-questions.com/java-pdf/1z0-809-pdf.html
https://www.certification-questions.com