0% found this document useful (0 votes)
218 views11 pages

Oracle: Question & Answers

The document provides sample questions and answers for the Oracle 1Z0-817 exam for upgrading Java skills. It includes 11 multiple choice questions about Java concepts like streams, exceptions, annotations, control flow, and serialization. The questions test understanding of language features and identifying differences between code snippets.

Uploaded by

Rafael Barros
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
218 views11 pages

Oracle: Question & Answers

The document provides sample questions and answers for the Oracle 1Z0-817 exam for upgrading Java skills. It includes 11 multiple choice questions about Java concepts like streams, exceptions, annotations, control flow, and serialization. The questions test understanding of language features and identifying differences between code snippets.

Uploaded by

Rafael Barros
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Oracle

1Z0-817
Upgrade OCP Java 6 & 7 & 8 to Java SE 11 Developer
QUESTION & ANSWERS

https://www.dumps4less.com/1Z0-817-dumps-pdf.html
QUESTION 1

Which of the following produces different output than the others?

A. They all produce the same output.


B. Stream.of('eeny', 'meeny', 'miny', 'moe') .collect(partitioningBy(x -˃ x.charAt(0) == 'e'))
.get(false) .stream() .collect(groupingBy(String::length)) .get(4)
.forEach(System.out::println);
C. Stream.of('eeny', 'meeny', 'miny', 'moe') .collect(groupingBy(x -˃ x.charAt(0) == 'e'))
.get(false) .stream() .collect(groupingBy(String::length)) .get(4)
.forEach(System.out::println);
D. Stream.of('eeny', 'meeny', 'miny', 'moe') .filter(x -˃ x.charAt(0) != 'e')
.collect(groupingBy(String::length)) .get(4) .forEach(System.out::println);
E. Stream.of('eeny', 'meeny', 'miny', 'moe') .collect(partitioningBy(x -˃ x.charAt(0) == 'e'))
.get(false) .stream() .collect(partitioningBy(x -˃ x.length() == 4)) .get(true)
.forEach(System.out::println);
F. Stream.of('eeny', 'meeny', 'miny', 'moe') .collect(groupingBy(x -˃ x.charAt(0) == 'e'))
.get(false) .stream() .collect(partitioningBy(String::length)) .get(4)
.forEach(System.out::println);

Correct Answer: F

Explanation/Reference:

Four of the five examples print miny. Option C does not compile. The difference is that
partitioningBy() requires a Predicate that returns a boolean. When getting a question like this on the
exam, focus on the differences between the provided options.

QUESTION 2

What is the output of the following application?


package ocean;
abstract interface CanSwim {
public void swim(final int distance);
}
public class Turtle {
final int distance = 2;
public static void main(String[] seaweed) {
final int distance = 3;
CanSwim seaTurtle = {
final int distance = 5;
@Override
public void swim(final int distance) {
System.out.print(distance);
}
};

https://www.dumps4less.com/1Z0-817-dumps-pdf.html
seaTurtle.swim(7);
}
}
A. 5
B. None of the above
C. The code does not compile.
D. 3
E. 7
F. 2

Correct Answer: C

Explanation/Reference:

The main() method attempts to define an anonymous class instance but fails to provide the class or
interface name, or use the new keyword. The right-hand side of the assignment to the seaTurtle
variable should start with new CanSwim(). For this reason,. If the code was corrected with the proper
declaration, then the program would output 7 at runtime.

QUESTION 3

Given the following two classes, each in a different package, which line inserted into the code allows
the second class to compile?
package commerce;
public class Bank {
public void withdrawal(int amountInCents) {}
public void deposit(int amountInCents) {}
}
package employee;
// INSERT CODE HERE
public class Teller {
public void processAccount(int deposit, int withdrawal) {
withdrawal(withdrawal);
deposit(deposit);
}
}
A. static import commerce.Bank;
B. import static commerce.Bank;
C. import static commerce.Bank.*;
D. static import commerce.Bank.*;
E. None of the above

https://www.dumps4less.com/1Z0-817-dumps-pdf.html
Correct Answer: E

Explanation/Reference:

A static import is used to import static members of another class. In this case, the withdrawal() and
deposit() methods in the Bank class are not marked static. They require an instance of Bank to be
used and cannot be imported as static methods. . If the two methods in the Bank class were marked
static, would be the correct answer since wildcards can be used with static imports to import more
than one method

QUESTION 4

What is the output of the Light program?


package physics;
class Wave {
public int size = 7;
}
public class Light extends Wave {
public int size = 5;
public static void main(String... emc2) {
Light v1 = new Light();
var v2 = new Light();
Wave v3 = new Light();
System.out.println(v1.size +","+ v2.size +","+ v3.size);
}
}
A. 5,5,5
B. 5,5,7
C. 5,7,7
D. 7,7,7
E. The code does not compile.
F. None of the above.

