Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail From: Eric Sosman Newsgroups: comp.lang.java.programmer Subject: Re: The greeting code in Java Date: Sun, 19 Jun 2011 16:05:23 -0400 Organization: A noiseless patient Spider Lines: 49 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:06:08 +0000 (UTC) Injection-Info: mx04.eternal-september.org; posting-host="BrOwaJANne849xlH+KPYjQ"; logging-data="30050"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+BT0sDqot/UCep5DVP89aq" User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.17) Gecko/20110414 Thunderbird/3.1.10 In-Reply-To: Cancel-Lock: sha1:1DAIWsz0JWNMbiDETJA87Yo07tE= Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:5403 On 6/19/2011 3: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. The Scanner class and its nextLine method are part of an I/O library that offers more power and flexibility than your program is capable of using. Unfortunately for you, the designers of Java chose not to provide a built-in I/O facility dumbed down to the level you need. You're not using a tenth of the power of Scanner, but that would be a poor reason for Scanner to jettison its other nine-tenths. > 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! Permute the chapter numbers if it makes you happier. For example, you don't need to know how to write constructors, you don't need to understand the `long' type, you don't need to know about nested classes, and so on, and so on. Move chapter 20 ahead of all those, if you like. More seriously, the purpose of a "Hello, world" program is not to teach you the language (whatever language) nor to illustrate its capabilities. It is a throat-clearing exercise intended to test whether the compiler/interpreter/libraries/runtime/licenses/whatnot are set up correctly. "Testing, testing, one, two, three" is not intended to convey a message, but to check that everything from the microphone to the speaker is properly connected and powered on. Do not judge the PA system by the banality of its first message. I imagine you are a C++ practitioner trying to learn Java, but making the mistake of trying to understand Java in C++'s terms. Have you ever hear the phrase "A real programmer can write FORTRAN in any language?" Try not to commit that error, but instead look at Java on its own merits (and its own demerits; Java's not perfect). Bruce Eckel's "Thinking in Java" gets a lukewarm reception (at best) from the experts, and I don't know whether it's been kept up to date as Java has developed and changed. However, it has one virtue I found helpful Back In The Day, and you may find helpful now: True to its title, it really does try to explain Java in Java's own terms, and not by saying "It's just like Lisp except ..." A goodly dose of that mindset might stand you in good stead. -- Eric Sosman esosman@ieee-dot-org.invalid