Sunday, 26 January 2014

Writing Console Output in java

how to work writing console output

Writing Console Output

Console output is most easily accomplished with print( ) and println( ). These methods are defined by the class PrintStream (which is the type of object referenced by System.out). Even though System.out is a byte stream, using it for simple program output is still acceptable.Because PrintStream is an output stream derived from OutputStream, it also implements the low-level method write( ). Thus, write( ) can be used to write to the console.

General form of writing console output

void write(int byteval)

This method writes to the stream the byte specified by byteval. Although byteval is declared as an integer, only the low-order eight bits are written.

Example for writing console output

// Demonstrate System.out.write().
class WriteDemo
public static void main(String args[])
int b;
b = 'A';

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

No comments :

Post a Comment