In JAVA when you import the Scanner class and create a Scanner object, how does the underlying logic work to capture the input and write it onto memory? I understand that the following statement
Scanner sc = new Scanner (System.in)
means you are creating a new Scanner
class object called sc
which will inherit the attributes and methods of the Scanner class to be used in a certain way. But I would like to know what does the System.in
argument do?
When the compiler goes through the class instantiation step, it would first create a class constructor which takes in System.in
as an argument which is an object of the InputStream
class. Which means that when you call a nextInt()
or nextln()
method of the Scanner class, what you are essentially doing is sending that input into that method which would perform some syntactic check on it and then pass it onto the InputStream class which would turn it into bytes which can then be written onto the memory.
Is that how it works? or am I totally off the rails with this?