Correct Answer: C

Explanation/Reference:

When replacing a variable in a subclass, Java uses the reference type to determine the variable to
use. Option A would be correct if the size variables were treated like method overriding since all of
the objects in the main() method are instances of Light. Instead, the reference type is used. The
variables v1 and v2 are of reference type Light, so 5 is selected. Likewise, the variable v3 is of type
Wave, so 7 is used. The output is 5,5,7, making option B correct.

https://www.dumps4less.com/1Z0-817-dumps-pdf.html
QUESTION 5

Which of these declarations will not compile?


A. double num1, int num2 = 0;
B. int num1, num2;
C. int num1, num2 = 0;
D. int num1 = 0, num2 = 0;
E. All of the above
F. None of the above

Correct Answer: A

Explanation/Reference:

Option A does not compile because Java does not allow declaring different types as part of the same
declaration. The other three options show various legal combinations of combining multiple variables
in the same declarations with optional default values.

QUESTION 6

How many lines of text does the following program print?


package tron;
class DiskPlayer implements AutoCloseable {
public void close() {}
}
public class LightCycle {
public static void main(String... bits) {
try (DiskPlayer john = new DiskPlayer()) {
System.out.println("ping");
john.close();
} finally {
System.out.println("pong");
john.close();
}
System.out.println("return");
}
}

A. One.
B. Two.
C. Three.
D. The code does not compile because of the DiskPlayer class.
E. The code does not compile for a different reason.
F. None of the above.

https://www.dumps4less.com/1Z0-817-dumps-pdf.html
Correct Answer: E

Explanation/Reference:

The code does not compile because john is declared in the try-with-resources statement and not
accessible in the finally block.

QUESTION 7

Fill in the blanks: The ___________________ keyword is used in method declarations, while the
___________________ keyword is used to send an exception to the surrounding process.

A. throwing, catch
B. throws, throw
C. catch, throw
D. throws, catch
E. throw, throws
F. catch, throwing

Correct Answer: B

Explanation/Reference:

The throws keyword is used in method declarations, while the throw keyword is used to send an
exception to the surrounding process, making option B the correct answer. The catch keyword is used
to handle exceptions. There is no throwing keyword in Java.

QUESTION 8

Which of the following can replace the body of the travel() method to produce the same output on any
nonempty input?
public void travel(List˂Integer˃ roads) {
for (int w = 1; w ˂= roads.size(); w++)
System.out.print(roads.get(w-1));
}
A. for (int q = roads.size(); q ˃= 0; q++) System.out.print(roads.get(q));
B. for(var z : roads) System.out.print(z);
C. for (var var : roads) System.out.print(roads);
D. None of the above
E. for (int t = roads.size(); t ˃ 0; t--) System.out.print(roads.get(t));
F. for (int r = 0; r ˂ roads.size(); r += 1) System.out.print(roads.get(0));

https://www.dumps4less.com/1Z0-817-dumps-pdf.html
Correct Answer: B

Explanation/Reference:

e method prints the elements of the list in the order in which they are defined.

QUESTION 9

How many lines of the following declaration contain a compiler error?


1: public @interface Thermometer {
2: int minTemp();
3: Integer maxTemp() default 1;
4: double[] color();
5: final String type;
6: Boolean compact;
7: }
A. Three
B. One
C. Five
D. None
E. Four
F. Two

Correct Answer: A

Explanation/Reference:

Lines 3 and 6 do not compile because wrapper classes are not permitted as annotation element
types. Line 5 does not compile because a constant must be declared with a value. For these reasons,
option D is correct. The rest of the lines compile without issue.

QUESTION 10

Which of these code snippets behaves differently from the others?

A. if (numChipmunks == 1) System.out.println("One chipmunk");if (numChipmunks == 2)


