Java arrays are objects. They inherit from the Object class.
The JVM specification does not define any specific implementation for objects if they behave according to the specifications. In practice, it is implemented with a heading followed by the actual fields of the object.
An array in Java is not just a sequence of its primitive components. This is an object, it has a length field, and it has methods. Thus, like any other object, it has a header followed by a length, and then all the components of the array.
An array allocated with zero size is an object with a title and size, but not the space allocated for real components.
An array reference is like a reference to any other object. Arrays in Java are not like arrays in C, where if the array was zero, the pointer pointing to its beginning would actually be invalid. An array reference points to an array object, which, as it turns out, has zero length and actual elements. If you try to access any element in such an array, there will be no question about valid pointers. The array reference itself points to a valid object. Then checking the boundaries will show that any index will be outside the boundaries, so further dereferencing of the pointer will not occur.
So, the bottom line indicates that the reference to char[0] is a valid reference to the actual selected object. It simply has no data beyond the length.
And this is different from null , which is a reference whose bits are zero, so it is not indicated anywhere at all. No memory is allocated except the link itself, while for char[0] , enough memory is allocated for the header and length.
As for strings, two empty strings do not necessarily point to the same character array. For example, if you write:
String a = new String(); String b = new String();
You will get two different empty string objects. Each of them has a separate empty array of characters that it points to. This is because the no-args constructor of the String class is implemented as follows:
public String() { this.value = new char[0]; }
Do you see the use of the new keyword? This means that a new array object is allocated, not copied from anywhere.
Please note that if your source was:
String a = ""; String b = "";
Then, due to internment, they will point to the same string object and, therefore, to the same array of characters. In addition, if it was:
String a = new String(); String b = new String(a);
Then you will have two different String objects, but they both point to the same internal array of characters. This is because the constructor for the second line:
public String(String original) { this.value = original.value; this.hash = original.hash; }
Again, a pointer to an empty string, of course, does not match a pointer to null. It points to the actual string object, which points to the actual character array object.