File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Array object vs. an array Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Array object vs. an array" Watch "Array object vs. an array" New topic

Array object vs. an array

Dan Walin
Ranch Hand

Joined: Nov 11, 2003
Posts: 109
While reading about Java I think I understand that there is something called an Array class which has methods and properties and then there is an array which is part of the Java language. I was taking a practice test and then looking at the explanation of the answers where they said an array has a "property" of "length". I thought only an object can have properties. Can anyone help me understand the true nature of an array in Java? Example: why can I create an array with "int mynum[]" and not have to use "Array mynum = new Array()". I may be way off in my understanding so if someone can point me to a good place to read up on this, that would help too. Thanks.
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
An array is an Object. Any Java context that accepts Object as a parameter will accept an array. The Array class is a utility class for creating and accessing java arrays. It is not the same as the classes that define a arrays in java. The API docs for the Class class state:
Instances of the class Class represent classes and interfaces in a running Java application. Every array also belongs to a class that is reflected as a Class object that is shared by all arrays with the same element type and number of dimensions.

That is why arrays can and do have a length property.
It would seem obvious that by using the new operator that arrays must be objects for example:

Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
Dan Walin
Ranch Hand

Joined: Nov 11, 2003
Posts: 109
Great, thanks. I'm reading up more on the Class class. You've just enlightened me a lot!
I agree. Here's the link:
subject: Array object vs. an array
It's not a secret anymore!