oracle 1z0-809 practice test

Java SE 8 Programmer II Exam

Last exam update: Jul 16 ,2024
Page 1 out of 11. Viewing questions 1-15 out of 164

Question 1

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;
}
public String getCourse() {return course;}
public String getName() {return name;}
public String getCity() {return city;}
and the code fragment:
List<Student> stds = Arrays.asList(
new Student (Jessy, Java ME, Chicago),
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));
What is the result?

  • A. A compilation error occurs.
  • B. Java EEJava ME
  • C. [Java EE: Helen:Houston][Java ME: Jessy:Chicago, Java ME: Mark:Chicago]
  • D. [Java ME: Jessy:Chicago, Java ME: Mark:Chicago][Java EE: Helen:Houston]
Mark Question:
Answer:

B

User Votes:
A
50%
B 1 votes
50%
C
50%
D
50%
Discussions
vote your answer:
A
B
C
D
0 / 1000

Question 2

Given:
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;)
}
and the code fragment:
List<Product> products = new ArrayList <> (Arrays.asList(new Product(1, 10),
new Product (2, 30),
new Product (3, 20));
Product p = products.stream().reduce(new Product (4, 0), (p1, p2) -> {
p1.price+=p2.price;
return new Product (p1.id, p1.price);});
products.add(p);
products.stream().parallel()
.reduce((p1, p2) - > p1.price > p2.price ? p1 : p2)
.ifPresent(System.out: :println);
What is the result?

  • A. 4:60
  • B. 2:30
  • C. 4:602:303:201:10
  • D. 4:0
  • E. The program prints nothing
Mark Question:
Answer:

C

User Votes:
A 1 votes
50%
B
50%
C
50%
D
50%
E
50%
Discussions
vote your answer:
A
B
C
D
E
0 / 1000

Question 3

Given the code fragment:
List<Double> doubles = Arrays.asList (100.12, 200.32);
DoubleFunction funD = d > d + 100.0;
doubles.stream (). forEach (funD); // line n1
doubles.stream(). forEach(e > System.out.println(e)); // line n2
What is the result?

  • A. A compilation error occurs at line n2.
  • B. 200.12300.32
  • C. 100.12200.32
  • D. A compilation error occurs at line n1.
Mark Question:
Answer:

A

User Votes:
A
50%
B
50%
C
50%
D 1 votes
50%

Explanation:

Discussions
vote your answer:
A
B
C
D
0 / 1000

Question 4

Given the code fragments:
class ThreadRunner implements Runnable {
public void run () { System.out.print (Runnable) ; }
}
class ThreadCaller implements Callable {
Public String call () throws Exception {return Callable; )
}
and
ExecutorService es = Executors.newCachedThreadPool ();
Runnable r1 = new ThreadRunner ();
Callable c1 = new ThreadCaller ();
// line n1
es.shutdown();
Which code fragment can be inserted at line n1 to start r1 and c1 threads?

  • A. Future<String> f1 = (Future<String>) es.submit (r1);es.execute (c1);
  • B. es.execute (r1);Future<String> f1 = es.execute (c1) ;
  • C. Future<String> f1 = (Future<String>) es.execute(r1);Future<String> f2 = (Future<String>) es.execute(c1);
  • D. es.submit(r1);Future<String> f1 = es.submit (c1);
Mark Question:
Answer:

D

User Votes:
A
50%
B
50%
C
50%
D 1 votes
50%
Discussions
vote your answer:
A
B
C
D
0 / 1000

Question 5

Given the definition of the Employee class:

and this code fragment:

What is the result?

  • A. [sales:Ada, hr:Bob, sales:Bob, hr:Eva]
  • B. [Ada:sales, Bob:sales, Bob:hr, Eva:hr]
  • C. [hr:Eva, hr:Bob, sales:Bob, sales:Ada]
  • D. [hr:Bob, hr:Eva, sales:Ada, sales:Bob]
Mark Question:
Answer:

A

User Votes:
A
50%
B
50%
C
50%
D 1 votes
50%
Discussions
vote your answer:
A
B
C
D
0 / 1000

Question 6

Given:

From what threading problem does the program suffer?

  • A. race condition
  • B. deadlock
  • C. starvation
  • D. livelock
Mark Question:
Answer:

B

User Votes:
A
50%
B 1 votes
50%
C
50%
D
50%
Discussions
vote your answer:
A
B
C
D
0 / 1000

Question 7

Given:

and the code fragment:

What is the result?

  • A. [Java EE: Helen:Houston][Java ME: Jessy:Chicago, Java ME: Mark:Chicago]
  • B. Java EEJava ME
  • C. [Java ME: Jessy:Chicago, Java ME: Mark:Chicago][Java EE: Helen:Houston]
  • D. A compilation error occurs.
Mark Question:
Answer:

D

User Votes:
A
50%
B 2 votes
50%
C
50%
D 1 votes
50%

Explanation:

Discussions
vote your answer:
A
B
C
D
0 / 1000

Question 8

Given that data.txt and alldata.txt are accessible, and the code fragment:

What is required at line n1 to enable the code to overwrite alldata.txt with data.txt?

  • A. br.close();
  • B. bw.writeln();
  • C. br.flush();
  • D. bw.flush();
Mark Question:
Answer:

D

User Votes:
A
50%
B
50%
C
50%
D 1 votes
50%
Discussions
vote your answer:
A
B
C
D
0 / 1000

Question 9

What is true about the java.sql.Statement interface?

  • A. It provides a session with the database.
  • B. It is used to get an instance of a Connection object by using JDBC drivers.
  • C. It provides a cursor to fetch the resulting data.
  • D. It provides a class for executing SQL statements and returning the results.
Mark Question:
Answer:

D

User Votes:
A
50%
B
50%
C
50%
D 2 votes
50%
Discussions
vote your answer:
A
B
C
D
0 / 1000

Question 10

Given the code fragments:

and

What is the result?

  • A. Video played.Game played.
  • B. A compilation error occurs.
  • C. class java.lang.Exception
  • D. class java.io.IOException
Mark Question:
Answer:

C

User Votes:
A
50%
B 2 votes
50%
C
50%
D
50%
Discussions
vote your answer:
A
B
C
D
0 / 1000

Question 11

Given the structure of the Student table:
Student (id INTEGER, name VARCHAR)
Given the records from the STUDENT table:

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.
What is the result?

  • A. The program prints Status: true and two records are deleted from the Student table.
  • B. The program prints Status: false and two records are deleted from the Student table.
  • C. A SQLException is thrown at runtime.
  • D. The program prints Status: false but the records from the Student table are not deleted.
Mark Question:
Answer:

B

User Votes:
A
50%
B 2 votes
50%
C
50%
D
50%
Discussions
vote your answer:
A
B
C
D
0 / 1000

Question 12

Given the code fragment:

Which should be inserted into line n1 to print Average = 2.5?

  • A. IntStream str = Stream.of (1, 2, 3, 4);
  • B. IntStream str = IntStream.of (1, 2, 3, 4);
  • C. DoubleStream str = Stream.of (1.0, 2.0, 3.0, 4.0);
  • D. Stream str = Stream.of (1, 2, 3, 4);
Mark Question:
Answer:

C

User Votes:
A
50%
B 1 votes
50%
C 1 votes
50%
D
50%
Discussions
vote your answer:
A
B
C
D
0 / 1000

Question 13

Which two statements are true about synchronization and locks? (Choose two.)

  • A. A thread automatically acquires the intrinsic lock on a synchronized statement when executed.
  • B. The intrinsic lock will be retained by a thread if return from a synchronized method is caused by an uncaught exception.
  • C. A thread exclusively owns the intrinsic lock of an object between the time it acquires the lock and the time it releases it.
  • D. A thread automatically acquires the intrinsic lock on a synchronized methods object when entering that method.
  • E. Threads cannot acquire intrinsic locks on classes.
Mark Question:
Answer:

A,B

User Votes:
A 2 votes
50%
B 1 votes
50%
C 1 votes
50%
D 2 votes
50%
E
50%
Discussions
vote your answer:
A
B
C
D
E
0 / 1000

Question 14

Which two statements are true about the Fork/Join Framework? (Choose two.)

  • A. The RecursiveTask subclass is used when a task does not need to return a result.
  • B. The Fork/Join framework can help you take advantage of multicore hardware.
  • C. The Fork/Join framework implements a work-stealing algorithm.
  • D. The Fork/Join solution when run on multicore hardware always performs faster than standard sequential solution.
Mark Question:
Answer:

A,C

User Votes:
A
50%
B 2 votes
50%
C 2 votes
50%
D
50%
Discussions
vote your answer:
A
B
C
D
0 / 1000

Question 15

Given the code fragment:

Which code fragment, when inserted at line 7, enables printing 100?

  • A. Function<Integer> funRef = e –> e + 10;Integer result = funRef.apply(value);
  • B. IntFunction funRef = e –> e + 10;Integer result = funRef.apply (10);
  • C. ToIntFunction<Integer> funRef = e –> e + 10;int result = funRef.applyAsInt (value);
  • D. ToIntFunction funRef = e –> e + 10;int result = funRef.apply (value);
Mark Question:
Answer:

A

User Votes:
A 1 votes
50%
B
50%
C 2 votes
50%
D
50%
Discussions
vote your answer:
A
B
C
D
0 / 1000
To page 2