Java programming questions 1. Why do we instantiate an object of a class? 2. What object can you use to read data into a Java program? 3. What method can you use to display formatted information? 4. What method is used to output some text and then go to the next line? 5. “Scanner” is part of what package? 6. Write a statement that creates a Scanner object called MyInput that reads from the keyboard. 7. Name two Scanner method (hint: one that reads a word and one that reads a line) 8. What is a driver/client program? 9. Why the data items in a class are called instance variables? 10. Why instance variables are declared private? And how do we modify (read/write) them? Solution 1. Why do we instantiate an object of a class? Instantiating an object of a class means allocating the required memory for the object, and assigning some possible values to those object members is what instantiation is. 2. What object can you use to read data into a Java program? There are multiple possible objects that can be used to read data into a Java program. Scanner object is the easiest which reads data from the console. 3. What method can you use to display formatted information? Again there are multiple possible methods. Where as to display formatted information, the well known method is: System.out.format(). 4. What method is used to output some text and then go to the next line? To print some text to the screen, and move to the next line, the method used is: System.out.println(); Here ln stands for line(new line.) 5. “Scanner” is part of what package? Scanner is part of java.util.* package. 6. Write a statement that creates a Scanner object called MyInput that reads from the keyboard. Scanner MyInput = new Scanner(System.in) will read data from keyboard. 7. Name two Scanner method (hint: one that reads a word and one that reads a line) The two Scanner methods are: Scanner.next() which reads the next word, and Scanner.nextLine() which reads the next line of data. 8. What is a driver/client program? 9. Why the data items in a class are called instance variables? 10. Why instance variables are declared private? And how do we modify (read/write) them?.