0

In order to use the "class" from the java.util package. is it necessary to create object?

If yes means then why we shouldn't create "object" in simple Java program at all time. https://code.sololearn.com/cZu88U0tilXE/?ref=app

11th May 2020, 1:49 PM
Yogeshwaran
6 odpowiedzi
0
System is a class and 'in' is a reference variable of type InputStream. You can get more details here. https://docs.oracle.com/javase/7/docs/api/java/lang/System.html System.in is passed to scanner class object to specify that it should except input from any input stream, could be a keyboard stroke or a file etc.
11th May 2020, 2:20 PM
Avinesh
Avinesh - avatar
0
No
11th May 2020, 1:50 PM
Abhay
Abhay - avatar
0
You need not create objects of classes at all times because they are either created for you and are assigned the static and final keyword so that you can call the methods on them directly. For eg- out is an object from PrintStream class and you directly call the print method on it. But this is from java.lang package. But to use scanner object from the java.util package, generally we say- new Scanner(System.in) You need not use the new keyword everytime. You can understand it better from the respective class definitions.
11th May 2020, 2:03 PM
Avinesh
Avinesh - avatar
0
Abhay then why we create a object while we using a scanner class to get a user's input. If we able to do it without creating object to get user's input then explain it with codebits https://code.sololearn.com/cq032kxCt7iw/?ref=app
11th May 2020, 2:04 PM
Yogeshwaran
0
Avinesh bro thanks but I don't know what is the "system.in" in new Scanner (System.in)?
11th May 2020, 2:08 PM
Yogeshwaran
0
Avinesh bro thanks....
11th May 2020, 2:23 PM
Yogeshwaran