Hello. I am quite new to java. I have taken one class, and have done some reading, but am still putting things together.
Listed below is a small bit of code which creates an integer array, then finds and displays the length of the array. I am trying to find out more about the "intArray.length" construct. I understand that an array is an object. How do I look for the array object in the Java API? What I did find is an Array class in the java.lang.reflect package, which extends the Object class, if I am understanding it right. When I look for instance variables in the Array class, I do not find one. Under the methods, there was "getLength", but not length. Also, it was my general understanding that a method always ends with parenthesis.
The J2SE API documentation doesn't cover arrays. There is no class definition for an array object.
length is a public final member of an array object, assigned a value when the array object is created.
Some other folks around these parts have discussed this topic a few times before. You might like to do a quick search on this forum for "array length". Note that the search page link is towards the top right of this page.
Well you are right, the methods have a parenthesis at the end. But the lenght of an array is not a returned by a method. Well, if you observe closely in the api of Arrays, you'll find that lenght is not mentioned in the methods, but as a class variable. Well, now u know what a variable is. Here length is a variable of int type. A simple int x = length; will give u an error, but int x = array.length; will give u the length of that array. You'll come across class variables more often once you start programming applets. In applets, the colors are class variables and not methods.
Hang on with Java and u'll soon understand the jargon.