• Post Reply Bookmark Topic Watch Topic
  • New Topic

Tehnical differences between Scanner and BufferedR??  RSS feed

 
Ustaad Desraj
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is there any Technical Differences between Scanner and BufferedReader?
which is better to use and why?
please tell i m not getting any both are taking my inputs
 
Campbell Ritchie
Marshal
Posts: 56593
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To the Batmobile Java™ Tutorials! And look at the API documentation for both classes.

I don't know why you are not getting your input.
 
Ustaad Desraj
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
o Sir, why people always give long long tutorial,
can't you give answer from your knowledge in lay man language for a laymann guy?

if i have to read all this and extract out differences why i put question?

Sir you people can explain it in a good language, and more understandable form like you guys did in previous posts.

pease, just give me major differences...thanks
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ustaad Desraj wrote:o Sir, why people always give long long tutorial,
can't you give answer from your knowledge in lay man language for a laymann guy?

if i have to read all this and extract out differences why i put question?

Sir you people can explain it in a good language, and more understandable form like you guys did in previous posts.

pease, just give me major differences...thanks


To be blunt, this resource won't always be that useful, for really complicated questions. If you only intend to take one computer class, and don't care to take more advanced ones. And probably don't care to become a programmer, you are probably right. Just get the question answered. Remember it for the test. And you are done.

If, however, you want to build on top of this knowledge, with more advanced courses, with the goal of becoming a professional programmer, then you need to learn the material. And in this case, if you actually intend to use those classes, then CR pointed you in the right direction.

Henry
 
Jan-Henrik Clausen
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have read the said tutorial and only understood the half of it (and that is already kind of boasting). As far as I understood the API documentation the BufferedReader's purpose is to provide a buffer for reading operations, accelerating your program a bit if it reads a lot from time-costly spaces (like disk drives). It cannot read itself (not from a source you want it to read from, anyway). You cannot use (only) a BufferedReader to read out the content of a file, for example. You combine it usually with an object of a class which CAN read something useful, like a file reader. It is like an afterburner for a car engine, or so I imagine it.

The Scanner's purpose - on the other hand - seems to be created for reading text from anywhere (files, console, younameit). It has not a buffering capacity as far as I know (I didn't find any hints in the documentation). And it is not something you can use a BufferedReader on, because a Scanner is not a Reader, but only an Object (inheritance-wise speaking). Being in the package java.util it has a basic smell on it.

I hope this helps - and what I really hope is that somebody more wise would give remarks correcting me and hinting at the proper use of these two classes. The tutorial at the oracle website is not that helpful for the unexperienced ones...
 
Campbell Ritchie
Marshal
Posts: 56593
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As far as I remember, Scanner does its own buffering internally, and "consumes" Exceptions, so it is much easier to use. It also will read a particular type of data, using the nextXXX() methods.
It does have a peculiarity that the readLine() method may return an empty line after a readXXX() call. I wrote about that here, last year.
You can also use the hasNextXXX() methods to avoid Exceptions when input is entered in the wrong format. Again you need a next() or nextLine() call to get rid of the old input before trying the new input.
Note that Scanner is described as a "simple text scanner". That doesn't mean it is simple, but that it scans simple text only. It is actually a very sophisticated application, which can use regular expressions to split its input. But it only works on text. The opposite of Scanner is Formatter.

I don't understand what you mean about java.util and a "basic smell".

BufferedReader is a sort of final common pathway for different inputs; it buffers input from different sources, returning it in reproducible formats.
 
Ustaad Desraj
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Clausen and Campbell for cool answer. I am writing your given points again
So what i got out of it:

1) BufferedReader -

Clausen Said:

a) It's purpose is to provide a buffer for reading operations, accelerating your program if it reads a lot from time-costly spaces (like disk drives).

b) It cannot read itself (not from a source you want it to read from, anyway).

c) You cannot use (only) a BufferedReader to read out the content of a file, for example. You combine it usually with an object of a class which CAN read something useful, like a file reader. It is like an afterburner for a car engine

Cambell also Added:

BufferedReader is a sort of final common pathway for different inputs; it buffers input from different sources, returning it in reproducible formats.



2) Scanner -

Clausen Described:

a) The Scanner's purpose seems to be created for reading text from anywhere (files, console, younameit).

b) It has not a buffering capacity and it is not something you can use a BufferedReader on, because a Scanner is not a Reader, but only an Object(inheritance-wise). Being in the package java.util it has a basic smell on it.

Cambell also Added:

:: Campbell Ritchie Cuts this point and said::
i) Scanner does its own buffering internally, and "consumes" Exceptions, so it is much easier to use.
ii) It also will read a particular type of data, using the next() methods.

c) It does have a peculiarity that the readLine() method may return an empty line after a read() call.

d) You can also use the hasNext() methods to avoid Exceptions when input is entered in the wrong format.
Again you need a next() or nextLine() call to get rid of the old input before trying the new input.

e) Note that Scanner is described as a "simple text scanner". That doesn't mean it is simple , but that it scans simple text only. It is actually a very sophisticated application, which can use regular expressions to split its input. But it only works on text.

* Thanks for this point: The opposite of Scanner is Formatter.
 
Ustaad Desraj
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if anyone have mroe too add kindly add plese
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!