Writing High-Quality Java Code cover

Writing High-Quality Java Code

No rating yet
Chapters
13
ISBN
9787111362593

Tags

Summary

Written by Qin Xiaobo and Cheng Lin and published by China Machine Press, this book shares its content with Writing High-Quality Code: 151 Suggestions for Improving Java Programs. It consists of 151 independent recommendations, arranged in the order of "syntax—classes and objects—JDK API—performance and tools—coding style and programming thought." Chapters 1 to 3 focus on the fundamentals of the Java language, discussing constants and variables, the ternary operator, varargs methods, serialization and static imports, wrapper types and boundary values, equals and hashCode, and other error-prone points. Chapters 4 to 9 address JDK APIs such as strings, arrays and collections, enums and annotations, generics and reflection, exception handling, and multithreading, explaining the appropriate use cases and pitfalls of each. Chapters 10 to 12 turn to performance tuning, the use of open-source tools and frameworks, and the cultivation of coding standards and programming thought. Each recommendation follows a structure of "first a typical scenario, then a comparison of good and bad practice, finally an analysis of the root cause," offering conclusions that can be applied directly as well as explanations at the JVM level. The book works well as a quick-reference manual for daily development; reading it straight through gives a systematic review of Java's syntactic details, and looking up entries as specific problems arise is equally effective.

Editor's review

Java 学到能写业务代码并不难,难的是写出“不出事、看得懂、改得动”的代码。这本书的写法正对这一点:不谈宏大的架构,也不堆砌框架用法,而是把一个个真实会踩到的坑摊开——为什么三元操作符两边类型不一致会引发意外、为什么包装类型用 == 比较会出问题、为什么覆写 equals 必须连 hashCode 一起改。每条建议都是“场景—反例—正解—根源”四步走,读到反例时常有“这段代码我写过”的熟悉感。 它有两个明显优点。一是颗粒度细,151 条建议相互独立,任何一条都可以在十分钟内读完并立刻用上,通勤路上翻两页就是收获;二是解释到了 JVM 层面,比如整型缓存池、构造代码块的执行顺序、序列化时的字段赋值时机,知道“为什么”之后才不容易忘。不足之处是成书较早,语言版本停留在 Java SE 6/7 时代,Lambda、Stream、Optional 等新特性没有覆盖,涉及老版本 API 的建议也要结合当前项目判断。把它当作夯实基础的常备手册,而不是新技术指南,就会有很好的性价比。

Who it's for

A good fit for

  • 已掌握 Java 基本语法、开始独立负责模块的初中级开发者
  • 希望系统梳理 Java 语言细节与常见陷阱的工程师
  • 需要为团队制定编码规范、做代码评审的技术负责人
  • 准备 Java 相关技术面试、想补齐语言细节的求职者

Not a good fit for

  • 完全没有编程基础、尚未写过 Java 程序的零基础读者
  • 主要想学习 Spring Boot、微服务等框架与工程架构的读者
  • 只想了解 Java 8 之后新特性(Lambda、Stream、模块化)的读者

Reading tips

  1. 先通读第1至3章,这部分覆盖日常编码最高频的语法陷阱,收益最直接。
  2. 把其余章节当工具书,遇到集合、并发、异常相关问题时按目录检索对应建议。
  3. 每读完一条建议,回到自己的项目里搜索类似写法,改一处比读十遍更记得住。
  4. 阅读时对照当前使用的 JDK 版本实践,老版本 API 的结论需自行验证后再采用。

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 Principles in Java Development (Recommendations 1–20)
  3. Chapter 2 Primitive Types (Recommendations 21–30)
  4. Chapter 3 Classes, Objects, and Methods (Recommendations 31–51)
  5. Chapter 4 Strings (Recommendations 52–59)
  6. Chapter 5 Arrays and Collections (Recommendations 60–83)
  7. Chapter 6 Enums and Annotations (Recommendations 84–92)
  8. Chapter 7 Generics and Reflection (Recommendations 93–106)
  9. Chapter 8 Exceptions (Recommendations 107–117)
  10. Chapter 9 Multithreading and Concurrency (Recommendations 118–131)
  11. Chapter 10 Performance and Optimization (Recommendations 132–139)
  12. Chapter 11 Open-Source Tools and Frameworks (Recommendations 140–146)
  13. Chapter 12 Coding Style and Programming Thought (Recommendations 147–151)

FAQ

这本书和《改善Java程序的151个建议》是同一本吗?
两者内容同源,都是围绕151条建议展开的Java编码实践;《编写高质量代码之Java》在书目与电子版中常被标为秦小波、成林合著,机械工业出版社出版,ISBN 与2012年版一致(9787111362593),可视为同一本书的不同书名或版本标注,购买前建议核对版权页。
书里的建议还适用于现在的 JDK 吗?
大部分结论仍然成立,如基本类型与包装类型的选择、equals 与 hashCode 的约定、集合遍历方式、可变参数与重载的陷阱等。但成书于 Java SE 6/7 时期,未涉及 Lambda、Stream、Optional、模块化等新特性,遇到涉及废弃 API 的建议应以当前版本文档为准。
零基础可以直接读这本书吗?
不建议。书中默认读者已能编写完整类与程序,讨论的是“怎样写得更好”,而不是“怎样入门”。完全没有 Java 基础的话,建议先学完语法、集合与异常处理,再来读这本书会顺畅得多。
需要按顺序从头读到尾吗?
不必。151条建议彼此独立,可按章节主题或目录关键词跳读。比较推荐的做法是先读完第1至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.

About the author

成林 Author

Cheng Lin is an author about whom very limited public information is available in the Chinese book database; only one work can be identified so far, namely the English Synchronized Workbook (Selective Compulsory Book 4). Judging from the title and its common classification, the book is a test-oriented supplementary teaching aid intended for high school students using Selective Compulsory Book 4, offering exercises that follow classroom instruction and help students consolidate vocabulary, grammar, and reading skills. Because public information is limited, Cheng Lin's nationality, education, professional background, and writing experience cannot be confirmed, nor is it possible to determine whether the author has long been engaged in English teaching or the compilation of supplementary materials. As far as the existing work shows, the approach is practical and synchronized, aligning with textbook progress, with exercise types designed for daily practice and exam preparation. Such supplementary books are usually produced by editors familiar with textbooks and examination requirements, and Cheng Lin's work reflects this characteristic, serving as auxiliary material for high school English study and for teachers and students in after-class practice and review.

More by the same author

Top rated in the same category