Please explain me the difference between scanner and the buffer reader

0 votes
Hi, I have a doubt why buffer reader is safer to take user input in java?

Can you explain that to me?

Thank you,
Aug 2, 2019 in Java by Bipasa
3,426 views

2 answers to this question.

0 votes
  1. BufferedReader is synchronous while Scanner is not. 
  2. BufferedReader should be used if we are working with multiple threads.
  3. BufferedReader has significantly larger buffer memory than Scanner.
  4. The Scanner has a little buffer as opposed to the BufferedReader, but it’s more than enough.
  5. BufferedReader is a bit faster as compared to scanner because the scanner does parsing of input data and BufferedReader simply reads a sequence of characters.
I hope this will help you to understand the difference,
Thank you
answered Aug 2, 2019 by sampriti
• 1,120 points
0 votes

As per your question for reading a text file you should use BufferedReader because Scanner hides IOException while BufferedReader throws it immediately.

BufferedReader is synchronized and Scanner is not.

Scanner is used for parsing tokens from the contents of the stream.

BufferedReader just reads the stream.

answered Aug 27, 2019 by Sirajul
• 59,230 points

Related Questions In Java

+1 vote
1 answer

Can you please explain the difference between string, string buffer and string builder?

String are immutable where as StringBuffer and ...READ MORE

answered Jul 5, 2019 in Java by Akash
• 160 points
1,055 views
0 votes
1 answer

Can you explain what is the difference between hashtable and hashmap?

Hi, Hashtable is synchronized, whereas HashMap is not. This makes HashMap better for ...READ MORE

answered Aug 15, 2019 in Java by anonymous
560 views
0 votes
2 answers

What is the difference between implements and extends?

Extends : This is used to get attributes ...READ MORE

answered Aug 3, 2018 in Java by samarth295
• 2,220 points
15,277 views
0 votes
1 answer

What is the difference between jdk and jre?

JRE: It stands for Java Runtime Environment. ...READ MORE

answered Apr 20, 2018 in Java by Akrati
• 3,190 points
1,687 views
+1 vote
1 answer

Are arrays equivalent to objects in Java ?

Yes; the Java Language Specification writes: In the Java ...READ MORE

answered May 10, 2018 in Java by Rishabh
• 3,620 points
1,028 views
+1 vote
1 answer

Remove objects from an array in Java?

We can use external libraries: org.apache.commons.lang.ArrayUtils.remove(java.lang.Object[] array, int ...READ MORE

answered Jun 26, 2018 in Java by scarlett
• 1,290 points
976 views
+1 vote
1 answer

Performance difference of if/else vs switch statement in Java

The thing you are worried about is ...READ MORE

answered Jul 26, 2018 in Java by geek.erkami
• 2,680 points
3,365 views
+1 vote
3 answers

What is the syntax to declare and initialize an array in java?

You can use this method: String[] strs = ...READ MORE

answered Jul 25, 2018 in Java by samarth295
• 2,220 points
3,174 views
0 votes
2 answers

What is the difference between Map and HashMap in java?

The basic difference is : Map is ...READ MORE

answered Aug 28, 2019 in Java by Sirajul
• 59,230 points
29,031 views
+2 votes
2 answers

Can you give me the proper difference between java.util.Date vs java.sql.Date ?

As per Javadoc java.sql.Date is a thin wrapper around millisecond ...READ MORE

answered Aug 2, 2019 in Java by sampriti
• 1,120 points
14,746 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP