wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Why arrays are object ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Why arrays are object ?" Watch "Why arrays are object ?" New topic
Author

Why arrays are object ?

Anto Telvin
Ranch Hand

Joined: Aug 12, 2008
Posts: 113
hi all can anyone tell me why it is saying that array's are object ...i am beginner in java..i read so many books but not getting a correct answer ?

can anyone help

thanks


Anto Telvin Mathew<br />Many of the life failures are people who did not realize how close they were to success when they give up. EDISON
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11153
    
  16

do you have some reason to thing they should NOT be objects?


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37939
    
  22
Because the designers of the language decided to make arrays objects in their own right.
Try calling a method on an array, eg toString(); even though the result may be rather basic (eg [I@abc123de) it gives a result at all.
Prashanti Mukund
Greenhorn

Joined: Aug 09, 2008
Posts: 4
Java is pure object oriented language except primitive datatypes rest all can be represented as objects.So when we create a class and when we want an array of objects of that class to be created how can we do if Arrays are not objects don't you think that will create another concept in java and we need to again learn that so arrays are objects

Originally posted by Anto telvin Mathew:
hi all can anyone tell me why it is saying that array's are object ...i am beginner in java..i read so many books but not getting a correct answer ?

can anyone help

thanks
Pratik Surti
Greenhorn

Joined: Sep 16, 2006
Posts: 21
In Java, arrays are objects, it can be created dynamically and can be assigned to variables of type Object. All methods of class Object may be invoked on an array.

A variable of array type holds a reference to an object. Declaring a variable of array type does not create an array object or allocate any space for array components. It creates only the variable itself, which can contain a reference to an array. However, the initializer part of a declarator may create an array, a reference to which then becomes the initial value of the variable.

Example:
int[] ai;// array of int
Exception ae[] = new Exception[3];


Pratik Surti
SCJP 5.0
Pratik Surti
Greenhorn

Joined: Sep 16, 2006
Posts: 21
In Java, arrays are objects, it can be created dynamically and can be assigned to variables of type Object. All methods of class Object may be invoked on an array.

A variable of array type holds a reference to an object. Declaring a variable of array type does not create an array object or allocate any space for array components. It creates only the variable itself, which can contain a reference to an array. However, the initializer part of a declarator may create an array, a reference to which then becomes the initial value of the variable.

Example:
int[] ai;// array of int
Exception ae[] = new Exception[3];
ravikdcs dixit
Greenhorn

Joined: Aug 27, 2008
Posts: 3
since java is object oriented you can acess instance members by creating objects or 'this' in some conditions
example
int a[]; //declares an array for integers
does not create an array but only a refernce of array that a is going to have integer type values
if array are not object how you are going to use it in your program?
example
int a[]=new int[10];//allocates memory for 10 integers
you can not access individual locations in the array if you not create object
you can also have array of Objects
example
Car[] c=new Car[10];
if it is not object then how you can create an array objects of your own class
Anto Telvin
Ranch Hand

Joined: Aug 12, 2008
Posts: 113
thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why arrays are object ?
 
Similar Threads
notify(), wait(), notifyall()
Wildcards in Class declaration
regarding resultset
Why do we have an equals method in String Class
Assigning double dimension array to single dimension array of type Object