Oracle certification · Exam 1z0-809

1z0-809 Mock Exam Page 3

Java SE 8 Programmer II

Free 1z0-809 mock exam questions 21–30, each with the answer and an explanation.

20 questions · 33 minutes · free, no sign-up

Free 1z0-809 questions

21–30 of 38 free
Question 21 Choose 1

Given:


Show answerHide answer

Correct answer: D

Y YY

Question 22 Choose 1

Given the code fragment:
public static void main (String [ ] args) throws IOException {
BufferedReader br = new BufferedReader (new InputStremReader (System.in));
System.out.print (“Enter GDP: “);
//line 1
}
Which code fragment, when inserted at line 1, enables the code to read the GDP from the
user?

Show answerHide answer

Correct answer: C

int GDP = br.nextInt();

Question 23 Choose 1

Given:
class UserException extends Exception { }
class AgeOutOfLimitException extends UserException { }
and the code fragment:
class App {
public void doRegister(String name, int age)
throws UserException, AgeOutOfLimitException {
if (name.length () < 6) {
throw new UserException ();
} else if (age >= 60) {
throw new AgeOutOfLimitException ();
} else {
System.out.println(“User is registered.”);
}
}
public static void main(String[ ] args) throws UserException {
App t = new App ();
t.doRegister(“Mathew”, 60);
}
}
What is the result?

Show answerHide answer

Correct answer: A

User is registered.

Question 24 Choose 1

Which statement is true about java.time.Duration?

Show answerHide answer

Correct answer: C

It defines time-based values.

Explanation

Reference: http://tutorials.jenkov.com/java-date-time/duration.html#accessing-the-time-ofa-
duration

Question 25 Choose 1

Given the code fragment:
public void recDelete (String dirName) throws IOException {
File [ ] listOfFiles = new File (dirName) .listFiles();
if (listOfFiles ! = null && listOfFiles.length >0) {
for (File aFile : listOfFiles) {
if (aFile.isDirectory ()) {
recDelete (aFile.getAbsolutePath ());
} else {
if (aFile.getName ().endsWith (“.class”))
aFile.delete ();
}
}
}
}
Assume that Projects contains subdirectories that contain .class files and is passed as an
argument to the recDelete () method when it is invoked.
What is the result?

Show answerHide answer

Correct answer: B

The method deletes the .class files of the Projects directory only.

Question 26 Choose 1

Given the code fragment:
class CallerThread implements Callable<String> {
String str;
public CallerThread(String s) {this.str=s;}
public String call() throws Exception {
return str.concat(“Call”);
}
}
and
public static void main (String[] args) throws InterruptedException, ExecutionException
{
ExecutorService es = Executors.newFixedThreadPool(4); //line n1
Future f1 = es.submit (newCallerThread(“Call”));
String str = f1.get().toString();
System.out.println(str);
Which statement is true?

Show answerHide answer

Correct answer: B

The program prints Call Call and does not terminate.

Question 27 Choose 2

Given the for loop construct:
for ( expr1 ; expr2 ; expr3 ) {
statement;
}
Which two statements are true?

Show answerHide answer

Correct answer: B, C

The expression expr1 is optional. it initializes the loop and is evaluated once, as the loop
begin.

When expr2 evaluates to false, the loop terminates. It is evaluated only after each
iteration through the loop.

Explanation

The for statement have this forms:
for (init-stmt; condition; next-stmt) {
body
}
There are three clauses in the for statement.
The init-stmt statement is done before the loop is started, usually to initialize an iteration
variable.
The condition expression is tested before each time the loop is done. The loop isn't
executed if the boolean expression is false (the same as the while loop).
The next-stmt statement is done after the body is executed. It typically increments an
iteration variable.

Question 28 Choose 1

Given:

What is the result?

Show answerHide answer

Correct answer: C

Compilation fails due to an error at line n2

Question 29 Choose 1

Given:
class FuelNotAvailException extends Exception { }
class Vehicle {
void ride() throws FuelNotAvailException {//line n1
System.out.println(“Happy Journey!”);
}
}
class SolarVehicle extends Vehicle {
public void ride () throws Exception {//line n2
super ride ();
}
}
and the code fragment:
public static void main (String[] args) throws FuelNotAvailException, Exception {
Vehicle v = new SolarVehicle ();
v.ride();
}
Which modification enables the code fragment to print Happy Journey!?

Show answerHide answer

Correct answer: B

Replace line n1 with protected void ride() throws Exception {

Question 30 Choose 2

Given:
public class ScopeTest {
int j, int k;
public static void main(String[] args) {
ew ScopeTest().doStuff(); }
void doStuff() {
nt x = 5;
oStuff2();
System.out.println("x");
}
void doStuff2() {
nt y = 7;
ystem.out.println("y");
or (int z = 0; z < 5; z++) {
ystem.out.println("z");
ystem.out.println("y");
}
Which two items are fields?

Show answerHide answer

Correct answer: A, B

j

k

Full mock exam

Sit the 1z0-809 exam before exam day

Full-length mocks with the same number of questions and the same time limit as the real 1z0-809 exam. Every attempt draws a new set of questions from the full bank, so you can keep going until you pass comfortably.

Get full 1z0-809 mock exam
  • 65questions per mock
  • 105 mintime limit
  • 128questions in the bank
  • Newmock on every attempt