samedi 11 juin 2016

5 Difference between BufferedReader and Scanner class in Java - Example

Even though both BufferedReader and Scanner can read a file or user input from command prompt in Java, there some significant differences between them. One of the main difference between BufferedReader and Scanner class is that former is meant to just read String while later is meant to both read and parse text data into Java primitive type e.g. int, short, float, double, and long. In other words, BufferedRedaer can only read String but Scanner can read both String and other data types like int, float, long, double, float etc. This functional difference drives several other differences on their usage. Another difference is Scanner is newer than BufferedReader, only introduced in Java 5, while BufferedReader is present in Java from JDK 1.1 version. This means, you have access to BufferedReader in almost all JDK version mainly Java 1.4 but Scanner is only available after Java 5.  This is also a popular core Java questions from interviews. Since many developer lack Java IO skill, questions like this test their knowledge about API and how to do some practical task.
Read more »
Share:

0 commentaires:

Enregistrer un commentaire