title: How does java.io.InputStream.read() work?
body: <p>Why does this :</p>
  
  <pre><code>import java.io.*;
  
  class ioTest2 {
    public static void main(String args[])throws IOException{
        int b;
        while( (b = System.in.read() ) != -1)
            System.out.print((char)b);
    }
  }
  </code></pre>
  
  <p>work as expected,i.e print exactly what you type, and this:</p>
  
  <pre><code>import java.io.*;
  
  class ioTest2 {
    public static void main(String args[])throws IOException{
      int b;
      while( (b = System.in.read() ) != -1)
          System.out.print(b);
    }
  }  
  </code></pre>
  
  <p>does not? Why do I have cast <code>b</code> to a character to make the code correct? </p>