Govt. Exams
Entrance Exams
A prototype bean can depend on singleton beans without issues. Each prototype instance gets the same singleton instance injected. The reverse (singleton depending on prototype) is problematic.
@Profile allows defining beans for specific environments (dev, prod, test). Alternatively, @Conditional provides more granular control with custom conditions.
map() is an intermediate operation that returns an IntStream. The lambda expression (x -> x * 2) transforms each int, but map() itself returns IntStream, not the transformed value type.
Optional with map() using a lambda expression is the functional programming approach. It's safe, readable, and chains operations effectively. Options B, C, and D are imperative approaches.
If a lambda body throws a checked exception, it must be declared in the functional interface's method signature. Otherwise, compilation will fail.
Lambda expressions can only be used with functional interfaces (single abstract method), whereas anonymous classes can implement any interface. Lambda expressions are also more concise.
Both expressions correctly sort by length. Option B uses Integer.compare (safer for int overflow), while Option C uses direct subtraction. Both work correctly here.
Function f1 = x -> x * 2;
Function f2 = x -> x + 5;
How to apply f1 first, then f2?
Both andThen and explicit composition order result in applying f1 first (3*2=6, then 6+5=11), equivalent to option C.
map() is an intermediate operation. The println executes because collect() is a terminal operation that triggers evaluation. It prints 1, 2, 3 (the original values).
This is a curried function - a higher-order function that takes one argument and returns another function taking the next argument. It transforms multi-argument functions into sequences of single-argument functions.