Java - Interview Questions and Answers for 'Scanner' | Search Java Interview Question - javasearch.buggybread.com
Javasearch.buggybread.com
Share

Search Java Interview Questions


 2137 questions in repository.
 There are more than 200 unanswered questions.
Click here and help us by providing the answer.
Label / Company      Label / Company / Text

   



Interview Questions and Answers for 'Scanner' - 5 question(s) found - Order By Newest

 Q1. What is Scanner class used for ? when was it introduced in Java ?Core Java
Admin
info@buggybread.com
Ans. Scanner class introduced in Java 1.5 for reading Data Stream from the imput device. Previously we used to write code to read a input using DataInputStream. After reading the stream , we can convert into respective data type using in.next() as String ,in.nextInt() as integer, in.nextDouble() as Double etc

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   java5   scanner   file io   file input   data input stream  file handling      basic


 Q2. Write code explaining use of Scanner class ?
Admin
info@buggybread.com
Ans. Scanner sc = new Scanner(System.in);
int i = sc.nextInt();

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   scanner   io   console io   scanner   System.in


 Q3. Difference between Scanner and BufferedReader ? Which one is faster and Why ?Core Java
Admin
info@buggybread.com
Ans. Scanner is used for parsing tokens from the contents of the stream while BufferedReader just reads the stream.

BufferedReader read files efficiently by using a buffer to avoid physical disk operations.

Buffer size of Scanner is usually smaller than the Buffered Writer.

BufferedReader is faster that Scanner as it just reads the Stream and doesn't Parse the tokens to read the stream into primitive data types.

  Sample Code for Scanner

  Sample Code for BufferedReader

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   file io   input output   scanner   bufferedreader  file handling


 Q4. Write a program / method to input few numbers and then print the sum.

Ans. http://javasearch.buggybread.com/CodeSnippets/searchCodeSamples.php?&category=code&searchOption&keyword=946

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     code  coding  scanner      basic


 Q5. What is the difference between hasNextInt and nextInt method of scanner class ?Core Java2017-07-23 18:29:51

Ans. The hasNextInt() is used to check if there are any more elements left and the nextInt() is used to access that element.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     input output  Scanner




Subscribe to Java News and Posts. Get latest updates and posts on Java from Buggybread.com
Enter your email address:
Delivered by FeedBurner



comments powered by Disqus
 

Help us and Others Improve. Please let us know the questions asked in any of your previous interview.

Any input from you will be highly appreciated and It will unlock the application for 10 more requests.

Company Name:
Questions Asked:
         

X Close this

X Close this

Help Us Improve.
Please share your
interview experience.

Company Name:   


Questions Asked: