What exactly is Scanner??
Fundamentally misunderstanding Java Scanner class.
A small rant regarding the Scanner class...
Why do we need Scanner class in order to input something?
Q1. What is the Scanner class in Java?
Q2. What type of class is the Scanner class?
Q3. How to write a Scanner class?
Videos
package project72;
import java.util.*;
import java.util.Scanner;
public class test1{
public static void main(String args[]){
Scanner input=new Scanner(System.in);
}
}is Scanner a Class?? (I'm assuming of course it is)
is Scanner a Class in this particular code below? if not what is it ? and what role is Scanner playing inside this code also what is System.in here??
why is it inside parenthesis and what is it doing ??
Hello! My wife is taking a beginner programming class in Java, and she's having trouble with Files and Scanners. In my quest to help her understand it, I realized that I don't really understand it myself.
For example: It seems the consensus is that each program only requires a single Scanner object. But if that's the case, how do you handle when a program needs to take input from multiple sources? Say a program needs to take a user prompt in the console, but you'd also like to use the Scanner class on a File object to easily loop through the file and use methods like nextLine(). How would you handle that with only a single Scanner?
Secondly, what actually does the close() method of Scanner do? My wife seems to think that using a line like Scanner inputFile = new Scanner(f) "opens" the file, and close "closes" the file, and we use close because it's the responsible thing to do. But the opening and closing a file makes sense on an OS to me- you're opening it in a program, starting a new task, and when you close it, you end that task. Is the file actually being "opened" somewhere? I'm guessing not. And if not, what does "closing" it actually mean? (I googled that for a while and could not fine a decent answer. The documentation just says "it closes the Scanner"). And you can close system. in , so how does that relate to all of this? Can Scanners be "re-opened"? Is that even useful, or should you just be closing Scanners (particularly, Scanners with files) and the end of each program?
And lastly, what's even the purpose of the Scanner class at all? Why do we need a class at all to get input? Does Java not have a Console.ReadLine() equivalent that we can just set to a String variable?
Sorry, I know it's a lot of questions, but I just like to understand these things as much as I can so I don't spread misinformation or use a bad analogy. Thanks for any help in advance.