jQuery in Action, 2nd edition*
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


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Array object vs. an array" Watch "Array object vs. an array" New topic
Author

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: http://aspose.com/file-tools
 
subject: Array object vs. an array
 
Similar Threads
confusion in Expression Language
getting 2D array view in jsp from actionform properties
Convert Java Array to JavaScript Array.
how to remove unwanted pixels from image
How to convert a number into an Array