A stream represents flow of data from one place to another place. Input stream reads or accepts data. And output stream sends or writes data to another place.

System.in is an object of InputStreamReader and it represents keyboard by default. System.out and System.err are the objects of PrintStream and they represent monitor by default.

All the Java streams are represented by classes in java.io package. Java streams represent I/O devices. And we can achieve hardware independence with Java streams.

I'm going to explain how streams can be used to accept the input from keyboard. Here are the steps to be followed in order to accept input from keyboard

1. Attach keyboard to InputStreamReader.
InputStreamReader obj = new InputStreamReader(System.in);

2. Attach InputStreamReader to BufferedReader
BufferedReader br = new BufferedReader(obj);

3. Now read data from BufferedReader using read() or readLine() data.

import java.io.InputStreamReader;
import java.io.BufferedReader;

* A demo class to accept input from keyboard.
* @author Santhosh Reddy Mandadi
* @since 23-Feb-2012
* @version 1.0
public class InputDemo
public static void main(String args[]) throws Exception
InputStreamReader reader = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(reader);
System.out.println("Enter name:");
String name = br.readLine();
System.out.println("You've entered "+name);