Java Reference
In-Depth Information
away from classical object orientation, which often focuses on mutating existing values, and
toward the functional-style programming spectrum in which what you want to do in
broad-brush terms (for example, create a value representing all transport routes from A to B for
less than a given price) is considered prime and separated from how you can achieve this (for
example, scan a data structure modifying certain components). Note that classical
object-oriented programming and functional programming, as extremes, might appear to be in
conflict. But the idea is to get the best from both programming paradigms, so you have a better
chance of having the right tool for the job! We discuss this in detail in the next two sections:
functions in Java and the new Streams API.
A takeaway line might be this: languages need to evolve to track changing hardware or
programmer expectations (if you need convincing, then consider that COBOL was once one of
the most important languages commercially). To endure, Java has to evolve by adding new
features. This evolution will be pointless unless the new features are used, so in using Java 8
you're protecting your way of life as a Java programmer. On top of that, we have a feeling you'll
love using Java 8's new features. Ask anyone who's used Java 8 whether they're willing to go
back! Additionally, the new Java 8 features might, in the ecosystem analogy, enable Java to
conquer programming-task territory currently occupied by other languages, so Java 8
programmers will be even more in demand.
We now introduce the new concepts in Java 8, one by one—pointing out on the way the chapters
that cover these concepts in more detail.
1.2. Functions in Java
The word function in programming languages is commonly used as a synonym for method ,
particularly a static method; this is in addition to it being used for mathematical function , one
without side effects. Fortunately, as you'll see, when Java 8 refers to functions these usages very
nearly coincide.
Java 8 adds functions as new forms of value. These facilitate the use of Streams, covered in
section 1.3 , which Java 8 provides to exploit parallel programming on multicore processors. We
start by showing that functions as values are useful in themselves.
Think about the possible values manipulated by Java programs. First, there are primitive values
such as 42 (of type int) and 3.14 (of type double). Second, values can be objects (more strictly,
references to objects). The only way to get one of these is by using new, perhaps via a factory
method or a library function; object references point to instances of a class. Examples include
"abc" (of type String), new Integer(1111) (of type Integer), and the result new HashMap<Integer,
 
Search WWH ::




Custom Search