Writing High-Quality Code: Java cover

Writing High-Quality Code: Java

No rating yet
Chapters
13
ISBN
9787111362593

Tags

Summary

This book is a guide to Java coding best practices, titled Writing High-Quality Code: 151 Suggestions for Improving Java Programs. Organized into five major sections—syntax conventions, program design and architecture, tools and frameworks, coding style, and programming philosophy—it comprises 12 chapters presented as 151 recommendations, each dissecting common pitfalls Java developers encounter in their daily work. Chapters 1–3 offer 51 recommendations on Java syntax itself, covering constants and variables, type consistency in ternary operators, varargs overloading, increment traps, serialization and UID, assertion usage, the boundary between primitive and wrapper types, monetary calculations, overriding equals/hashCode, anonymous class constructors, garbage collection, and other foundational topics. Chapters 4–9 focus on practical scenarios involving the JDK API, including string concatenation and the choice of commonly used methods, optimized use of collections and enums, prevention of NullPointerException, multiple bounds in generics, multithreading, and deadlock prevention. Chapters 10–12 extend to program performance tuning, the trade-offs of open-source tools and frameworks, and coding style and programming philosophy. Most recommendations follow a "contrast between correct and incorrect examples" approach: first presenting a flawed or poor practice and analyzing its root cause, then offering a field-tested solution, and finally clarifying applicable scenarios and caveats. The examples are typical and closely tied to real-world development. The book can be read sequentially by topic or used as a desk reference to consult whenever writing a line of code or taking over a project.

Editor's review

Java 书籍大多在讲「怎么用」,这本书专注讲「怎样写才对、写得更好」。151 条建议每一条都自带一个真实的踩坑现场:变长参数重载带来的编译歧义、三元操作符类型不一致引发的隐式转换、包装类型比较的经典陷阱、货币计算误用 double、equals 与 hashCode 不成对覆写导致集合失效……这些内容放在今天的面试题和代码评审里依然是高频考点。 本书最大的价值在于它的「双向对比」写法。作者不满足于告诉你正确答案,而是先把你可能写出的错法摆出来,再解释 JVM、JDK 的设计原理为何会导致这种偏差,最后才给建议。这种从现象到原理、再到规范的推导路径,比单纯背结论更能沉淀为编码直觉。对于已经能写业务代码、但常被线上 Bug 和 Code Review 意见困扰的开发者,本书是一次系统性的「代码卫生」体检。 需要提醒的是,书中部分示例基于 Java 6/7 时代的 JDK,例如字符串拼接、并发集合、日期时间处理等话题,如今已有 Java 8 之后的更优方案。阅读时宜「取思想、辨细节」,把建议背后的原理迁移到当前版本中理解,效果最佳。

Who it's for

A good fit for

  • 已掌握 Java 基础语法、能独立写业务代码的初中级开发者
  • 希望减少线上 Bug、提升代码评审通过率的工程师
  • 准备 Java 面试、需要系统梳理语言细节与陷阱的求职者
  • 带新人或做代码规范落地的技术负责人、团队 Leader

Not a good fit for

  • 完全没有 Java 基础、尚未写过类的初学者,读来会偏琐碎
  • 只关心框架用法(如 Spring Boot 集成)而不关心语言细节的读者
  • 期待覆盖 Java 8 之后新特性(Stream、Optional、新日期 API)的读者

Reading tips

  1. 不要从头背到尾:先把 151 条标题过一遍,标出与自己项目相关的条目,优先精读。
  2. 每条建议动手复现书中的反例代码,亲眼看到编译报错或运行异常,印象远胜过阅读。
  3. 关注 Java 版本差异,遇到字符串、集合、并发相关建议时对照当前 JDK 文档确认是否有更优写法。
  4. 把书放在工位或 IDE 旁边当速查手册,在 Code Review 前后按主题翻阅,效果更好。

About the publisher

China Machine Press China · Founded in 1950

In addition to science and technology and professional publishing, the books in our catalog from China Machine Press also reflect a sustained focus on psychology, computing, management, finance and economics, and social sciences. In psychology, the catalog includes works by C. G. Jung and introductions to analytical psychology, as well as applied topics such as stress and health, and addiction and healing. In computing, it features Structure and Interpretation of Computer Programs (JavaScript Edition). Management and finance titles include Administrative Behavior (4th Edition), The Price of Inequality (Collector's Edition), and This Time Is Different: Eight Centuries of Financial Folly (Commemorative Edition). In the philosophy and history of science, there is The Worldview: The Third Edition. Relevant authors include C. G. Jung, William McGuire, Sonu Shamdasani, and Gabor Maté. Public information is limited; the above summarizes the publisher's profile based solely on the books in our catalog.

Contents

  1. Preface
  2. Chapter 1 Common Methods and Guidelines in Java Development
  3. Chapter 2 Primitive Types
  4. Chapter 3 Classes, Objects, and Methods
  5. Chapter 4 Strings
  6. Chapter 5 Arrays and Collections
  7. Chapter 6 Enums and Annotations
  8. Chapter 7 Generics and Reflection
  9. Chapter 8 Exceptions and Logging
  10. Chapter 9 Multithreading and Concurrency
  11. Chapter 10 Performance and Efficiency
  12. Chapter 11 The Open-Source World
  13. Chapter 12 Thought as the Source

FAQ

这本书和《改善Java程序的151个建议》是同一本书吗?
是同一本书。《编写高质量代码之Java》是书名的简称写法,完整书名为《编写高质量代码:改善Java程序的151个建议》,ISBN 均为 9787111362593,由机械工业出版社出版,作者秦小波。部分图书馆书目信息中另有「成林」并列署名,购买或借阅时以 ISBN 核对最为稳妥。
书里的内容过时了吗,还值得读吗?
核心内容仍成立。书中的基础类型、equals/hashCode、序列化、泛型、并发死锁等议题属于 Java 语言的长期知识。但部分示例基于 Java 6/7,字符串处理、并发工具、日期时间等已有更新方案,建议对照当前 JDK 文档阅读,取其原理而非照抄写法。
需要什么基础才能读懂?
至少应能熟练编写类和接口、使用集合与多线程基础 API。书中直接从语法细节切入,不铺垫语言入门知识,零基础读者容易觉得零散;有一定项目经验后再读,反而能处处对上自己踩过的坑。
适合当作面试复习资料吗?
很适合作为补充。书中大量「反例+原理」的讲法,正好对应面试中关于隐式转换、自动装箱缓存、equals 与 hashCode 约定、序列化等高频考点。不过它不覆盖数据结构与算法、JVM 内存模型等专题,需与其他资料配合使用。

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