Scanner or BufferedReader ?

View Poll Results: Scanner or BufferedReader?
Scanner 3 33.33%
BufferedReader 6 66.67%
Voters: 9. You may not vote on this poll

Thread Solved

Join Date: Dec 2007
Posts: 1,648
Reputation: javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all 
Solved Threads: 223
Featured Poster
javaAddict's Avatar
javaAddict javaAddict is offline Offline
Posting Virtuoso

Scanner or BufferedReader ?

 
0
  #1
Jan 22nd, 2009
This is not much of a question, but a discussion and searching for opinions. I have seen that many use the Scanner class for getting input from the keyboard. Some, like myself, use the BufferedReader.

Why will someone use one over the other?

Or they both do the same thing when it comes something simple as that and their real difference is when it comes to using them for something more complex?
Check out my New Bike at my Public Profile at the "About Me" tab
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 895
Reputation: Paul Thompson has a spectacular aura about Paul Thompson has a spectacular aura about 
Solved Threads: 143
Sponsor
Paul Thompson's Avatar
Paul Thompson Paul Thompson is offline Offline
previously paulthom12345

Re: Scanner or BufferedReader ?

 
0
  #2
Jan 22nd, 2009
Well im voting for the scanner. Thats how i learnt and thats how i go, i dont find anything wrong with it so i stay that way.. addmitedly i really dont know a thing about Buffered Reader anyway, so it could be loads better for all i know.
Make it idiot proof and someone will make a better idiot.
Check out my Site | and join us on IRC | Python Specific IRC
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 34
Reputation: jrdark13 is an unknown quantity at this point 
Solved Threads: 3
jrdark13 jrdark13 is offline Offline
Light Poster

Re: Scanner or BufferedReader ?

 
0
  #3
Jan 22nd, 2009
Originally Posted by paulthom12345 View Post
Well im voting for the scanner. Thats how i learnt and thats how i go, i dont find anything wrong with it so i stay that way.. addmitedly i really dont know a thing about Buffered Reader anyway, so it could be loads better for all i know.
Ditto... If i ever begin to study BufferedReader I'll discuss it further. What are the differences anyway? Any one that is advanced plz reply?
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,438
Reputation: Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of 
Solved Threads: 509
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: Scanner or BufferedReader ?

 
0
  #4
Jan 22nd, 2009
Neither one. I don't write console applications.
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 4,185
Reputation: peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of 
Solved Threads: 481
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is online now Online
Code tags enforcer

Re: Scanner or BufferedReader ?

 
0
  #5
Jan 22nd, 2009
Ehmmm where do I find this in Java Microedition?

Neither me. For now I work in JME, Swing or Web Development so no.
Last edited by peter_budo; Jan 22nd, 2009 at 3:57 pm.
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 21
Reputation: chili5 is an unknown quantity at this point 
Solved Threads: 2
chili5's Avatar
chili5 chili5 is offline Offline
Newbie Poster

Re: Scanner or BufferedReader ?

 
0
  #6
Jan 22nd, 2009
I used to use the buffered reader in September but I started to find when in my contests that the Scanner is better.

Since I can read individual elements at a time, I don't have to worry about splitting and parsing into integers.

Say my input file is:

4 4
*...
....
.*..
With the buffered reader, I would have to read things in line at a time, split it up and parse it into integers. Thus the buffered reader seems to make input a lot tougher.

Buffered reader:

  1. BufferedReader br = new BufferedReader(new FileReader("DATA1.txt"));
  2. String[] arsNums = br.readLine().split(" ");
  3. int nX = Integer.parseInt(arsNums[0]);
  4. int nY = Integer.parseInt(arsNums[1]);

With the scanner I don't have to read in each line as a string and parse it with the Integer class.

Scanner:

  1. Scanner sin = new Scanner(new FileReader("DATA1.txt"));
  2. int nX = sin.nextInt();
  3. int nY = sin.nextInt();
  4. char[][] arcGrid = new char[nX][nY];
  5. String sLine = "";
  6.  
  7. for (int x=0;x<nX;x++) {
  8. sLine = sin.next();
  9. for (int y=0;y<nY;y++) {
  10. arcGrid[x][y] = sLine.charAt(y);
  11. }
  12. }

Also I can have Scanner that parses each individual element in a String. So the Scanner class is quite helpful - and in my opinion a lot better than the buffered reader.

  1. String sText = "Four men went down to the store, to catch frogs!";
  2. Scanner sin = new Scanner(sText);
  3. while (sin.hasNext()) {
  4. System.out.println(sin.next());
  5. }

Prints:

Four
men
went
down
to the
store,
to
catch
frogs!
So that is why I believe the Scanner class is better than the Buffered Reader.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 1,648
Reputation: javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all 
Solved Threads: 223
Featured Poster
javaAddict's Avatar
javaAddict javaAddict is offline Offline
Posting Virtuoso

Re: Scanner or BufferedReader ?

 
0
  #7
Jan 23rd, 2009
Originally Posted by Ezzaral View Post
Neither one. I don't write console applications.
I don't write console applications either but when I first begun I knew from my book only the BufferedReader. So since we've seen many students here asking how to read files and input from the console I thought to get other opinions and discuss the topic.

There has to be some reason why someone would choose to use one over the other
Check out my New Bike at my Public Profile at the "About Me" tab
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 91
Reputation: ezkonekgal is an unknown quantity at this point 
Solved Threads: 1
ezkonekgal ezkonekgal is offline Offline
Junior Poster in Training

Re: Scanner or BufferedReader ?

 
0
  #8
Jan 23rd, 2009
I guess it's just the matter of what you like, and on which is a lot easier. I have learn buffered reader. My prof. didn't teach us scanner. I heard about it from others that it is much easier to use, but i don't know. My prof. doesn't allow us to use scanner. I don't know why.
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 1,175
Reputation: stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light 
Solved Threads: 125
Featured Poster
stephen84s's Avatar
stephen84s stephen84s is offline Offline
Veteran Poster

Re: Scanner or BufferedReader ?

 
0
  #9
Jan 23rd, 2009
Originally Posted by javaAddict View Post
I don't write console applications either but when I first begun I knew from my book only the BufferedReader.

That was most probably because when we learnt Java, java.util.Scanner did not exist.
I started learning Java from the 1.4.2 version of the JDK, and Scanner was introduced only in the 1.5 version and since console input is not so widely used by many of us, we opted to stick with good ol' BufferedReader.
Last edited by stephen84s; Jan 23rd, 2009 at 7:13 am.
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand."

"How to ask questions the smart way ?"
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 1,648
Reputation: javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all 
Solved Threads: 223
Featured Poster
javaAddict's Avatar
javaAddict javaAddict is offline Offline
Posting Virtuoso

Re: Scanner or BufferedReader ?

 
0
  #10
Jan 23rd, 2009
Originally Posted by stephen84s View Post
That was most probably because when we learnt Java, java.util.Scanner did not exist.
I started learning Java from the 1.4.2 version of the JDK, and Scanner was introduced only in the 1.5 version and since console input is not so widely used by many of us, we opted to stick with good ol' BufferedReader.
Well the book I had was called Java 1.2. I don't remember what kind of java I had because I didn't know about versions but I believe I had Java Version 1.2
Check out my New Bike at my Public Profile at the "About Me" tab
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC