Search Interview Questions | More than 3000 questions in repository. There are more than 900 unanswered questions. Click here and help us by providing the answer. Have a video suggestion. Click Correct / Improve and please let us know. |
|
| ||||
Core Java - Interview Questions and Answers for 'Scanner' - 6 question(s) found - Order By Newest | ||||
| ||||
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 | ||||
| ||||
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 | ||||
| ||||
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 | ||||
| ||||
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 | ||||
| ||||
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 | ||||
| ||||
Ans. For releasing input stream reference (System.in), you should close scanner. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  scanner  input output  io | ||||