Spring & Functional Idioms Flashcards
Why was it necessary for Java to include the BigDecimal type?
BigDecimal avoids the floating point errors that can arise when using double for calculations. BigDecimal can represent all numbers that can be represented in decimal notion and that includes all numbers representing money. If you are dealing with money, or precision is a must, use BigDecimal.
What are the some of the major differences between implementing Spring DI using XML configuration vs using annotations?
Each approach has its pros and cons, and, usually, it is up to the developer to decide which strategy suits them better. Due to the way they are defined, annotations provide a lot of context in their declaration, leading to shorter and more concise configuration. However, because XML wires up components using an external file, changes can be made without touching the source code or recompiling. Some developers prefer having the wiring close to the source while others argue that when using annotated classes, the configuration becomes decentralized and harder to control. Spring can accommodate both styles and even mix them together.
What is a lambda or anonymous method?
A lambda or anonymous function (sometimes called a function literal) is a function definition that is not bound to an identifier. Anonymous functions are often arguments being passed to higher-order functions. It comprises a set of parameters, a lambda operator (->) and a function body.
How does using the Streams API to solve a data related problem compare to writing imperative code (loops, conditional statements, etc.)?
A stream is a sequence of objects that supports various methods which can be pipelined to produce the desired result. Streams bring functional programming in Java. You can use the Streams API by importing the java.util.stream package.
Advantages of streams:
Streams provide the most convenient and natural way to apply functions to sequences of objects.
Streams can succinctly express quite sophisticated behavior.
If mutability is a concern, operations performed on a stream do not modify the source.