How are arrays implemented in java?

Although arrays are Objects in the sense that they inherit java.lang.Object, the classes are created dynamically as a special feature of the language. They are not defined in source code.

Consider this array:

MySpecialCustomObject[] array;

There is no such source code for that. You have created it in code dynamically.

The reason why length is in lower case and a field is really about the fact that the later Java coding standards didn’t exist at the time this was developed. If an array was being developed today, it would probably be a method: getLength().

Length is a final field defined at object construction, it isn’t a constant, so some coding standards would not want that to be in upper case. However in general in Java today everything is generally either done as a constant in upper case or marked private with a public getter method, even if it is final.

Leave a Comment