In Java Examples in a Nutshell, David Flanagan, the bestselling author of Java in a Nutshell, has created an entire book of programs that not only serve as great learning tools, but can also be modified for individual use. The second edition covers Java 1.3, and contains 164 complete, prac
Java by Comparison - Become a Java Craftsman in 70 Examples
β Scribed by Simon Harrer, JΓΆrg Lenhard, Linus Dietz
- Publisher
- The Pragmatic Programmers
- Year
- 2018
- Tongue
- English
- Leaves
- 206
- Category
- Library
No coin nor oath required. For personal study only.
β¦ Synopsis
Write code that's clean, concise, and to the point: code that others will read with pleasure and reuse. Comparing your code to that of expert programmers is a great way to improve your coding skills. Get hands-on advice to level up your coding style through small and understandable examples that compare flawed code to an improved solution. Discover handy tips and tricks, as well as common bugs an experienced Java programmer needs to know. Make your way from a Java novice to a master craftsman.
This book is a useful companion for anyone learning to write clean Java code. The authors introduce you to the fundamentals of becoming a software craftsman, by comparing pieces of problematic code with an improved version, to help you to develop a sense for clean code. This unique before-and-after approach teaches you to create clean Java code.
Learn to keep your booleans in check, dodge formatting bugs, get rid of magic numbers, and use the right style of iteration. Write informative comments when needed, but avoid them when they are not. Improve the understandability of your code for others by following conventions and naming your objects accurately. Make your programs more robust with intelligent exception handling and learn to assert that everything works as expected using JUnit5 as your testing framework. Impress your peers with an elegant functional programming style and clear-cut object-oriented class design.
Writing excellent code isn't just about implementing the functionality. It's about the small important details that make your code more readable, maintainable, flexible, robust, and faster. Java by Comparison teaches you to spot these details and trains you to become a better programmer.
What You Need:
You need a Java 8 compiler, a text editor, and a fresh mind.That's it.
β¦ Table of Contents
Cover
Table of Contents
Foreword
Acknowledgments
Welcome!
Who Should Read This Book
Why Read This Book?
How to Read This Book
Online Resources
Get Ready for Your Mission to Mars
1. Start Cleaning Up
Avoid Unnecessary Comparisons
Avoid Negations
Return Boolean Expressions Directly
Simplify Boolean Expressions
Avoid NullPointerException in Conditionals
Avoid Switch Fallthrough
Always Use Braces
Ensure Code Symmetry
What Have You Learned?
2. Level Up Your Code Style
Replace Magic Numbers with Constants
Favor Enums Over Integer Constants
Favor For-Each Over For Loops
Avoid Collection Modification During Iteration
Avoid Compute-Intense Operations During Iteration
Group with New Lines
Favor Format Over Concatenation
Favor Java API Over DIY
What Have You Learned?
3. Use Comments Wisely
Remove Superfluous Comments
Remove Commented-Out Code
Replace Comments with Constants
Replace Comments with Utility Methods
Document Implementation Decisions
Document Using Examples
Structure JavaDoc of Packages
Structure JavaDoc of Classes and Interfaces
Structure JavaDoc of Methods
Structure JavaDoc of Constructors
What Have You Learned?
4. Name Things Right
Use Java Naming Conventions
Follow Getter/Setter Conventions for Frameworks
Avoid Single-Letter Names
Avoid Abbreviations
Avoid Meaningless Terms
Use Domain Terminology
What Have You Learned?
5. Prepare for Things Going Wrong
Fail Fast
Always Catch Most Specific Exception
Explain Cause in Message
Avoid Breaking the Cause Chain
Expose Cause in Variable
Always Check Type Before Cast
Always Close Resources
Always Close Multiple Resources
Explain Empty Catch
What Have You Learned?
6. Assert Things Going Right
Structure Tests Into Given-When-Then
Use Meaningful Assertions
Expected Before Actual Value
Use Reasonable Tolerance Values
Let JUnit Handle Exceptions
Describe Your Tests
Favor Standalone Tests
Parametrize Your Tests
Cover the Edge Cases
What Have You Learned?
7. Design Your Objects
Split Method with Boolean Parameters
Split Method with Optional Parameters
Favor Abstract Over Concrete Types
Favor Immutable Over Mutable State
Combine State and Behavior
Avoid Leaking References
Avoid Returning Null
What Have You Learned?
8. Let Your Data Flow
Favor Lambdas Over Anonymous Classes
Favor Functional Over Imperative Style
Favor Method References Over Lambdas
Avoid Side Effects
Use Collect for Terminating Complex Streams
Avoid Exceptions in Streams
Favor Optional Over Null
Avoid Optional Fields or Parameters
Use Optionals as Streams
What Have You Learned?
9. Prepare for the Real World
Use Static Code Analysis Tools
Agree On the Java Format in Your Team
Automate Your Build
Use Continuous Integration
Prepare for and Deliver Into Production
Favor Logging Over Console Output
Minimize and Isolate Multithreaded Code
Use High-Level Concurrency Abstractions
Speed Up Your Program
Know Your Falsehoods
What Have You Learned?
Bibliography
Index
β SYMBOLS β
β A β
β B β
β C β
β D β
β E β
β F β
β G β
β H β
β I β
β J β
β K β
β L β
β M β
β N β
β O β
β P β
β R β
β S β
β T β
β U β
β V β
β W β
π SIMILAR VOLUMES
In Java Examples in a Nutshell, David Flanagan, the bestselling author of Java in a Nutshell, has created an entire book of programs that not only serve as great learning tools, but can also be modified for individual use. The second edition covers Java 1.3, and contains 164 complete, prac
<span><div><p>Write code that's clean, concise, and to the point: code that others will read with pleasure and reuse. Comparing your code to that of expert programmers is a great way to improve your coding skills. Get hands-on advice to level up your coding style through small and understandable exa
Presents practical examples of elegant, readable, & maintainable Java code. Covers the key APIs & enhancements to the JDK 1.2, including new chapters on inner classes, reflection & collection classes. Paper. CD-ROM included
Java is one of the most used software languages by programmers and developers. It powers massive applications from Google to Amazon all over the world.