What is an array in Java?
Why Interviewers Ask This
This is a classic screening question for Java roles. Hiring managers ask it early in interviews to gauge your baseline understanding and determine if you can communicate technical concepts clearly.
Answer
An array in Java is a fixed-size, ordered collection of elements of the same type. Once created, its size cannot change. Arrays are objects and are stored in the heap. Declare and create: int[] numbers = new int[5]; or int[] numbers = {1, 2, 3, 4, 5};. Access elements with zero-based indices: numbers[0]. Accessing an index out of bounds throws ArrayIndexOutOfBoundsException. Multi-dimensional arrays are arrays of arrays: int[][] matrix = new int[3][3];. The length property (not a method) gives the array size. For dynamic collections, use ArrayList instead.
Pro Tip
If you're unsure about a detail, say so honestly and explain your reasoning. Interviewers respect candidates who can think through uncertainty rather than bluffing.
Previous
What is the difference between throw and throws in Java?
Next
What is the enhanced for loop (for-each) in Java?