8Handling Input and Output


  • How input and output differ
  • How to handle interaction with users in your programs
  • How to store and load information in files


The wrox.com code downloads for this chapter are found at www.wrox.com/go/beginningjavaprogramming on the Download Code tab. The code is in the Chapter 8 download and individually named according to the names throughout the chapter.

So far, all the programs you’ve been writing throughout the course of this book have operated more or less on their own, without much interaction with the user at runtime, meaning that the interaction with the program happened while you were coding it, i.e. specifying all the tasks the program should perform. Once it ran, however, the program just went its course.

Interaction in programming is described as “input/output” (I/O). Of course, this communication flows in two directions, one in the form of “output,” which is information the program provides to outside parties, and the other in the form of “input,” which is information users provide to the program or information the program reads in from the outside world. It is easy to imagine a multitude of cases where such functionality could be useful. Imagine a program asking the user’s name, for instance, or a program asking if it should terminate or ignore an error when something unexpected happens. These aspects are all covered in this chapter.

Interaction ...

Get Beginning Java Programming 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.