Home Page Icon
Home Page
Table of Contents for
Title Page
Close
Title Page
by Jörg Lenhard, Linus Dietz, Simon Harrer
Java By Comparison
 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
Search in book...
Toggle Font Controls
Playlists
Add To
Create new playlist
Name your new playlist
Playlist description (optional)
Cancel
Create playlist
Sign In
Email address
Password
Forgot Password?
Create account
Login
or
Continue with Facebook
Continue with Google
Sign Up
Full Name
Email address
Confirm Email Address
Password
Login
Create account
or
Continue with Facebook
Continue with Google
Next
Next Chapter
Java by Comparison
Add Highlight
No Comment
..................Content has been hidden....................
You can't read the all page of ebook, please click
here
login for view all page.
Day Mode
Cloud Mode
Night Mode
Reset