If I use a normal class like List, Vector or something else, I get a size()
function which returns the length of the regarded class but if I use an array of a class or a default data type I get a public member length which returns the current length of the array.
int a[] = new int[3];
a.length; // used without ()
Vector<Integer> v = new Vector<Integer>();
v.length(); // used with ()
Why is that? I mean an array is not an own class isn't it? So if it is no class it can't have a member varaible. I can't get an idea how that is handled in the background (ByteCode). I know that an array in the memory is stored with a pointer to the first element of the array and with the index (i) the memory pointer is shifted to ArrayPointer + i*(size of DataType)
.
Now you can say the computer goes throught all elements of an array and counts all the elements but how can a computer know where an array ends and where the next starts? And from where comes the 'member varaible' from the array where the size is stored?
I mean we use arrays so often but I know so little what happens behind the Java code in the ByteCode. Can you explain to me how that is possible?