My Java 8 in Action

来源:互联网 发布:枪手步态 知乎 编辑:程序博客网 时间:2024/05/22 14:57

《Java 8 in Action》有500+页,相当地啰嗦。啰嗦的另一面是详细,可以作为我学习Java 8的一个索引。

在“编程导论_codes_补充\Java8Demo”创建了一个Netbeans项目。


第0章 简介

第1章 λ表达式

技术上,λ表达式并不能够让程序员做Java 8之前不能够做的事情,λ表达式只是实现回调函数的更紧凑的方式。观念上,Java引入λ表达式,希望程序员能够以函数式编程的高阶函数考虑问题,而非以多态考虑问题。

1.1λ表达式的本质 通过一个接口DoubleOP,说明应用程序App提供回调函数的3种方式,由此可知,λ表达式最基本的目的:替换匿名类以编写更简洁/concise的代码。

Java 8并没有把函数设计为一种数据类型而是依靠现有的常规类型,Java的lambda表达式,不是匿名函数,而是省略了名字的函数。所以有了目标类型(target typing)、函数接口的概念。

1.1.2λ表达式的语法

1.2高阶函数

1.2.1行为参数化 函数接口作为形参

1.2.2函数作为返回值

1.2.3默认方法

1.2.4 java.util.function.*

第2章

2.1什么是流 比较Stream与常用的数组或集合类如List,流的元素可以是无限的。从MapReduce模型,说明需要数据序列的供给过程和使用过程交替进行的结构——流。

2.2管道/Pipelinin惰性/ laziness、部分地构造、流的一次性

1. λ表达式

Java8: 《3.1. Lambdas in a nutshell》

λ表达式的基本用途 完成了回调的原意——代码的参数化。λ表达式可以赋值给变量,作为实参。


2.流

Stream概念 java.util.stream.Stream 管道/Pipelinin、

创建Stream 《5.7. Building streams》在练习各种操作之前,有流对象在手。


1. Fundamentals
Chapter 1. Java 8: why should you care?
1.1. Why is Java still changing?
1.1.1. Java’s place in the programming language
ecosystem
1.1.2. Stream processing
1.1.3. Passing code to methods with behavior
parameterization
1.1.4. Parallelism and shared mutable data
1.1.5. Java needs to evolve
1.2. Functions in Java
1.2.1. Methods and lambdas as first-class citizens
1.2.2. Passing code: an example
1.2.3. From passing methods to lambdas
1.3. Streams
1.3.1. Multithreading is difficult
1.4. Default methods
1.5. Other good ideas from functional programming
1.6. Summary


Chapter 2 Passing code with behavior parameterization

Chapter 3. Lambda expressions
3.2.1. Functional interface
3.2.2. Function descriptor
3.4. Using functional interfaces
3.4.1. Predicate
3.4.2. Consumer
3.4.3. Function
3.5. Type checking, type inference, and restrictions
3.5.1. Type checking
3.5.2. Same lambda, different functional interfaces
3.5.3. Type inference
3.5.4. Using local variables
3.6. Method references
3.6.1. In a nutshell
3.6.2. Constructor references
3.7. Putting lambdas and method references into
practice!
3.7.1. Step 1: Pass code
3.7.2. Step 2: Use an anonymous class
3.7.3. Step 3: Use lambda expressions
3.7.4. Step 4: Use method references
3.8. Useful methods to compose lambda expressions
3.8.1. Composing Comparators
3.8.2. Composing Predicates
3.8.3. Composing Functions
3.9. Similar ideas from mathematics
3.9.1. Integration
3.9.2. Connecting to Java 8 lambdas
3.10. Summary
2. Functional-style data processing
Chapter 4. Introducing streams
4.1. What are streams?
4.2. Getting started with streams
4.3. Streams vs. collections
4.3.1. Traversable only once
4.3.2. External vs. internal iteration
4.4. Stream operations
4.4.1. Intermediate operations
4.4.2. Terminal operations
4.4.3. Working with streams
4.5. Summary
Chapter 5. Working with streams
5.1. Filtering and slicing
5.1.1. Filtering with a predicate
5.1.2. Filtering unique elements
5.1.3. Truncating a stream
5.1.4. Skipping elements
5.2. Mapping
5.2.1. Applying a function to each element of a stream
5.2.2. Flattening streams
5.3. Finding and matching
5.3.1. Checking to see if a predicate matches at least
one element
5.3.2. Checking to see if a predicate matches all
elements
5.3.3. Finding an element
5.3.4. Finding the first element
5.4. Reducing
5.4.1. Summing the elements
5.4.2. Maximum and minimum
5.5. Putting it all into practice
5.5.1. The domain: Traders and Transactions
5.5.2. Solutions

