Java 8 in Action cover

Java 8 in Action

Rating 4.5
Word count
552K words
Chapters
35
Series
Turing Programming Series · Java Series
ISBN
9787115419347

Tags

Summary

This book is the Chinese translation of Java 8 in Action, built around the landmark new features introduced when Java 8 was released in March 2014, with the goal of helping developers already familiar with Java actually use the new syntax in everyday projects. The book has four parts. Part 1, Fundamentals, begins with why you should care about Java 8, explaining the motivations for Java's evolution against the backdrop of multicore processors and big data applications, then uses the running example of filtering apples to explain behavior parameterization, and systematically introduces lambda expressions, method references, functional interfaces and type inference, and explains why default methods are the key that allowed the collections libraries to evolve. Part 2, Functional-style Data Processing, focuses on the Stream API, including filtering, slicing, mapping, finding and matching, reducing, numeric streams and building streams, as well as using collectors to aggregate stream results into collections, groups and partitions; it also explains how parallel streams work and where they apply. Part 3, Effective Java 8 Programming, discusses refactoring existing code with lambdas and streams, making code more readable, testable and debuggable, and introduces Optional, CompletableFuture and the new date and time API. Part 4, Beyond Java 8, moves past specific APIs to the mindset and techniques of functional programming, persistent data structures and lazy evaluation, and uses a comparison with Scala to show hybrid object-oriented and functional styles, ending with a review of Java 8 language features and a look at Java's future; appendices cover library updates, annotations, performing multiple stream operations concurrently, and how lambdas are implemented in JVM bytecode. The book includes many runnable code examples, end-of-chapter summaries, and interactive sections such as quizzes and quick checks so readers can test their understanding as they read.

Editor's review

Java 8 是 Java 语言发展史上的一个分水岭:Lambda、Stream、默认方法、Optional、新日期时间 API 纷纷落地,代码写法由此从“命令式堆循环”转向“声明式描述意图”。但很多开发者至今仍停留在把 Lambda 当作语法糖、把 Stream 当作一种新 for 循环的层面,面试能答、代码里却依旧满是嵌套空判断和冗余遍历。本书的价值在于把每个特性背后的设计动机讲透:为什么要行为参数化、流为什么强调“内部迭代”、并行流什么时候会反而变慢、默认方法为何是集合库得以演进的必要代价。三位作者中,厄马是剑桥大学计算机科学博士,富斯科是 Red Hat 高级工程师、开源库 lambdaj 的作者,米克罗夫特是剑桥大学计算机实验室教授、树莓派基金会联合创始人,学术功底与工业经验兼备。全书结构清晰,以贯穿全文的“苹果筛选”案例层层递进,每个概念都配有完整可运行代码和章末小结,还设计了测验与快速检查,读起来更像跟着课程学,而非翻阅 API 手册。豆瓣评分长期维持在 9 分以上,是国内 Java 开发者学习 Java 8 新特性的首选中文读物,也常被列为企业内部培训与面试复习的参考书。需要提醒的是,本书只覆盖到 Java 8(后续版本中有《Java实战(第2版)》,涵盖 Java 8 至 11 等内容),若工作中已使用更高版本,可作为打好根基的第一站。

Who it's for

A good fit for

  • 已掌握 Java 基础语法与面向对象、希望系统学习 Java 8 新特性的开发者
  • 日常代码中大量使用 for 循环遍历集合、想转向声明式写法的工程师
  • 准备技术面试、需要吃透 Lambda 与 Stream 考点的求职者
  • 需要使用 Optional、CompletableFuture 和新时间 API 改善项目代码的中级开发者
  • 团队技术负责人,希望为组内确立统一的 Java 8 编码范式

Not a good fit for

  • 完全没有 Java 基础、尚未理解类、接口、泛型的初学者
  • 只想查 API 用法、希望当速查手册使用的读者
  • 只关心 Spring Boot、微服务等框架实战,不打算补语言基础的开发者
  • 已在生产中使用 Java 17 及以上版本、需要了解 record、switch 模式匹配等新特性的资深工程师

Reading tips

  1. 第 1 至 3 章务必精读并亲手敲代码,行为参数化与 Lambda 的思维方式是全书地基
  2. 第 2 部分边读边把项目里已有的循环筛选、分组统计改写成 Stream 版本,效果最明显
  3. 并行流与新日期时间 API 两处容易误用,读完先在非核心业务中小范围试点再推广
  4. 每章末的测验先自己作答再看答案,用来检验是否真正理解而非只是看懂了代码

