1Z0-809 | The Renewal Guide To 1Z0-809 examcollection


Q21. Given the code fragment: 

Path p1 = Paths.get(“/Pics/MyPic.jpeg”); System.out.println (p1.getNameCount() + “:” + p1.getName(1) + “:” + p1.getFileName()); 

Assume that the Pics directory does NOT exist. What is the result? 

A. An exception is thrown at run time. 

B. 2:MyPic.jpeg: MyPic.jpeg 

C. 1:Pics:/Pics/ MyPic.jpeg 

D. 2:Pics: MyPic.jpeg 

Answer:

Q22. Given: 

public enum USCurrency { 

PENNY (1), 

NICKLE(5), 

DIME (10), 

QUARTER(25); 

private int value; 

public USCurrency(int value) { 

this.value = value; 

public int getValue() {return value;} 

public class Coin { 

public static void main (String[] args) { 

USCurrency usCoin =new USCurrency.DIME; 

System.out.println(usCoin.getValue()): 

Which two modifications enable the given code to compile? 

A. Nest the USCurrency enumeration declaration within the Coin class. 

B. Make the USCurrency enumeration constructor private. 

C. Remove the new keyword from the instantion of usCoin. 

D. Make the getter method of value as a static method. 

E. Add the final keyword in the declaration of value. 

Answer: A,E 

Q23. Given the code fragment: 

What is the result? 

A. Found Red Found Default 

B. Found Teal 

C. Found Red Found Blue Found Teal 

D. Found Red Found Blue Found Teal Found Default 

E. Found Default 

Answer:

Q24. For which three objects must a vendor provide implementations in its JDBC driver? 

A. Time B. Date 

C. Statement 

D. ResultSet 

E. Connection 

F. SQLException 

G. DriverManager 

Answer: C,D,E 

Explanation: Database vendors support JDBC through the JDBC driver interface or through the ODBC connection. Each driver must provide implementations of java.sql.Connection, java.sql.Statement, java.sql.PreparedStatement, java.sql.CallableStatement, and java.sql.Re sultSet. They must also implement the java.sql.Driver interface for use by the generic java.sql.DriverManager interface. 

Q25. Which two reasons should you use interfaces instead of abstract classes? 

A. You expect that classes that implement your interfaces have many common methods or fields, or require access modifiers other than public. 

B. You expect that unrelated classes would implement your interfaces. 

C. You want to share code among several closely related classes. 

D. You want to declare non-static on non-final fields. 

E. You want to take advantage of multiple inheritance of type. 

Answer: A,E 

Reference: http://www.programmerinterview.com/index.php/java-questions/interface-vs-abstract-class/ 

Q26. Given the definition of the Emp class: 

public class Emp 

private String eName; 

private Integer eAge; 

Emp(String eN, Integer eA) { 

this.eName = eN; 

this.eAge = eA; 

public Integer getEAge () {return eAge;} 

public String getEName () {return eName;} 

and code fragment: 

List<Emp>li = Arrays.asList(new Emp(“Sam”, 20), New Emp(“John”, 60), New Emp(“Jim”, 

51)); 

Predicate<Emp> agVal = s -> s.getEAge() > 50;//line n1 

li = li.stream().filter(agVal).collect(Collectors.toList()); 

Stream<String> names = li.stream()map.(Emp::getEName);//line n2 

names.forEach(n -> System.out.print(n + “ “)); 

What is the result? 

A. Sam John Jim 

B. John Jim 

C. A compilation error occurs at line n1. 

D. A compilation error occurs at line n2. 

Answer:

Q27. Given the code fragment: 

public class Foo { 

public static void main (String [ ] args) { 

Map<Integer, String> unsortMap = new HashMap< > ( ); 

unsortMap.put (10, “z”); 

unsortMap.put (5, “b”); 

unsortMap.put (1, “d”); 

unsortMap.put (7, “e”); 

unsortMap.put (50, “j”); 

Map<Integer, String> treeMap = new TreeMap <Integer, String> (new 

Comparator<Integer> ( ) { 

@Override public int compare (Integer o1, Integer o2) {return o2.compareTo 

(o1); } } ); 

treeMap.putAll (unsortMap); 

for (Map.Entry<Integer, String> entry : treeMap.entrySet () ) { 

System.out.print (entry.getValue () + “ “); 

What is the result? 

A. A compilation error occurs. 

B. d b e z j 

C. j z e b d 

D. z b d e j 

Answer:

Q28. Given that /green.txt and /colors/yellow.txt are accessible, and the code fragment: 

Path source = Paths.get(“/green.txt); 

Path target = Paths.get(“/colors/yellow.txt); 

Files.move(source, target, StandardCopyOption.ATOMIC_MOVE); 

Files.delete(source); 

Which statement is true? 

A. The green.txt file content is replaced by the yellow.txt file content and the yellow.txt file is deleted. 

B. The yellow.txt file content is replaced by the green.txt file content and an exception is thrown. 

C. The file green.txt is moved to the /colors directory. 

D. A FileAlreadyExistsException is thrown at runtime. 

Answer:

Q29. Given the code fragment: 

List<String> str = Arrays.asList (“my”, “pen”, “is”, “your’, “pen”); Predicate<String> test = s -> { 

int i = 0; 

boolean result = s.contains (“pen”); 

System.out.print(i++) + “:”); 

return result; 

}; 

str.stream() 

.filter(test) 

.findFirst() 

.ifPresent(System.out ::print); 

What is the result? 

A. 0 : 0 : pen 

B. 0 : 1 : pen 

C. 0 : 0 : 0 : 0 : 0 : pen 

D. 0 : 1 : 2 : 3 : 4 : 

E. A compilation error occurs. 

Answer:

Q30. The data.doc, data.txt and data.xml files are accessible and contain text. 

Given the code fragment: 

Stream<Path> paths = Stream.of (Paths. get(“data.doc”), 

Paths. get(“data.txt”), 

Paths. get(“data.xml”)); 

paths.filter(s-> s.toString().endWith(“txt”)).forEach( 

s -> { 

try { 

Files.readAllLines(s) 

.stream() 

.forEach(System.out::println); //line n1 

} catch (IOException e) { 

System.out.println(“Exception”); 

); 

What is the result? 

A. The program prints the content of data.txt file. 

B. The program prints: 

Exception 

<<The content of the data.txt file>> 

Exception 

C. A compilation error occurs at line n1. 

D. The program prints the content of the three files. 

Answer: