3 Program structure
This chapter covers
- Mistakes that happen when using
if
–else
chains - Problems using
while
andfor
loops - How to avoid pitfalls around the initialization of fields and classes
- Missing a call to a superclass method
- What happens if you accidentally declare a static field instead of an instance one
Java provides a number of constructions to alter the program control flow. These include branching statements (switch
and if
–else
), loop statements (for
and while
), and so on. It is common for beginners to make mistakes in control flow statements, and it is a useful skill to be able to identify them. Such mistakes may result in visiting the wrong branch, having more loop iterations than expected, and other undesirable outcomes. ...
Get 100 Java Mistakes and How to Avoid Them now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.