Java Interview Questions
1 .
Can we re-size an array after it is created?
No, we can’t re-size an array after its creation. But in case of re initialization, whatever data that is stored in the array before re initialization will be lost.
2 .
Difference between a[] and []a in Java?
You can declare an array in Java by either prefixing or suffixing [] with variable. There is not much difference between them if you are not creating more than one variable in one line, but if you do then it creates different types of variables, as shown in following example :

int a[], b; // first is int array, second is just int variable
int[] c, d; // both c and d are integer array
3 .
Is it legal to initialize an array int i[] = {1, 2, 3, 4, 5};
Yes, it is perfectly legal. You can create and initialize array in same line in Java.
4 .
How to get length of an array?
By using arrayname.length property to know the size/ length of an array.
5 .
Can you pass the negative number as an array size?
No. You can’t pass the negative integer as an array size. If you pass, there will be no compile time error but you will get NegativeArraySizeException at run time.
6 .
what is ArrayIndexOutOfBoundsException in java? When it occurs?
ArrayIndexOutOfBoundsException is a run time exception which occurs when your program tries to access invalid index of an array i.e negative index or index higher than the size of the array.
7 .
What value does array elements get, if they are not initialized?
They get default values.
8 .
What is ArrayStoreException in java? When you will get this exception?
ArrayStoreException is a run time exception which occurs when you try to store non-compatible element in an array object. The type of the elements must be compatible with the type of array object. For example, you can store only string elements in an array of strings. if you try to insert integer element in an array of strings, you will get ArrayStoreException at run time.
9 .
There are two array objects of int type. one is containing 100 elements and another one is containing 10 elements. Can you assign array of 100 elements to an array of 10 elements?
Yes, you can assign array of 100 elements to an array of 10 elements provided they should be of same type. While assigning, compiler checks only type of the array not the size.

public class MainClass
{
    public static void main(String[] args)
    {
        int[] a = new int[10];
        int[] b = new int[100];
        a = b;      //Compiler checks only type, not the size
    }
}
10 .
What are the drawbacks of the arrays in java?
The main drawback of the arrays is that arrays are of fixed size. You can’t change the size of the array once you create it. Therefore, you must know how many elements  you want in an array before creating it. You can’t insert or delete the elements once you create an array. Only you can do is change the value of the elements.