About the publisher

Posts & Telecom Press China · Founded in 1953

Posts & Telecom Press is known for its strengths in science and technology, computing, and information and communications titles, and has extended its publishing into photography, art, software learning, and inspirational growth, giving it a fairly diverse range. Its catalog includes computing and communications works such as Refactoring and Patterns (Revised Edition) and Huawei Switch Learning Guide (Second Edition), alongside bilingual collector's editions such as The Little Prince (Chinese-English-French illustrated collector's edition), The Great Gatsby, and Three Days to See. Beijing Ten Years: 1980-1990 and Ghost Blade: WLOP Personal Illustration Collection reflect its presence in photography and art. Its authors include Antoine de Saint-Exupéry, Helen Keller, Joshua Kerievsky, Wang Da, Zhang Zhaozeng, and WLOP.

Contents

  1. Part 1 Fundamentals
  2. Chapter 1 Why Care About Java 8
  3. 1.1 Why Java Keeps Changing
  4. 1.2 Functions in Java
  5. 1.3 Streams
  6. 1.4 Default Methods
  7. 1.5 Other Good Ideas from Functional Programming
  8. 1.6 Summary
  9. Chapter 2 Passing Code Through Behavior Parameterization
  10. 2.1 Coping with Changing Requirements
  11. 2.2 Behavior Parameterization
  12. 2.3 Tackling Verbosity (Anonymous Classes and Lambdas)
  13. 2.4 Real-World Examples (Comparator, Runnable, GUI Event Handling)
  14. 2.5 Summary
  15. Chapter 3 Lambda Expressions
  16. 3.1 A First Look at Lambdas
  17. 3.2 Where and How to Use Lambdas (Functional Interfaces, Function Descriptors)
  18. 3.3 Putting Lambdas into Practice: The Execute-Around Pattern
  19. 3.4 Using Functional Interfaces (Predicate, Consumer, Function)
  20. 3.5 Type Checking, Type Inference and Restrictions
  21. Chapter 4 Introducing Streams
  22. Chapter 5 Working with Streams
  23. Chapter 6 Collecting Data with Streams
  24. Chapter 7 Parallel Data Processing and Performance
  25. Part 2 Functional-style Data Processing
  26. Part 3 Effective Java 8 Programming (Refactoring, Optional, CompletableFuture, the New Date and Time API)
  27. Part 4 Beyond Java 8
  28. Chapter 13 Thinking Functionally
  29. Chapter 14 Techniques of Functional Programming
  30. Chapter 15 Mixing Object-Oriented and Functional Programming: Java 8 and Scala Compared
  31. Chapter 16 Conclusions and Java's Future
  32. Appendix A Updates to Other Language Features
  33. Appendix B Library Updates
  34. Appendix C Performing Multiple Operations on the Same Stream Concurrently
  35. Appendix D Lambda Expressions and JVM Bytecode

FAQ

这本书和《Java实战(第2版)》有什么区别?
本书是《Java 8 in Action》的中译本,只讲 Java 8 的新特性。第 2 版在此基础上补充了 Java 9、10、11 的内容(模块系统、局部变量类型推断等)。若你所在项目已用较高版本 JDK,可直接选择第 2 版。
零基础可以读这本书吗?
不建议。本书面向熟悉 Java 语法、面向对象与泛型的读者,开篇即讨论行为参数化,不会讲解基本语法。零基础建议先读入门教材,再来读这一本。
书中的代码示例可以直接运行吗?
示例基于 Java 8 编写,结构完整,多数可直接编译运行。少数示例需要额外依赖或构建工具配置,建议边读边在本地 IDE 中新建工程手敲验证,比只看代码收获大得多。
现在 Java 都更新到 20 多个版本了,读只讲 Java 8 的书还有意义吗?
有意义。Lambda、Stream、Optional、新日期时间 API 至今仍是主流写法的基础,Java 后续版本的模式匹配、record 等特性也都建立在这套函数式思路之上。先把这些吃透,再学新特性会轻松很多。
这本书的豆瓣评分是多少?
该书在豆瓣长期保持 9 分以上评价,不同渠道的统计(豆瓣页、出版社资料)在 9.1 至 9.3 之间浮动。评分随用户评价动态变化,购买前建议查看最新页面。

Comments

Find this book

This site is an index: you start “Search all sources” in your browser, and the entries it lists all point to third-party sites; please judge their availability yourself.

More by the same author

Top rated in the same category