100 Java Mistakes and How to Avoid Them (MEAP v1)

This document was uploaded by one of our users. The uploader already confirmed that they had the permission to publish it. If you are author/publisher or own the copyright of this documents, please report to us by using this DMCA report form.

Simply click on the Download Book button.

Yes, Book downloads on Ebookily are 100% Free.

Sometimes the book is free on Amazon As well, so go ahead and hit "Search on Amazon"

Dodge the common mistakes that even senior developers make, take full advantage of static analysis tools, and deliver robust and error-free Java code. Inside 100 Java Mistakes and How To Avoid Them you will learn how to: Write better Java programs Recognize common mistakes during programming Create fewer bugs and save time for debugging and testing Get help from static analyzers during programming Configure static analysis tools to reduce amount of false reports Extend static analysis tools with custom plugins Whenever you make a mistake writing Java, it’s almost guaranteed that someone else has made it before! In 100 Java Mistakes and How To Avoid Them you’ll learn about the common and the not-so-common antipatterns, errors, and tricky bits that trip up almost every Java developer. Discover the bugs that are hiding in your Java code, and explore useful and effective ways to dodge them—from unit tests and defensive coding to static analysis tools like IntelliJ IDEA, SonarLint, and Error Prone. about the technology Minor bugs you might not notice when writing code can quickly spin out of control in production, costing you time and money to fix. The solution is clear: spot the mistakes before you make them! This one-of-a-kind guide makes it just that easy. It shines a spotlight on the errors most often made by Java developers, so you can consistently deliver exceptional Java code.

Author(s): Tagir Valeev
Publisher: Manning Publications
Year: 2023

Language: English
Pages: 118

100 Java Mistakes and How to Avoid Them MEAP V01
Copyright
Welcome
Brief contents
Chapter 1: Introduction
1.1 The structure of this book
1.2 Code review and pair programming
1.3 Code style
1.4 Static analysis
1.4.1 Static analysis tools for Java
1.4.2 Using static analyzers
1.4.3 Limitations of static analysis
1.4.4 Suppressing unwanted warnings
1.5 Annotation packages
1.6 Dynamic analysis
1.7 Automated testing
1.8 Mutation coverage
1.9 Code assertions
1.10 Summary
Chapter 2: Expressions
2.1 Mistake #1. Wrong precedence in arithmetic expressions
2.1.1 Bitwise operators
2.1.2 Binary shift
2.2 Mistake #2. Lack of parentheses in conditions
2.2.1 && and || precedence
2.2.2 Conditional operator and addition
2.2.3 Conditional operator and null check
2.2.4 Initial capacity
2.2.5 Conditional operator returning a boolean value
2.3 Mistake #3. Accidental concatenation instead of addition
2.4 Mistake #4. Multiline string literals
2.5 Mistake #5. Unary plus
2.6 Mistake #6. Implicit type conversion in conditional expression
2.6.1 Boxed numbers in conditional expressions
2.6.2 Nested conditional expressions
2.7 Mistake #7. Using non-short-circuit logic operators
2.8 Mistake #8. Mixing && and ||
2.9 Mistake #9. Incorrect use of variable arity calls
2.9.1 Ambiguous variable arity calls
2.9.2 Mixing array and collection
2.10 Mistake #10. Conditional operators and variable arity calls
2.11 Mistake #11. Ignoring the method result value
2.12 Mistake #12. Not using newly created object
2.13 Mistake #13. Binding a method reference to the wrong method
2.14 Mistake #14. Using the wrong method in a method reference
2.15 Summary
Chapter 3: Program structure
3.1 Mistake #15. Malformed if-else chain
3.2 Mistake #16. Condition dominated by a previous condition
3.3 Mistake #17. Accidental pass-through in switch statement
3.4 Mistake #18. Malformed classic for loop
3.5 Mistake #19. Not using the loop variable
3.6 Mistake #20. Wrong loop direction
3.7 Mistake #20. Loop overflow
3.8 Mistake #21. Idempotent loop body
3.9 Mistake #22. Incorrect initialization order
3.9.1 Static fields
3.9.2 Subclass fields
3.9.3 Class initialization order
3.10 Mistake #23. Missing super method call
3.11 Mistake #24. Accidental static field declaration
3.12 Summary
Chapter 4: Numbers
4.1 Mistake #25. Accidental use of octal literal
4.2 Mistake #26. Numeric overflow
4.2.1 Overflow in Java
4.2.2 Assigning the result of int multiplication to a long variable
4.2.3 File size and financial computations
4.3 Mistake #27. Rounding during integer division
4.4 Mistake #28. Absolute value of Integer.MIN_VALUE
4.5 Mistake #29. Oddness check and negative numbers
4.6 Mistake #30. Widening with precision loss
4.7 Mistake #31. Unconditional narrowing
4.8 Mistake #32. Negative hexadecimal values
4.9 Mistake #33. Implicit type conversion in compound assignments
4.10 Mistake #34. Division and compound assignment
4.11 Mistake #35. Using the short type
4.12 Mistake #36. Manually writing bit-manipulating algorithms
4.13 Mistake #37. Forgetting about negative byte values
4.14 Mistake #38. Incorrect clamping order
4.15 Mistake #39. Ignoring the difference between +0.0 and −0.0
4.16 Mistake #40. Forgetting to handle the NaN value
4.17 Summary