Casting InputStreamReader as (char)
<p>I'm presently working my way through <em>Java: The Complete Reference 8th Edition</em> by Herbert Schildt. I'm a recent compsci grad and a novice programmer.</p>

<p>In the I/O chapter, the book presents a small piece of sample code (I've included it below). The code creates a BufferedReader that is supplied with InputStreamReader(System.in) as an argument (line 6). I checked the <a href="http://docs.oracle.com/javase/7/docs/api/java/io/InputStreamReader.html" rel="nofollow">Java SE7 docs for InputStreamReader</a> and it says that it "[...]reads bytes and decodes them into characters[...]". My question is, why is it necessary (or is it even necessary) to cast br.read() as a char when assigning it to 'c' in line 9 of the example code?</p>

<p>Thank you very much for any assistance.</p>

<p>Jamie</p>

<pre><code>1.  import java.io.*
2.  
3.  class BRRead {
4.       public static void main(String args[]) throws IOException {
5.            char c;
6.            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
7.            System.out.println("Enter characters, 'q' to quit.");
8.            do {
9.                 c = (char) br.read();
10.                System.out.println(c);
11.           } while(c != 'q');
12.      }
13. }
</code></pre>
