Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #6493

Re: The greeting code in Java

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!newsfeed.straub-nv.de!feeder.news-service.com!newsfeed101.telia.com!starscream.dk.telia.net!news.tele.dk!feed118.news.tele.dk!dotsrc.org!filter.dotsrc.org!news.dotsrc.org!not-for-mail
Date Sat, 23 Jul 2011 22:15:47 -0400
From Arne Vajhøj <arne@vajhoej.dk>
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:5.0) Gecko/20110624 Thunderbird/5.0
MIME-Version 1.0
Newsgroups comp.lang.java.programmer
Subject Re: The greeting code in Java
References <f61fee62-589e-4ad1-a9ef-a54e2b589e5b@s9g2000yqm.googlegroups.com> <ld8sv6tugbkdq7n1dc0d4ja0o604rr6n5q@4ax.com> <b70ab7d1-fe03-413e-ba87-6819ae24973e@hd10g2000vbb.googlegroups.com>
In-Reply-To <b70ab7d1-fe03-413e-ba87-6819ae24973e@hd10g2000vbb.googlegroups.com>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
Lines 72
Message-ID <4e2b8058$0$316$14726298@news.sunsite.dk> (permalink)
Organization SunSITE.dk - Supporting Open source
NNTP-Posting-Host 72.192.23.157
X-Trace news.sunsite.dk DXC=SC9Z4aIgb=:8NX=BCM0\c1YSB=nbEKnk;XjhVkob8B`6JPe3\kP5EU1KBm9cfh9BS4M2;kT<[:>[1B8=H]I6T1]3TO:f=BK=Lj:
X-Complaints-To staff@sunsite.dk
Xref x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:6493

Show key headers only | View raw


On 6/19/2011 3:15 PM, Saeed Amrollahi wrote:
> On Jun 19, 8:36 pm, rossum<rossu...@coldmail.com>  wrote:
>> On Sun, 19 Jun 2011 06:05:53 -0700 (PDT), Saeed Amrollahi
>> <amrollahi.sa...@gmail.com>  wrote:
>>> I'm a C++ programmer and I started to learn Java. After famous "Hello
>>> World"
>>> program, the obvious code is "Say hello to specific people". Program
>>> asked
>>> user's name, then print a greeting message.

>> Stream readers are more often used for binary input.  For text input
>> people tend to use the java.util.Scanner class.
>>
>>    public static void main(String[] args) {
>>      System.out.print("Please enter your first name: ");
>>      Scanner sc = new Scanner(System.in);
>>      String name = sc.nextLine();
>>      System.out.println("Hello, " + name);
>>    }
>
> What is the Scanner?

Something that scan's - in the same meaning as scanf.

>                         Why we use nextLine?

Some text plus hitting the return key is called a line,
so nextLine describes pretty well what it does.

>                                              What's the relation of
> such concepts with a simple greeting program.
> 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!

It should not be.

Simple use of Scanner should be in one of the first chapters.

If it is not then it can be because the book is old.

Scanner is a late invention.

Before Scanner:

Scanner sc = new Scanner(System.in);
String name = sc.nextLine();

would be done as:

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String name = br.readLine();

But that is not easier.

Also note that the Java API is pretty big.

Java 1.6 has approx. 3000 classes with approx. 100000
methods.

No book can cover everything.

So it is essential that you learn to find things in the
Java API docs.

Arne





Back to comp.lang.java.programmer | Previous | Next | Find similar


Thread

Re: The greeting code in Java Arne Vajhøj <arne@vajhoej.dk> - 2011-07-23 22:15 -0400

csiph-web