1Z0-809 PDF DOWNLOAD

How to use our free PDF

Our Free PDF is based on the full mock exams which is available on our Web Site. The PDF consists in an extract of questions and answers with detailed explanations that are available to be:

Follow us on SlideShare to see the latest available 1Z0-809 tests pdf.

Watch us also on Vimeo: See how our 1Z0-809 tests works.

										
										
Q1. Consider the following class:

public final class Program {
	
	final private String name;
	
	Program (String name){
		this.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 : https://docs.oracle.com/javase/tutorial/essential/concurrency/imstrat.html



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();
14.			sc.method1();
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 : https://docs.oracle.com/javase/tutorial/java/IandI/subclasses.html



Q3. Given the following class:

1.	public class Test {
2.		public static void main(String args[]) {
3.			//Code Here
4.			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 : https://docs.oracle.com/javase/tutorial/essential/concurrency/



Q4. Which of the following database urls are correct?

A. jdbc:mysql://localhost:3306
B. jdbc:mysql://localhost:3306/sample
C. jdbc:mysql://localhost:3306/sample/user=root?password=secret
D. jdbc:mysql://localhost:3306/sample?user=root&password=secret
E. 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 : https://docs.oracle.com/javase/tutorial/jdbc/overview/



Q5. Given the following code:

1.	public class Program {
2.	
3.		public static void main (String args[]) throws IOException {
4.			Console c = System.console();
5.			int 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 5
B. 0 1 2 3 4
C. 0 2 4 6 8
D. 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 as
the 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 console
Oracle Reference : https://docs.oracle.com/javase/tutorial/essential/io/cl.html



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. 18
B. 7
C. 6
D. 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 classes
Oracle Reference : https://docs.oracle.com/javase/tutorial/essential/concurrency/imstrat.html


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 = list.stream().map( i -> {
8.				return ""+(i+1);
9.			}).reduce("", String::concat);
10.		
11.			System.out.println(s);
12.		}
13.	}

What will be the result?

A. 4612663
B. 5713674
C. 3661264
D. 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 syntax
Oracle Reference : https://docs.oracle.com/javase/8/docs/api/java/util/stream/package-summary.html



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 class
Oracle Reference : https://docs.oracle.com/javase/tutorial/java/IandI/objectclass.html



Q9. Consider the following class:

1.	public class Test {
2.		public static  int count(T[] array, T elem) {
3.			int 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}; 
11.			int n = Test.count(a, 3);
12.			System.out.println(n);
13.		}
14.	}

What will be the result?

A. 2
B. 3
C. 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 class
Oracle Reference : https://docs.oracle.com/javase/tutorial/java/generics/methods.html



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.				}
9.			
10.				@Override
11.				public void run() {
12.					System.out.println("start");
13.				}
14.			});
15.		
16.			th.start();
17.		}
18.	}

What will be the result?

A. start initial
B. initial start
C. initial
D. 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 classes
Oracle Reference : https://docs.oracle.com/javase/tutorial/java/javaOO/anonymousclasses.html