14. Recursion

Overview

In this chapter, we will see how using recursion can help you to write effective code. The chapter begins with an initial exercise illustrating one of the simplest mistakes you can make with recursion: forgetting to code a termination condition. The first step, then, is learning how to salvage your program when the Java stack has blown away. From there, you will learn to write recursive methods in order to handle mathematical formulas and other recurrent processing needs. Finally, with these techniques (and those further defined by this chapter), you will practice creating and processing XML files with the Document Object Model (DOM) API.

Introduction

Recursion is where a method calls itself, over and over again. ...

Get The Java Workshop 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.