Writing of sole Output 

Console output is most easily accomplished with print( ) and print in( ), described earlier, which are used in most of the examples in this book. These methods are defined by the class Print Stream (which is the type of the object referenced by System.out). Even though System,out is a byte stream, using It for simple program output is still acceptable. However, a character-based alternative is described in the next section. Because Print Stream is an output stream derived from Output Stream, it also implements the low-level method write(). Thus, write () can be used to write to the console. The simplest form of write( ) defined by Print Stream’is shown here: This method writes to the file the.byte specified by by/evil!. Although by teal is declared as an integer, only the low-order eight bits are written. Here is a short example that . uses write( ) to output the character” A” followed by a newline to the screen:

You will not often use write () to perform console output (although doing so might be useful in some situations), because print ) and print inf ) are substantially easier to use..

[vfb id=1]

Share This