This discussion is archived
7 Replies Latest reply: Oct 5, 2006 11:36 AM by 807598 RSS

OT: BufferedReader vs. Scanner General Question.

807598 Newbie
Currently Being Moderated
Hi everyone.

First let me say I have not googled or searched the forums for this type of question. I am most interested with answers from those of you working in the field.

I have been posting, and hopefully helping users, since March or so and I see many posts using the Scanner class. Most questions seem come from very green people.
When I was first learning Java syntax, we were taught to use a BufferedReader to get entire lines of text either from a text file, URL, or the console and then we would parse / manipulate the string to get the desired token(s).
So, I am wondering why the sudden influx of using the Scanner class to get input directly from the user? To me, it makes more sense to grab the entire line in one shot then parse it behind the scenes, even using the Scanner class to do it.

Also What is the current industry 'best practices' for getting input? I realize most input will come from non console input streams like files, sockets, and URL's.

BTW, this is my second question post ever. for what its worth...

Thanks,

JJ
  • 1. Re: OT: BufferedReader vs. Scanner General Question.
    800351 Newbie
    Currently Being Moderated
    According to uncle_alice,
    http://forum.java.sun.com/thread.jspa?threadID=767911&start=0&tstart=0
    The Scanner should not be used for simple input for beginner's programs.
  • 2. Re: OT: BufferedReader vs. Scanner General Question.
    807598 Newbie
    Currently Being Moderated
    I agree totally. It just seems that i have seen many examples where a student has to get a series of numerical and textural data from the user, and the usually end up with a nice large block of sc,nextInt() and or sc.next(). All it takes is one fat fingered entry and the program bombs.

    I have a feeling that some of the instructors think because the Scanner class is new to 1.5, it must be a better method to get user input. Just a thought.

    JJ
  • 3. Re: OT: BufferedReader vs. Scanner General Question.
    807598 Newbie
    Currently Being Moderated
    Speaking as someone who knows next nothing about programming.....
    I just looked in the index in my textbook, first semester CS, the only mention
    of BR is a plain jane methods list in appendix E. As a new student the only
    way I know it exits at all is from participating on this forum, some self study and
    my prof's media from last year. From my very limited experience,
    when I've tried to make sense of an assignment using this class, or extend
    it so it seems like it may work in the real world, I have run into trouble.

    That is it outa me
    I'm really looking forward to where this thread may go

    Message was edited by:
    ThatJive
  • 4. Re: OT: BufferedReader vs. Scanner General Question.
    807598 Newbie
    Currently Being Moderated
    The sudden influx of people using Scanner is because (1) it's a new class, and (2) school just started.

    Scanner seems like such a simple, but Swiss-Army-Knife kind of tokenizer (it does all sorts of things, without regard to any particular context) that it seems like it was introduced specifically for newbies or for people who want to write some quick-and-dirty code. I would think that if you were doing any really advanced stuff you'd write a specialized parser or use whatever the java equivalent of lex is.
  • 5. Re: OT: BufferedReader vs. Scanner General Question.
    807598 Newbie
    Currently Being Moderated
    I have a feeling that some of the instructors think
    because the Scanner class is new to 1.5, it must be a
    better method to get user input. Just a thought.
    I think it's the other way 'round: Java has always lacked an obvious way to get user input, which has made instructors' jobs more difficult than it needed to be. Now that the Scanner has finally been introduced, they're all over it. But Scanner uses regexes under the hood, and makes them available through its own API, so n00b's are being exposed to them practically in their first week ("Hello world! WTF's a regex?"). And I doubt most of their instructors are up to speed on regexes, so I don't expect this first exposure is usually a positive experience.

    BTW, in that other thread, the problem was that the OP was using the Scanner for just about the opposite of simple user input. I was saying that Scanner, being the wrong tool for the job, was actually making his job more difficult. (Thanks for reminding me, though; Friedl's site is up to date now.)
  • 6. Re: OT: BufferedReader vs. Scanner General Question.
    796254 Newbie
    Currently Being Moderated
    javacc is a 100% java lex/yacc tool. I think Antlr is another.

    %
  • 7. Re: OT: BufferedReader vs. Scanner General Question.
    807598 Newbie
    Currently Being Moderated
    Thanks for all the feedback !

    ;-)