Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail From: Joshua Cranmer Newsgroups: comp.lang.java.programmer Subject: Re: The greeting code in Java Date: Sun, 19 Jun 2011 16:00:21 -0400 Organization: A noiseless patient Spider Lines: 27 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Sun, 19 Jun 2011 20:00:21 +0000 (UTC) Injection-Info: mx04.eternal-september.org; posting-host="bAymlyY9SkaJNa8Tz2rerw"; logging-data="25856"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18Lk+cOHalN0GzJMjPHuyWvlcJHwFR9xfc=" User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.16pre) Gecko/20110305 Lightning/1.0b3pre Thunderbird/3.1.10pre In-Reply-To: Cancel-Lock: sha1:MJddPjRfkmUwjY3FUn7Tn9UZhrQ= Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:5402 On 06/19/2011 03:15 PM, Saeed Amrollahi wrote: > What is the Scanner? Why we use nextLine? What's the relation of > such concepts with a simple greeting program. java.util.Scanner is a very useful class for parsing simple textual protocols, that makes retrieval of words, lines, numbers, etc. very simple. In other words, it's very much like istream::operator<< except more explicit in what it is doing (does operator<<(string&) feed me a word or a line?); that Java did not have it until version 5 is a great shame. > Why the code for writing "Hello, world" is in chapter 1, page 1 > of The Java Programming Language, but the code of greeting may be in > Chapter 20! Outputting ASCII is very simple, and "Hello, world" has become (for better or for worse) the standard introduction to programming. True I/O, one that takes into account the harsh vagaries of international text and the heaping mess that is character sets, is actually very difficult and very easy to get wrong. Reading from an input stream is actually logically difficult (what happens if you read from a closed stdin?); Java 1.0 actually got this mildly wrong, which is part of the reason why the APIs for particularly reading Strings is much more circuitous. -- Beware of bugs in the above code; I have only proved it correct, not tried it. -- Donald E. Knuth