5.6.3. Putting numerical streams into practice:Pythagorean triples
Java8:创建Stream (5.6. Numeric streams 
5.7.3. Streams from files
5.8. Summary
Chapter 6. Collecting data with streams
6.1. Collectors in a nutshell
6.1.1. Collectors as advanced reductions
6.1.2. Predefined collectors
6.2. Reducing and summarizing
6.2.1. Finding maximum and minimum in a stream of
values
6.2.2. Summarization
6.2.3. Joining Strings
6.2.4. Generalized summarization with reduction
6.3. Grouping
6.3.1. Multilevel grouping
6.3.2. Collecting data in subgroups
6.4. Partitioning
6.4.1. Advantages of partitioning
6.4.2. Partitioning numbers into prime and nonprime
6.5. The Collector interface
6.5.1. Making sense of the methods declared by
Collector interface
6.5.2. Putting them all together
6.6. Developing your own collector for better
performance
6.6.1. Divide only by prime numbers
6.6.2. Comparing collectors’ performances
6.7. Summary
Chapter 7. Parallel data processing and performance
7.1. Parallel streams
7.1.1. Turning a sequential stream into a parallel one
7.1.2. Measuring stream performance
7.1.3. Using parallel streams correctly
7.1.4. Using parallel streams effectively
7.2. The fork/join framework
7.2.1. Working with RecursiveTask
7.2.2. Best practices for using the fork/join framework
7.2.3. Work stealing
7.3. Spliterator
7.3.1. The splitting process
7.3.2. Implementing your own Spliterator
7.4. Summary
3. Effective Java 8 programming
Chapter 8. Refactoring, testing, and debugging
8.1. Refactoring for improved readability and flexibility
8.1.1. Improving code readability
8.1.2. From anonymous classes to lambda expressions
8.1.3. From lambda expressions to method references
8.1.4. From imperative data processing to Streams
8.1.5. Improving code flexibility
8.2. Refactoring object-oriented design patterns with
lambdas
8.2.1. Strategy
8.2.2. Template method
8.2.3. Observer
8.2.4. Chain of responsibility
8.2.5. Factory
8.3. Testing lambdas
8.3.1. Testing the behavior of a visible lambda
8.3.2. Focusing on the behavior of the method using
a lambda
8.3.3. Pulling complex lambdas into separate methods
8.3.4. Testing high-order functions
8.4. Debugging
8.4.1. Examining the stack trace
8.4.2. Logging information
8.5. Summary
Chapter 9. Default methods
9.1. Evolving APIs
9.1.1. API version 1
9.1.2. API version 2
9.2. Default methods in a nutshell
9.3. Usage patterns for default methods
9.3.1. Optional methods
9.3.2. Multiple inheritance of behavior
9.4. Resolution rules
9.4.1. Three resolution rules to know
9.4.2. Most specific default-providing interface wins
9.4.3. Conflicts and explicit disambiguation
9.4.4. Diamond problem
9.5. Summary
Chapter 10. Using Optional as a better alternative to null
10.1. How do you model the absence of a value?
10.1.1. Reducing NullPointerExceptions with defensive
checking
10.1.2. Problems with null
10.1.3. What are the alternatives to null in other
languages?
10.2. Introducing the Optional class
10.3. Patterns for adopting Optional
10.3.1. Creating Optional objects
10.3.2. Extracting and transforming values from
optionals with map
10.3.3. Chaining Optional objects with flatMap
10.3.4. Default actions and unwrapping an optional
10.3.5. Combining two optionals
10.3.6. Rejecting certain values with filter
10.4. Practical examples of using Optional
10.4.1. Wrapping a potentially null value in an optional
10.4.2. Exceptions vs. Optional
10.4.3. Putting it all together
10.5. Summary
Chapter 11. CompletableFuture: composable asynchronous
programming
11.1. Futures
11.1.1. Futures limitations
11.1.2. Using CompletableFutures to build an
asynchronous application
11.2. Implementing an asynchronous API
11.2.1. Converting a synchronous method into an
asynchronous one
11.2.2. Dealing with errors
11.3. Make your code non-blocking
11.3.1. Parallelizing requests using a parallel Stream
11.3.2. Making asynchronous requests with
CompletableFutures
11.3.3. Looking for the solution that scales better
11.3.4. Using a custom Executor
11.4. Pipelining asynchronous tasks
11.4.1. Implementing a discount service
11.4.2. Using the Discount service
11.4.3. Composing synchronous and asynchronous
operations
11.4.4. Combining two CompletableFutures—dependent
and independent
11.4.5. Reflecting on Future vs. CompletableFuture
11.5. Reacting to a CompletableFuture completion
11.5.1. Refactoring the best-price-finder application
11.5.2. Putting it to work
11.6. Summary
Chapter 12. New Date and Time API
12.1. LocalDate, LocalTime, Instant, Duration, and Period
12.1.1. Working with LocalDate and LocalTime
12.1.2. Combining a date and a time
12.1.3. Instant: a date and time for machines
12.1.4. Defining a Duration or a Period
12.2. Manipulating, parsing, and formatting dates
12.2.1. Working with TemporalAdjusters
12.2.2. Printing and parsing date-time objects
12.3. Working with different time zones and calendars
12.3.1. Fixed offset from UTC/Greenwich
12.3.2. Using alternative calendar systems
12.4. Summary
4. Beyond Java 8
Chapter 13. Thinking functionally
13.1. Implementing and maintaining systems
13.1.1. Shared mutable data
13.1.2. Declarative programming
13.1.3. Why functional programming?
13.2. What’s functional programming?
13.2.1. Functional-style Java
13.2.2. Referential transparency
13.2.3. Object-oriented vs. functional-style programming
13.2.4. Functional style in practice
13.3. Recursion vs. iteration
13.4. Summary
Chapter 14. Functional programming techniques
14.1. Functions everywhere
14.1.1. Higher-order functions
14.1.2. Currying
14.2. Persistent data structures
14.2.1. Destructive updates vs. functional
14.2.2. Another example with Trees
14.2.3. Using a functional approach
14.3. Lazy evaluation with streams
14.3.1. Self-defining stream
14.3.2. Your own lazy list
14.4. Pattern matching
14.4.1. Visitor design pattern
14.4.2. Pattern matching to the rescue
14.5. Miscellany
14.5.1. Caching or memoization
14.5.2. What does “return the same object” mean?
14.5.3. Combinators
14.6. Summary
Chapter 15. Blending OOP and FP: comparing Java 8 and
Scala
15.1. Introduction to Scala
15.1.1. Hello beer
15.1.2. Basic data structures: List, Set, Map, Tuple,
Stream, Option
15.2. Functions
15.2.1. First-class functions in Scala
15.2.2. Anonymous functions and closures
15.2.3. Currying
15.3. Classes and traits
15.3.1. Less verbosity with Scala classes
15.3.2. Scala traits vs. Java 8 interfaces
15.4. Summary
Chapter 16. Conclusions and where next for Java
16.1. Review of Java 8 features
16.1.1. Behavior parameterization (lambdas and method
references)
16.1.2. Streams
16.1.3. CompletableFuture
16.1.4. Optional
16.1.5. Default methods
16.2. What’s ahead for Java?
16.2.1. Collections
16.2.2. Type system enhancements
16.2.3. Pattern matching
16.2.4. Richer forms of generics
16.2.5. Deeper support for immutability
16.2.6. Value types
16.3. The final word
Appendix A. Miscellaneous language updates
A.1. Annotations
A.1.1. Repeated annotations
A.1.2. Type annotations
A.2. Generalized target-type inference
Appendix B. Miscellaneous library updates
B.1. Collections
B.1.1. Additional methods
B.1.2. The Collections class
B.1.3. Comparator
B.2. Concurrency
B.2.1. Atomic
B.2.2. ConcurrentHashMap
B.3. Arrays
B.3.1. Using parallelSort
B.3.2. Using setAll and parallelSetAll
B.3.3. Using parallelPrefix
B.4. Number and Math
B.4.1. Number
B.4.2. Math
B.5. Files
B.6. Reflection
B.7. String
Appendix C. Performing multiple operations in parallel on a
stream
C.1. Forking a stream
C.1.1. Implementing the Results interface with the
ForkingStreamConsumer
C.1.2. Developing the ForkingStreamConsumer and the
BlockingQueueSpliterator
C.1.3. Putting the StreamForker to work
C.2. Performance considerations
Appendix D. Lambdas and JVM bytecode
D.1. Anonymous classes
D.2. Bytecode generation
D.3. InvokeDynamic to the rescue
D.4. Code-generation strategies

0 0
原创粉丝点击