OCJP Practice Papers - Lambda Built-In Functional Interfaces
OCJP Practice Papers Using Loop Constructs include following topics
- Create and use a generic class
- Create and use ArrayList, TreeSet, TreeMap, and ArrayDeque objects
- Use java.util.Comparator and java.lang.Comparable interfaces
- Collections Streams and Filters
- Iterate using forEach methods of Streams and List
- Describe Stream interface and Stream pipeline
- Filter a collection by using lambda expressions
- Use method references with Streams
See the complete syllabus for OCJP here
1. Fill in the blanks: The______ functional interface does not take any inputs,while the____ functional interface does not return any data.
A. IntConsumer, LongSupplier
B. IntSupplier, Function
C. Supplier, DoubleConsumer
D. UnaryOperator, Consumer
2. Which functional interface takes a long value as an input argument and has anaccept() method?
A. LongConsumer
B. LongFunction
C. LongPredicate
D. LongSupplier
3. What is the output of the following application?
A. Saved
B. Too far
C. The code does not compile because of line y1.
D. The code does not compile because of line y2.
4. Which of the following statements about DoubleSupplier and SupplierDouble is nottrue?
A. Both are functional interfaces.
B. Lambdas for both can return a double value.
C. Lambdas for both cannot return a null value.
D. One supports a generic type, the other does not.
5. Which functional interface, when filled into the blank, allows the class to compile?
A. BiConsumerInteger,Double
B. BiFunctionInteger,Double,Double
C. BiFunctionInteger,Integer,Double
D. FunctionInteger,Double
6. Assuming the proper generic types are used, which lambda expression cannot beassigned to a ToDoubleBiFunction functional interface reference?
A. (Integer a, Double b) - {int c; return b;}
B. (h,i) - (long)h
C. (String u, Object v) - u.length()+v.length()
D. (x,y) - {int z=2; return y/z;}
7. Which of the following is not a functional interface in the java.util.functionpackage?
A. BiPredicate
B. DoubleUnaryOperator
C. ObjectDoubleConsumer
D. ToLongFunction
8. What is the output of the following application?
A. 51
B. The code does not compile because of lambda expression.
C. The code does not compile for a different reason.
D. The code compiles but prints an exception at runtime.
9. Which functional interface returns a primitive value?
A. BiPredicate
B. CharSupplier
C. LongFunction
D. UnaryOperator
10. Which functional interface, when entered into the blank below, allows the class tocompile?
A. Consumer
B. DoubleConsumer
C. SupplierDouble
D. None of the above
11. Which of the following three functional interfaces is not equivalent to the other two?
A. BiFunctionDouble,Double,Double
B. BinaryOperatorDouble
C. DoubleFunctionDouble
D. None of the above. All three are equivalent.
12. Which lambda expression can be passed to the magic() method?
A. magic((a) - a)
B. magic((b,w) - (long)w.intValue())
C. magic((c,m) - {long c=4; return c+m;})
D. magic((Integer d, Integer r) - (Long)r+d)
13. What is the output of the following program?
A. Program started!
B. The code does not compile because of line d1 only.
C. The code does not compile because of line d2 only.
D. The code does not compile because of both lines d1 and d2.
14. Which statement about all UnaryOperator functional interfaces (generic and primitive)is correct?
A. The input type must be compatible with the return type.
B. Some of them take multiple arguments.
C. They each take a generic argument.
D. They each return a primitive value.
15. Starting with DoubleConsumer and going downward, fill in the missing values for thetable.
Functional Interface # Parameters
DoubleConsumer
IntFunction
LongSupplier
ObjDoubleConsumer
A. 0, 1, 1, 1
B. 0, 2, 1, 2
C. 1, 1, 0, 2
D. 1, 1, 0, 1
16. Starting with DoubleConsumer and going downward, fill in the values for the table. Forthe choices below, assume R is a generic type.
Functional Interface Return Type
DoubleConsumer
IntFunction
LongSupplier
ObjDoubleConsumer
A. double, R, long, R
B. R, int, long, R
C. void, int, R, void
D. void, R, long, void
17. Fill in the blanks: In the Collection interface, the method removeIf() takesa____________ , while the method forEach() takes a____________ .
A. Function, Function
B. Predicate, Consumer
C. Predicate, Function
D. Predicate, UnaryOperator
18. What is the output of the following application?
A. XXXXX
B. The code does not compile because of the lambda expression.
C. The code does not compile for a different reason.
D. The code compiles but produces an infinite loop at runtime.
19. Which functional interface has a get() method?
A. Consumer
B. Function
C. Supplier
D. UnaryOperator
20. The following diagram shows input arguments being applied to three functionalinterfaces of unknown type. Which three functional interfaces, inserted in order fromleft to right, could be used to complete the diagram?
A. DoubleBinaryOperator
ToDoubleBiFunctionInteger,Double
UnaryOperatorInteger
B. BinaryOperatorDouble
BiFunctionInteger,Integer,Double
UnaryOperatorInteger
C. FunctionDouble,Integer
BiFunctionInteger,Integer,Double
DoubleToIntFunction
D. BiFunctionInteger,Double,Integer
BinaryOperatorInteger
IntUnaryOperator
21. Which statement about functional interfaces and lambda expressions is not true?
A. A lambda expression may be compatible with multiple functional interfaces.
B. A lambda expression must be assigned to a functional interface when it is declared.
C. A method can return a lambda expression in the form of a functional interface
instance.
D. The compiler uses deferred execution to skip determining whether a lambda
expression compiles or not.
22. Which expression is compatible with the IntSupplier functional interface?
A. () - 110 ? "3" : 4
B. () - {return 1/0;}
C. () - return 4
D. System.out::print
23. What is the output of the following application?
A. [JENNY, GRACE]
B. [tps.Boss@4218224c, tps.Boss@815f19a]
C. The code does not compile because of the lambda expression.
D. The code does not compile for a different reason.
24. Which of the following method references can be passed to a method that takesConsumerObject as an argument?
I. ArrayList::new
II. String::new
III. System.out::println
A. I only
B. I, II, and III
C. I and III
D. III only
25. Which of the following is a valid functional interface in the java.util.functionpackage?
A. FloatPredicate
B. ToDoubleBiFunction
C. UnaryIntOperator
D. TriPredicate
26. Which functional interface, when filled into the blank, prevents the class fromcompiling?
A. DoubleUnaryOperator
B. FunctionString,String
C. IntToLongFunction
D. UnaryOperator
27. Which functional interface does not have the correct number of generic arguments?
A. BiFunctionT,U,R
B. DoubleFunctionT,R
C. ToDoubleFunctionT
D. ToIntBiFunctionT,U
28. Which lambda expression, when filled into the blank, allows the code to compile?
A. (int n, double e) - (int)(n+e)
B. (n,w,e) - System.out::print
C. (s,w) - 2*w
D. (s,e) - s.intValue()+e.intValue()
29. Fill in the blank: ____________is the only functional interface that does notinvolve double, int, or long.
A. BooleanSupplier
B. CharPredicate
C. FloatUnaryOperator
D. ShortConsumer
30. What is the output of the following application?
A. 200
B. 250
C. The code does not compile because of line j1.
D. None of the above
31. Which functional interface takes a double value and has a test() method?
A. DoubleConsumer
B. DoublePredicate
C. DoubleUnaryOperator
D. ToDoubleFunction
32. Given the following class, how many lines contain compilation errors?
A. None. The code compiles as is.
B. One
C. Two
D. Three
33. Which lambda expression cannot be assigned to a DoubleToLongFunction functionalinterface?
A. a - null==null ? 1 : 2L
B. e - (int)(10.0*e)
C. (double m) - {long p = (long)m; return p;}
D. (Double s) - s.longValue()
34. Which of the following is not a functional interface in the java.util.functionpackage?
A. DoublePredicate
B. LongUnaryOperator
C. ShortSupplier
D. ToIntBiFunction
35. Which functional interface, when filled into the blank, allows the class to compile?
A. ConsumerSheep
B. FunctionSheep,void
C. UnaryOperatorSheep
D. None of the above
36. What is the output of the following application?
A. 2
B. 3
C. The code does not compile because of lambda expression.
D. The code does not compile for a different reason.
37. Which functional interface takes two values and has an apply() method?
A. BiConsumer
B. BiFunction
C. BiPredicate
D. DoubleBinaryOperator
38. Which of the following lambda expressions can be passed to a method that takesIntFunctionInteger as an argument?
I. (Integer f) - f
II. (v) - null
III. s - s
A. I, II, and III
B. II and III only
C. III only
D. None of the above
39. What is the output of the following application?
A. Plenty!
B. On Backorder!
C. The code does not compile because of the checkInventory() method.
D. The code does not compile for a different reason.
40. Which of the following statements about functional interfaces is true?
A. It is possible to define a functional interface that returns two data types.
B. It is possible to define a primitive functional interface that uses float, char, or
short.
C. It is not possible to define a functional interface that does not take any arguments
nor return any value.
D. None of the primitive functional interfaces include generic arguments
OCJP Practice Test, Certification Path, Tips/Tricks
- Oracle (OCJP) Java Certification Exam
- Java Certification Tips And Tricks
- OCJP Practice Papers - Java Basics
- OCJP Practice Papers - Operators And Decision Constructs
- OCJP Practice Papers-A Advanced Java Class Design
- OCJP Practice Papers Creating And Using Arrays
- OCJP Practice Papers Using Loop Constructs
- OCJP Practice Papers - Generics And Collections
- OCJP Practice Papers - Lambda Built-In Functional Interfaces
- OCJP Practice Papers Java Class Design
- OCJP Practice Papers - Java Stream API
- OCJP Practice Papers - Exceptions And Assertions
- OCJP Practice Papers - Date/Time API
- OCJP Practice Papers - Java I/O Fundamentals
- OCJP Practice Papers - Working With Methods And Encapsulation
- OCJP Practice Papers - Working With Inheritance
- OCJP Practice Papers - Handling Exceptions
- OCJP Practice Papers - Selected Classes From Java API
- OCJP Practice Papers - Java File I/O Nio.2
- OCJP Practice Papers - Java Concurrency