Explain how to use a Scanner object to read information from
Explain how to use a Scanner object to read information from a page on the internet. Give an example.
Explain what a wrapper classes are and how they are used in Java. Give an example.
What is an ArrayList object? How does is it similar to and how does it differ from a traditional array.
What is inheritance? How is it useful in software projects. How is the is-a test related to inheritance?
What is an exception? Explain how to use try/catch blocks to prevent a program from crashing.
What is refactoring? What are some of the ways that Eclipse can help you with refactoring?
What is the output? Explain how you obtain this answer by hand, not using a computer.
What is the output? Explain how you obtain this answer by hand, not using a computer.
A Java Swing application contains this paintComponent method for a panel. Sketch what is drawn by this method.
Solution
(a) scanner input = new scanner (system.in)
By above, we use a scanner object to read information from a page on the internet.
Example:
(b) Wrapper Class: To convert primitive into object into primitive is called wrapper class.
Example:
public class WrapperDemo{
public static void main(String args[]){
//Converting Integer to int
Integer a=new Integer(3);
int i=a.intValue();//converting Integer to int
int j=a;//unboxing, now compiler will write a.intValue() internally
system.out.println(a+\" \"+i+\" \"+j);
}}
(c) Array List Object: Arraylist is a class which implements List interface. ArrayList is a variable length in Collection class. Array list is growable in nature that is decrease and increase its size.
Example: ArrayList<Integer> integerList = new ArrayList<Integer>();
integerList.add(1);
Similarity Between Array List and Array:
Difference Between Array List and Array:
(d) Inheritance: It is a OOP\'s Concept. It allows child class to inherit the property or method of it\'s parent class.
Inheritance represents the IS-A relationship, also known as parent-child relationship.
It is useful in software projects: It is used for code reusability and to achieve method overriding.
Example:
class Employee{
float salary=4000;
}
class Guard extends Employee{
int bonus=10000;
public static void main(String args[]){
Guard g=new Guard();
System.out.println(\"Guard salary is:\"+g.salary);
System.out.println(\"Bonus of Guard Salary is:\"+g.bonus);
}
}
The is-a test related to inheritance: In above example, Guard is the subclass and Employee is the superclass. Relationship between two classes is Guard IS-A Employee.It means that Guard is a type of Employee. So, this is the is-a test related to inheritance.
| Primitive Type | Wrapper Class |
| boolean | Boolean |
| char | Char |
| byte | Byte |
| short | Short |
| int | Int |
| long | Long |
| float | Float |
| double | Double |

