Using System.out


The most frequent use of System.out is to post messages to the console in an effort to locate defects in a program. You insert System.out.println statements to display useful information at judicious points in your code. When you execute the application, the output from these trace statements can help you understand the flow of messages and data through the objects interacting in the system.

Debuggers are far more sophisticated tools that accomplish the same goal and much more, but simple trace statements can occasionally be a more rapid and effective solution. Also, in some environments it is not feasible to use a debugger.

Regardless, you should find minimal need to debug your code, or even insert trace statements into it, if you do TDD properly. If you do the small steps that TDD prescribes, you will introduce very small amounts of code into your application before finding out you have a problem. Instead, the better solution is to discard the small amount of newly introduced code and start again, using even smaller verified steps.

Build your system in small increments of test and code. Discard an increment and start over with smaller steps if you have a problem.


Most developers do not write console-based applications, although you are probably familiar with many of them. The compiler javac itself is a console-based application. Simple server applications are often coded as console applications so that developers can easily monitor their output.



Agile Java. Crafting Code with Test-Driven Development
Agile Javaв„ў: Crafting Code with Test-Driven Development
ISBN: 0131482394
EAN: 2147483647
Year: 2003
Pages: 391
Authors: Jeff Langr

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net