1z0-809.exam.53q: Number: 1z0-809 Passing Score: 800 Time Limit: 120 Min
1z0-809.exam.53q: Number: 1z0-809 Passing Score: 800 Time Limit: 120 Min
53q
Number: 1z0-809
Passing Score: 800
Time Limit: 120 min
https://www.gratisexam.com/
1z0-809
Java SE 8 Programmer II
https://www.gratisexam.com/
Exam A
QUESTION 1
Given:
What is the result of running the code with the –ea option?
A. -10
B. 0
C. An AssertionError is thrown.
D. A compilation error occurs.
Correct Answer: C
Section: (none)
Explanation
Explanation/Reference:
QUESTION 2
Given:
class Bird {
public void fly () { System.out.print(“Can fly”); }
}
class Penguin extends Bird {
public void fly () { System.out.print(“Cannot fly”); }
}
class Birdie {
https://www.gratisexam.com/
public static void main (String [ ] args) {
fly( ( ) -> new Bird ( ));
fly (Penguin : : new);
}
/* line n1 */
}
Which code fragment, when inserted at line n1, enables the Birdie class to compile?
https://www.gratisexam.com/
Correct Answer: C
Section: (none)
Explanation
Explanation/Reference:
QUESTION 3
Given:
https://www.gratisexam.com/
4. }
5.
6. class Square extends Shape {
7. int side;
8. Square int side {
9. /* insert code here */
10. this.side = side;
11. }
12. public void area ( ) { System.out.println (“Square”); }
13. }
14. class Rectangle extends Square {
15. int len, br;
16. Rectangle (int x, int y) {
17. /* insert code here */
18. len = x, br = y;
19. }
20. void area ( ) { System.out.println (“Rectangle”); }
21. }
Correct Answer: DF
Section: (none)
Explanation
Explanation/Reference:
QUESTION 4
Given:
https://www.gratisexam.com/
int [ ] data;
public Sum (int [ ]data, int start, int end) {
this.data = data;
this stIndex = start;
this. lstIndex = end;
}
protected void compute ( ) {
int sum = 0;
if (lstIndex – stIndex <= THRESHOLD_SIZE) {
for (int i = stIndex; i < lstIndex; i++) {
sum += data [i];
}
System.out.println(sum);
} else {
new Sum (data, stIndex + THRESHOLD_SIZE, lstIndex).fork( );
new Sum (data, stIndex,
Math.min (lstIndex, stIndex + THRESHOLD_SIZE)
).compute ();
}
}
}
Correct Answer: A
Section: (none)
Explanation
Explanation/Reference:
https://www.gratisexam.com/
QUESTION 5
Given:
public static <T> Foo<T, T> twice (T value) (return new Foo<T, T> (value, value); )
Correct Answer: C
Section: (none)
Explanation
Explanation/Reference:
QUESTION 6
Given the code fragment:
https://www.gratisexam.com/
A. 1John2null
B. 12
C. A NullPointerException is thrown at run time.
D. A compilation error occurs.
Correct Answer: D
Section: (none)
Explanation
Explanation/Reference:
QUESTION 7
Given the code fragments:
and
24. try {
25. doStuff ( ):
26. } catch (ArithmeticException | NumberFormatException | Exception e) {
27. System.out.println (e.getMessage()); }
28. catch (Exception e) {
29. System.out.println (e.getMessage()); }
30. }
Correct Answer: C
https://www.gratisexam.com/
Section: (none)
Explanation
Explanation/Reference:
QUESTION 8
Given the definition of the Country class:
Correct Answer: B
Section: (none)
Explanation
Explanation/Reference:
https://www.gratisexam.com/
QUESTION 9
Given the code fragment:
Correct Answer: B
Section: (none)
Explanation
Explanation/Reference:
Reference: TreeMap inherits SortedMap and automatically sorts the element's key
QUESTION 10
Given:
class Book {
int id;
String name;
public Book (int id, String name) {
this.id = id;
this.name = name;
}
public boolean equals (Object obj) { //line n1
boolean output = false;
Book b = (Book) obj;
if (this.name.equals(b name))}
output = true;
}
return output;
https://www.gratisexam.com/
}
}
https://www.gratisexam.com/
Correct Answer: A
Section: (none)
Explanation
Explanation/Reference:
QUESTION 11
Given the content of /resourses/Message.properties:
welcome1=”Good day!”
https://www.gratisexam.com/
FileInputStream fis = new FileInputStream (“/resources/Message.properties”);
prop.load(fis);
System.out.println(prop.getProperty(“welcome1”));
System.out.println(prop.getProperty(“welcome2”, “Test”));//line n1
System.out.println(prop.getProperty(“welcome3”));
A. Good day!
Test
followed by an Exception stack trace
B. Good day!
followed by an Exception stack trace
C. Good day!
Test
null
D. A compilation error occurs at line n1.
Correct Answer: C
Section: (none)
Explanation
Explanation/Reference:
QUESTION 12
Which action can be used to load a database driver by using JDBC3.0?
A. Add the driver class to the META-INF/services folder of the JAR file.
B. Include the JDBC driver class in a jdbc.properties file.
C. Use the java.lang.Class.forName method to load the driver class.
D. Use the DriverManager.getDriver method to load the driver class.
Correct Answer: C
Section: (none)
Explanation
Explanation/Reference:
https://www.gratisexam.com/
QUESTION 13
Given the code fragment:
Path p1 = Paths.get(“/Pics/MyPic.jpeg”);
System.out.println (p1.getNameCount() +
“:” + p1.getName(1) +
“:” + p1.getFileName());
Correct Answer: B
Section: (none)
Explanation
Explanation/Reference:
QUESTION 14
Given the code fragments:
and
https://www.gratisexam.com/
ta[x].start();
}
Correct Answer: A
Section: (none)
Explanation
Explanation/Reference:
QUESTION 15
Given the code fragment:
Which code fragment, when inserted at line 1, enables the code to read the GDP from the user?
Correct Answer: A
Section: (none)
Explanation
Explanation/Reference:
https://www.gratisexam.com/
QUESTION 16
Given the code fragment:
A. A file with the name log.txt is created in the /data directory and the content of the /data/december/log.txt file is copied to it.
B. The program executes successfully and does NOT change the file system.
C. A FileNotFoundException is thrown at run time.
D. A FileAlreadyExistsException is thrown at run time.
Correct Answer: D
Section: (none)
Explanation
Explanation/Reference:
QUESTION 17
Given:
class Student {
String course, name, city;
public Student (String name, String course, String city) {
this.course = course; this.name = name; this.city = city;
}
public String toString() {
return course + “:” + name + “:” + city;
}
https://www.gratisexam.com/
new Student (“Helen”, “Java EE”, “Houston”),
new Student (“Mark”, “Java ME”, “Chicago”));
stds.stream()
.collect(Collectors.groupingBy(Student::getCourse))
.forEach(src, res) -> System.out.println(scr));
Correct Answer: B
Section: (none)
Explanation
Explanation/Reference:
QUESTION 18
Given:
https://www.gratisexam.com/
and this code fragment:
Correct Answer: A
Section: (none)
Explanation
Explanation/Reference:
QUESTION 19
Given the structure of the STUDENT table:
Given:
https://www.gratisexam.com/
st.executeUpdate(“INSERT INTO student VALUES (102, ‘Kelvin’)”);
}
}
Assume that:
The required database driver is configured in the classpath.
The appropriate database is accessible with the URL, userName, and passWord exists.
The SQL query is valid.
A. The program executes successfully and the STUDENT table is updated with one record.
B. The program executes successfully and the STUDENT table is NOT updated with any record.
C. A SQLException is thrown as runtime.
D. A NullPointerException is thrown as runtime.
Correct Answer: C
Section: (none)
Explanation
Explanation/Reference:
QUESTION 20
Given the code fragments:
class Employee {
Optional<Address> address;
Employee (Optional<Address> address) {
this.address = address;
}
public Optional<Address> getAddress() { return address; }
}
class Address {
String city = “New York”;
public String getCity { return city: }
public String toString() {
return city;
}
}
https://www.gratisexam.com/
and
A. New York
B. City Not available
C. null
D. A NoSuchElementException is thrown at run time.
Correct Answer: B
Section: (none)
Explanation
Explanation/Reference:
QUESTION 21
Given the code fragment:
});
https://www.gratisexam.com/
https://www.gratisexam.com/
A. All files and directories under the home directory are listed along with their attributes.
B. A compilation error occurs at line n1.
C. The files in the home directory are listed along with their attributes.
D. A compilation error occurs at line n2.
Correct Answer: A
Section: (none)
Explanation
Explanation/Reference:
QUESTION 22
Given:
class Vehicle {
int vno;
String name;
https://www.gratisexam.com/
What is the result?
A. 10123 Ford
10124 BMW
B. 10124 BMW
10123 Ford
C. A compilation error occurs.
D. A ClassCastException is thrown at run time.
Correct Answer: D
Section: (none)
Explanation
Explanation/Reference:
QUESTION 23
Given that course.txt is accessible and contains:
Course : : Java
https://www.gratisexam.com/
A. ur :: va
B. ueJa
C. The program prints nothing.
D. A compilation error occurs at line n1.
Correct Answer: B
Section: (none)
Explanation
Explanation/Reference:
QUESTION 24
Given:
A. Java 100
B. java.lang.string@<hashcode>java.lang.Integer@<hashcode>
C. A compilation error occurs. To rectify it, replace line n1 with:
Test<Integer> type1 = new Test<>();
D. A compilation error occurs. To rectify it, replace line n2 with:
type1.set (Integer(100));
https://www.gratisexam.com/
Correct Answer: A
Section: (none)
Explanation
Explanation/Reference:
QUESTION 25
Given the definition of the Vehicle class:
class Vehicle {
String name;
void setName (String name) {
this.name = name;
}
String getName() {
return name;
}
}
Correct Answer: D
Section: (none)
Explanation
Explanation/Reference:
QUESTION 26
Given:
https://www.gratisexam.com/
public class product {
int id; int price;
public Product (int id, int price) {
this.id = id;
this.price = price;
}
public String toString() { return id + “:” + price; }
}
A. 2 : 30
B. 4 : 0
C. 4 : 60
D. 4 : 60
2 : 30
3 : 20
1 : 10
E. The program prints nothing.
Correct Answer: C
Section: (none)
Explanation
Explanation/Reference:
QUESTION 27
Given the code fragments:
https://www.gratisexam.com/
public class Book implements Comparator<Book> {
String name;
double price;
public Book () {}
public Book(String name, double price) {
this.name = name;
this.price = price;
}
public int compare(Book b1, Book b2) {
return b1.name.compareTo(b2.name);
}
public String toString() {
return name + “:” + price;
}
}
and
List<Book>books = Arrays.asList (new Book (“Beginning with Java”, 2), new book (“A
Guide to Java Tour”, 3));
Collections.sort(books, new Book());
System.out.print(books);
Correct Answer: A
Section: (none)
Explanation
Explanation/Reference:
QUESTION 28
Given the code fragment:
https://www.gratisexam.com/
System.out.println (
// line n1
);
Which code fragment, when inserted at line n1, enables the code to print the count of string elements whose length is greater than three?
Correct Answer: A
Section: (none)
Explanation
Explanation/Reference:
QUESTION 29
Given the code fragments:
and
https://www.gratisexam.com/
What is the result?
Correct Answer: A
Section: (none)
Explanation
Explanation/Reference:
QUESTION 30
Given:
https://www.gratisexam.com/
A. Board does not compile.
B. Paper does not compile.
C. Frame does not compile.
D. Drawable does not compile.
E. All classes compile successfully.
Correct Answer: E
Section: (none)
Explanation
Explanation/Reference:
QUESTION 31
Given the code fragment:
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.
Correct Answer: A
Section: (none)
Explanation
https://www.gratisexam.com/
Explanation/Reference:
QUESTION 32
Given the code fragment:
A. 100, Robin, HR
101, Peter, HR
B. A compilation error occurs at line n1.
C. 100, Robin, HR
101, Peter, HR
200, Mary, AdminServices
D. 100, Robin, HR
200, Mary, AdminServices
101, Peter, HR
Correct Answer: A
Section: (none)
Explanation
Explanation/Reference:
QUESTION 33
Given:
class Car {
private String name;
public Car (String name) {
this.name = name;
https://www.gratisexam.com/
}
}
Correct Answer: C
Section: (none)
Explanation
Explanation/Reference:
QUESTION 34
Which statement is true about the single abstract method of the java.util.function.Function interface?
Correct Answer: D
Section: (none)
Explanation
Explanation/Reference:
QUESTION 35
Given:
https://www.gratisexam.com/
System.out.print(“Open”);
}
}
public class Test {
public static void main (String [] args) throws Exception {
try (Folder f = new Folder()) {
f.open();
}
}
}
Correct Answer: AE
Section: (none)
Explanation
Explanation/Reference:
QUESTION 36
You want to create a singleton class by using the Singleton design pattern.
Which two statements enforce the singleton nature of the design?
https://www.gratisexam.com/
C. Override equals() and hashCode() methods of the java.lang.Object class.
D. Use a static reference to point to the single instance.
E. Implement the Serializable interface.
Correct Answer: BD
Section: (none)
Explanation
Explanation/Reference:
QUESTION 37
Given the code fragment:
Assume that:
The required database driver is configured in the classpath.
The appropriate database is accessible with the dbURL, userName, and passWord exists.
The Employee and Customer tables are available and each table has id column with a few records and the SQL queries are valid.
What is the result of compiling and executing this code fragment?
https://www.gratisexam.com/
https://www.gratisexam.com/
C. The program prints Error.
D. compilation fails on line 13.
Correct Answer: C
Section: (none)
Explanation
Explanation/Reference:
QUESTION 38
Given:
A. 0
B. 2
C. 3
D. 4
https://www.gratisexam.com/
E. 5
Correct Answer: D
Section: (none)
Explanation
Explanation/Reference:
QUESTION 39
Given:
Item table
• ID, INTEGER: PK
• DESCRIP, VARCHAR(100)
• PRICE, REAL
• QUANTITY< INTEGER
9. try {
10. Connection conn = DriveManager.getConnection(dbURL, username, password);
11. String query = “Select * FROM Item WHERE ID = 110”;
12. Statement stmt = conn.createStatement();
13. ResultSet rs = stmt.executeQuery(query);
14. while(rs.next()) {
15. System.out.println(“ID: “ + rs.getInt(“Id”));
16. System.out.println(“Description: “ + rs.getString(“Descrip”));
17. System.out.println(“Price: “ + rs.getDouble(“Price”));
18. System.out.println(Quantity: “ + rs.getInt(“Quantity”));
19. }
20. } catch (SQLException se) {
21. System.out.println(“Error”);
22. }
Assume that:
The required database driver is configured in the classpath.
The appropriate database is accessible with the dbURL, userName, and passWord exists.
The SQL query is valid.
https://www.gratisexam.com/
A. An exception is thrown at runtime.
B. Compilation fails.
C. The code prints Error.
D. The code prints information about Item 110.
Correct Answer: D
Section: (none)
Explanation
Explanation/Reference:
QUESTION 40
Given:
You have been asked to ensure that the run methods of both the Worker and Master classes are executed.
Which modification meets the requirement?
https://www.gratisexam.com/
A. At line n2, insert CyclicBarrier cb = new CyclicBarrier(2, master);
B. Replace line n1 with class Master extends Thread {
C. At line n2, insert CyclicBarrier cb = new CyclicBarrier(1, master);
D. At line n2, insert CyclicBarrier cb = new CyclicBarrier(master);
Correct Answer: C
Section: (none)
Explanation
Explanation/Reference:
QUESTION 41
Given the code fragment:
A. 0
B. 1
C. A compilation error occurs at line n1.
D. A compilation error occurs at line n2.
Correct Answer: A
Section: (none)
Explanation
Explanation/Reference:
QUESTION 42
Given the code fragment:
https://www.gratisexam.com/
.map(funVal)
.peek(System.out::print);
Correct Answer: C
Section: (none)
Explanation
Explanation/Reference:
QUESTION 43
Given:
https://www.gratisexam.com/
Correct Answer: A
Section: (none)
Explanation
Explanation/Reference:
QUESTION 44
Given the code fragment:
A. 2016-02-14
B. A DateTimeException is thrown.
C. 2016-02-29
D. A compilation error occurs at line n1.
Correct Answer: A
Section: (none)
Explanation
Explanation/Reference:
QUESTION 45
Given the code fragment:
A. 20
B. 20.5
https://www.gratisexam.com/
C. A compilation error occurs at line n1.
D. A compilation error occurs at line n2.
Correct Answer: C
Section: (none)
Explanation
Explanation/Reference:
QUESTION 46
Given the code fragment:
A. 4000.0
B. 4000
C. A compilation error occurs at line n1.
D. A compilation error occurs at line n2.
Correct Answer: D
Section: (none)
Explanation
Explanation/Reference:
QUESTION 47
You have been asked to create a ResourceBundle which uses a properties file to localize an application.
Which code example specifies valid keys of menu1 and menu2 with values of File Menu and View Menu?
https://www.gratisexam.com/
B. <key>menu1</key><value>File Menu</value>
<key>menu2</key><value>View Menu</value>
C. menu1, File Menu, menu2, View Menu Menu
D. menu1 = File Menu
menu2 = View Menu
Correct Answer: D
Section: (none)
Explanation
Explanation/Reference:
QUESTION 48
Given the records from the Employee table:
try {
Connection conn = DriverManager.getConnection (URL, userName, passWord);
Statement st = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_UPDATABLE);
st.execute(“SELECT*FROM Employee”);
ResultSet rs = st.getResultSet();
while (rs.next()) {
if (rs.getInt(1) ==112) {
rs.updateString(2, “Jack”);
}
}
rs.absolute(2);
System.out.println(rs.getInt(1) + “ “ + rs.getString(2));
} catch (SQLException ex) {
System.out.println(“Exception is raised”);
}
Assume that:
https://www.gratisexam.com/
The required database driver is configured in the classpath.
The appropriate database accessible with the URL, userName, and passWord exists.
What is the result?
Correct Answer: A
Section: (none)
Explanation
Explanation/Reference:
QUESTION 49
Given the code fragment:
and
https://www.gratisexam.com/
}
Correct Answer: B
Section: (none)
Explanation
Explanation/Reference:
QUESTION 50
Given the code fragment:
https://www.gratisexam.com/
C. The program prints files names sequentially.
D. A compilation error occurs at line n1.
Correct Answer: B
Section: (none)
Explanation
Explanation/Reference:
QUESTION 51
Given the code fragments:
class TechName {
String techName;
TechName (String techName) {
this.techName=techName;
}
}
and
A. stre.forEach(System.out::print);
B. stre.map(a-> a.techName).forEach(System.out::print);
C. stre.map(a-> a).forEachOrdered(System.out::print);
D. stre.forEachOrdered(System.out::print);
Correct Answer: B
Section: (none)
Explanation
https://www.gratisexam.com/
Explanation/Reference:
QUESTION 52
Given that /green.txt and /colors/yellow.txt are accessible, and the code fragment:
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.
Correct Answer: D
Section: (none)
Explanation
Explanation/Reference:
https://www.gratisexam.com/
QUESTION 53
Given:
interface Doable {
public void doSomething (String s);
}
https://www.gratisexam.com/
public void doSomethingElse(String s) { }
}
B. public abstract class Work implements Doable {
public abstract void doSomething(String s) { }
public void doYourThing(Boolean b) { }
}
C. public class Job implements Doable {
public void doSomething(Integer i) { }
}
D. public class Action implements Doable {
public void doSomething(Integer i) { }
public String doThis(Integer j) { }
}
E. public class Do implements Doable {
public void doSomething(Integer i) { }
public void doSomething(String s) { }
public void doThat (String s) { }
}
Correct Answer: AE
Section: (none)
Explanation
Explanation/Reference:
https://www.gratisexam.com/