Ahmad Auada wrote:and what is the difference between instance variable, reference variable, and class variable?
instance variable- are those which are declared inside a class and are out of all the loops and are not static .
reference variables - are the variable that refer to any object/instance of a class or the variables that are reference to the object/instance of a class.
class variable - are the variable that are declared static. They are compile time variable.
instance variable share a copy of them with every instance of a class whereas class/static variables share the original value.
means, different instances of a class will have different value of instance variable but will contain the same unique value of class/static varibale
"Despite the performance benefit offered by the primitive types, there are times when you will need an object representation. For example, you can’t pass a primitive type by reference to a method."
Where did you see this? Can you give us the source?
...you can’t pass a primitive type by reference to a method.
This implies that you could pass a variable by reference if it were a wrapper type. This is not true. You can pass nothing by reference in Java. You can pass the value of a reference and work on that variable inside the method, but you're still passing a value.
A better illustration of why you sometimes need a wrapper class is generics. You might be familiar with something like this:
This works because String is a class. But what if you wanted to do this?
It won't compile because int is a primitive, not a class. So you use the wrapper class Integer:
All things are lawful, but not all things are profitable.