What's an accurate explanation of what is really happening when you use the Java scanner class to receive user input? -


i need know if understand semantics of simple java statement. , not one. have googled question , lots of people have been asking gives same answer or gives regurgitated information official documentation. know how use it. want know how works. why.

i know (and others who've asked this) how use scanner class. know how accept user input , store input in variable. feel should not go further till know sure understand why works , how works. involves instantiation, classes, objects, etc. huge part of language. language.

what tell think going on in code , have tell me if accurate or not. ok, here go.

scanner keyboard; keyboard = new scanner(system.in); string userinput = keyboard.next(); 

what happening here?

we want receive user input keyboard decide use scanner class achieve this.

1.) the first thing declare our variable. name keyboard in declaration. (is variable keyboard "type scanner"? variable type here? scanner, object, class, etc. it's not primitive.)

2.) now use java keyword , operator **new instantiate (create) object based off scanner. assign object keyboard variable declared.**

3.) we pass in system.in data source in case keyboard.

4.) now want receive user's input keyboard declare new variable named userinput. , invoke next() method on newly instantiated keyboard object , assign value new variable userinput (is call constructor? part call constructor?)

i've asked few different questions here , if gets downvoted hell, please in least me answers. grateful. have no idea. thank all.

look @ comments. clear enough.

// declare variable of type `scanner` scanner keyboard;   // call constructor of class `scanner` , pass `systen.in` parameter create new instance  // , assign reference `keyboard` keyboard = new scanner(system.in);    // declare variable of type `string` ,  // assign return value of `next()` method called on `keyboard` object string userinput = keyboard.next();  

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -