Click here to load reader

1z0 809 dumps

  • View

  • Download

Embed Size (px)

Text of 1z0 809 dumps

Free On-Line Java 8 Certification Test

Oracle JAVA8 1Z0-809 Available Here: now to get full access to a set of three 1Z0-809 Dumps Exams. Enrolling now you will get access to 340 unique Java 8 Certification Questions.

Q1. Consider the following class:

public final class Program {final private String name;Program (String name){ = name;getName();}//code here}

Which of the following codes will make an instance of this class immutable?

A. public String getName(){return name;}B. public String getName(String value){ name=value; return value;}C. private String getName(){return name+"a";}D. public final String getName(){return name+="a";}E. All of Above.

Option A,C are correct.

Option B and D have a compile error since name variable is final.Option C is private and doesn't change the name value.Option A is public and doesn't change the name value.

Exam Objective: Encapsulation and Subclassing - Making classes immutable.Oracle Reference :

Q2. Consider the following code:

1.class SuperClass{2.protected void method1(){3.System.out.print("M SuperC");4.}5.}6.7.class SubClass extends SuperClass{8.private void method1(){9.System.out.print("M SubC");10.}11.12.public static void main(String[] args){13.SubClass sc = new SubClass();;15.}16.}

What will be the result?

A. M SubC.B. M SuperC.C. M SuperCM SubC.D. Compilation fails.E. None of above.

Option D is correct.The code fails to compile at line 8 as it cannot reduce the visibility of the inherited method from SuperClass.

Exam Objective: Encapsulation and Subclassing - Creating and use Java subclasses.Oracle Reference :

Q3. Given the following class:

1.public class Test {2.public static void main(String args[]) {3.//Code Here4.Thread thread = new Thread(r);5.thread.start();6.}7.}

Which of the following lines will give a valid Thread creation?

A.Thread r = () -> System.out.println("Running");B.Run r = () -> System.out.println("Running");C.Runnable r = () -> System.out.println("Running");D.Executable r = () -> System.out.println("Running");E.None Of Above

Option C is correct.Option A,B, and 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 :

Q4. Which of the following database urls are correct?

A. jdbc:mysql://localhost:3306B. jdbc:mysql://localhost:3306/sampleC. jdbc:mysql://localhost:3306/sample/user=root?password=secretD. jdbc:mysql://localhost:3306/sample?user=root&password=secretE. All

Option A,B and D are correct.The correct url format is the following:jdbc:mysql://[host][,failoverhost...][:port]/[database][?propertyName1][=propertyValue1][&propertyName2][=propertyValue2]...So C is incorrect and A,B and D are correct.

Exam Objective: Database Applications with JDBC - Connecting to a database by using a JDBC driver.Oracle Reference :

Q5. Given the following code:

1.public class Program {2.3.public static void main (String args[]) throws IOException {4.Console c = System.console(); i = (int)c.readLine("Enter value: ");6.for (int j = 0; j < i; j++) {7.c.format(" %2d",j);8.}9.}10.}

What will be the result of entering the value 5?

A. 1 2 3 4 5B. 0 1 2 3 4C. 0 2 4 6 8D. The code will not compile because of line 5.E. Unhandled exception type NumberFormatException at line 7.

Option D is correct.The method's signature "int readLine(String fmt, Object... args)" doesn't exist asthe right method's signature returns a String so line 5 will give a compile error and option D is right.

Exam Objective: I/O Fundamentals - Read and write data from the consoleOracle Reference :

Q6. 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;};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.}

What will be the result?

A. 18B. 7C. 6D. The code will not compile.E. None of above

Option C is correct.The class "Singleton" 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 classesOracle Reference :

Q7. Given the following class:

1.public class Program {2.3.public static void main(String[] args) {4.5.List list = Arrays.asList(4,6,12,66,3);6.7.String s = i -> {8.return ""+(i+1);9.}).reduce("", String::concat);10.11.System.out.println(s);12.}13.}

What will be the result?

A. 4612663B. 5713674C. 3661264D. The code will not compile because of line 7.E. Unhandled exception type NumberFormatException al line 8.

Option B is correct.The Program is 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 syntaxOracle Reference :

Q8. Which of the following are correct overrides of Object class?

I. public int hashCode();II.public String toString();III. public boolean equals(Object obj);IV.public Class getClass();

A. I, II, III, IV.B. I, II, III. C. I, II. D. III, IV.E. All.

Option B is correct.The Object class has all the methods signature specified above so the override is possible on all options except IV because is declared final in Object class, so B is correct.

Exam Objective: Java Class Design - Override hashCode, equals, and toString methods from Object classOracle Reference :

Q9. Consider the following class:

1.public class Test {2.public static int count(T[] array, T elem) { count = 0;4.for (T e : array)5.if( e.compareTo(elem) > 0) ++count;6.7.return count;8.}9.public static void main(String[] args) {10.Integer[] a = {1,2,3,4,5}; n = Test.count(a, 3);12.System.out.println(n);13.}14.}

What will be the result?

A. 2B. 3C. The code will not compile because of line 5.D. An exception is thrown.E. None of Above.

Option C is correct.C is correct 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 int count(T[] array, T elem) {

Exam Objective: Collections and Generics - Creating a custom generic classOracle Reference :

Q10. Given the following class:

1.public class Program {2.public static void main(String[] args) {3.4.Thread th = new Thread(new Runnable(){5.6.static {7.System.out.println("initial");8.}[email protected] void run() {12.System.out.println("start");13.}14.});;17.}18.}

What will be the result?

A. start initialB. initial startC. initialD. A runtime exception is thrown.E. The code will not compile because of line 6.

Option E is correct.Because you cannot 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 classesOracle Reference :

Q11. Consider the following class: 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);20.System.out.print(im);21.22.a.setA(" bye");23.System.out.print(im);24.}25.}

What will be the result?

A. Bye byeB. Bye ByeC. ByeBye byeD. Compilation failureE. None of Above

Option C is correct.

In order for 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

Search related