Hands-on Guide to write Clean Code in Java
About the Book
Nothing affects the work of a team as much as bad, illegible, sloppy, and quickly written code that has not been designed carefully. Team dynamics can be improved, requirements can be redefined, and the schedule can be modified. However, if bad code takes over, it becomes more and more a burden for the team.
Programmers should develop all the time. Even if they think that they have sufficient skills and knowledge to move around in current projects, they should not stop there, and it is worthwhile for them to learn new concepts, approaches, language, and frameworks from time to time. Learning should be a journey and not a destination.
This book discusses the best practices of writing better code. It also contains many code examples in Java of increasing complexity.
This is a Forever Edition. That means that the book will see periodic updates, which are free for you. The book will use the latest Java version for the examples provided.
- What about the code examples and typographic conventions?
- Which literature is this book based on?
- Giving feedback?
1 Java Best Practices
- 1.1 Avoid instantiation for utility classes
- 1.2 Use immutable objects
- 1.3 Prefer records for immutability
- 1.4 Provide immutable decorators for sensitive mutable classes
- 1.5 Consider using sealed classes and interfaces
- 1.6 Avoid constant interfaces
- 1.7 Avoid global constant classes
- 1.8 Favour composition over inheritance
- 1.9 Consider using lambdas
- 1.10 Use meaningful return types
1.11 Use the
1.12 Use the
1.13 Prefer returning Null-Objects over
nullas a method parameter
- 1.15 Prefer enhanced loops over for loops
- 1.16 Code against interfaces not implementations
- 1.17 Use existing exceptions
- 1.18 Validate method parameter
1.20 Safely cast
- 1.21 Convert integers to floating-point for floating-point math operations
- 1.22 Use Generics in favor of raw types
1.23 Prefer enums over
1.24 Prefer the
equalsfor comparing enum values
1.25 Be aware of the contract between
- 1.26 Use text blocks for multi-line strings
- 1.27 Use always braces for the body of all statements
- 1.28 Simplifying boolean expressions
- 1.29 Pre-calculate the length in loops
1.30 Avoid constructor instantiation of
- 1.32 Reduce lookups in collection containers
1.33 Instantiate wrapper objects with
- 1.36 Reduce the number of casts
The Leanpub 60-day 100% Happiness Guarantee
Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.
See full terms
80% Royalties. Earn $16 on a $20 book.
We pay 80% royalties. That's not a typo: you earn $16 on a $20 sale. If we sell 5000 non-refunded copies of your book or course for $20, you'll earn $80,000.
(Yes, some authors have already earned much more than that on Leanpub.)
In fact, authors have earnedover $12 millionwriting, publishing and selling on Leanpub.
Learn more about writing on Leanpub
Free Updates. DRM Free.
If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).
Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.
Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.