I have a basic doubt, when I was analyzing object and reference.
int a; //here we are creating an object a of type integer
Integer b=new Integer(); // here we are creating a reference variable b points to an object of type Integer in heap.
What is the advantage of each one ? where to use "int a" and the other one?
In case of arrays:
int[] a=new int a[5];
if "int a" is possible why " int a[5] " is not possible, because the below code throws null pointer exception:
int a[5];
a[0]=10;
System.out.println(a[0]); //gives null pointer exception
The code works well when:
int[] a=new int[5];
a[0]=5;
System.out.println(a[0]);
Why in case the former case its excepting a reference needs to be created when "int a" works?