System.out.println("Two chipmunks");if (numChipmunks == 3) System.out.println("Three
chipmunks");
B. switch (numChipmunks) { case 1: System.out.println("One chipmunk"); case 2:
System.out.println("Two chipmunks"); case 3: System.out.println("Three chipmunks");}
C. if (numChipmunks == 1) System.out.println("One chipmunk");else if (numChipmunks == 2)
System.out.println("Two chipmunks");else if (numChipmunks == 3) System.out.println("Three
chipmunks");
D. All three code snippets do the same thing.

https://www.dumps4less.com/1Z0-817-dumps-pdf.html
Correct Answer: B

Explanation/Reference:

Options A and C print one line if numChipmunks is 1, 2, or 3. Option B does not behave the same way
if numChipmunks is 1 or 2. There is no break statement, so the case statements fall through, and
more than one statement will be printed.

QUESTION 11

Which classes are least likely to be marked Serializable. (Choose two.)


A. A class that tracks which users have logged in
B. A class that manages the memory of running processes in an application
C. A class that tracks the amount of candy in a gumball machine
D. A class that stores information about apples in an orchard
E. A class that monitors the state of every thread in the application
F. A class that holds data about the amount of rain that has fallen in a given yea

Correct Answer: B,E

Explanation/Reference:

Generally speaking, classes should be marked with the Serializable interface if they contain data that
we might want to save and retrieve later

QUESTION 12

What is the output of the following application?


package dinosaur;
public class Park {
public final static void main(String... arguments) {
int pterodactyl = 8;
long triceratops = 3;
if(pterodactyl % 3 > 1 + 1)
triceratops++;
triceratops--;
System.out.print(triceratops);
}
}

A. 3
B. 2
C. The code does not compile.
D. The code compiles but throws an exception at runtime.

https://www.dumps4less.com/1Z0-817-dumps-pdf.html
E. 4

Correct Answer: B

Explanation/Reference:

First, determine whether the if statement’s expression is executed. The expression 8 >valuates to 2.
The right-hand side of the expression is evaluated next since + has a higher precedence than ˃. Since
2 ˃ 2 is false, the expression triceratops++ is not called. Notice there are no braces, {}, in the if
statement. Despite the triceratops–– line being indented, it is not part of the if statement. Therefore,
triceratops–– is always executed, resulting in a value of 2 for triceratops, and making option A the
correct answer.

QUESTION 13

What is the result of executing the following program?


public class Canine {
public String woof(int bark) {
return "1"+bark.toString();
}
public String woof(Integer bark) {
return "2"+bark.toString();
}
public String woof(Object bark) {
return "3"+bark.toString();
}
public static void main(String[] a) {
System.out.println(woof((short)5));
}
}

A. 15
B. 25
C. 35
D. One line does not compile.
E. Two lines do not compile.
F. The program compiles but throws an exception at runtime.

Correct Answer: E

Explanation/Reference:

The first woof() method does not compile because bark is a primitive, not an object, and does not

https://www.dumps4less.com/1Z0-817-dumps-pdf.html
have a toString() method. The main() method also does not compile because it is static and all of the
woof() methods require an instance of Canine. Since these two lines do not compile, option E is the
correct answer. If the toString() was removed from the first method and all of the methods were
marked static, then the program would print 15 at runtime.

QUESTION 14

Which statements about the following class are correct? (Choose three.)
import java.security.*;
import java.util.*;

public class UserProfile {


private static class UserEntry {
private final UserProfile value;
private final Permission permission;
// Constructors/Getters Omitted
}

public static Permission getPermission(String check) {


// Implementation Omitted
}

private static Map˂String,UserEntry˃ data = new HashMap˂˃();


public static UserProfile getProfile(String check) {
var securityRecord = data.get(check);
if (securityRecord != null)
return securityRecord.getValue(); // h1

var permission = getPermission(check);


var permCol = permission.newPermissionCollection();
permCol.add(permission);
var prof = AccessController.doPrivileged( // h2
new PrivilegedAction˂UserProfile˃() {
public UserProfile run() {
return new UserProfile();
}},
new AccessControlContext(
new ProtectionDomain[] {
new ProtectionDomain(null, permCol)
}));
data.put(check, new UserEntry(prof, permission)); // h3
return prof;
}}
A. Line h3 violates security guidelines by allowing security information to be cached.
B. Line h2 does not elevate security privileges.
C. Line h3 does not violate security guidelines.
D. Line h2 elevates security privileges.
E. Line h1 properly validates security.
F. Line h1 presents an unacceptable security risk.

https://www.dumps4less.com/1Z0-817-dumps-pdf.html
Correct Answer: C,D,F

Explanation/Reference:

Caching permissions for a user is allowed, so option F is correct. That said, the security on using the
cached data must be checked. The class is missing calls to AccessController.checkPermission() before
lines h1 and h2. On line h1, this can result in a user reading a cached permission they do not have
access to, making option B correct. On line h2, security permissions could be elevated since access is
not checked,

QUESTION 15

Fill in the blanks: The name of the abstract method in the Function interface is ______________, while
the name of the abstract method in the Consumer interface is ______________

A. apply(), apply()
B. apply(), accept()
C. accept(), apply()
D. accept(), get()
E. apply(), test()

Correct Answer: B

Explanation/Reference:

The Function interface uses apply(), while the Consumer interface uses accept(), making . For
reference, get() is the name of the method used by Supplier, while test() is the name of the method
used by Predicate.

https://www.dumps4less.com/1Z0-817-dumps-pdf.html

You might also like