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.
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. |