aspose file tools*
The moose likes Java in General and the fly likes Array in Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Array in Java" Watch "Array in Java" New topic
Author

Array in Java

Ankur Gargg
Ranch Hand

Joined: Sep 11, 2011
Posts: 55

HI Ranchers

How is Array implemented in Java?
I mean when I create an int array say like int[] intarray=new int[10]; the intarray object is of which class?
Thirdly when I saw the modifiers of the class created to represent this array the modifiers showed "public,abstract and final"..Why is that so?
Fourthly form where does the attribute length come for an array?

Regards
Ankur Garg



Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14107
    
  16

Ankur Gargg wrote:I mean when I create an int array say like int[] intarray=new int[10]; the intarray object is of which class?

It's a special built-in class that doesn't really have a name. Have a look at this:

This will print the rather strange: [I as the name of the class.
Also see this:

Ankur Gargg wrote:Thirdly when I saw the modifiers of the class created to represent this array the modifiers showed "public,abstract and final"..Why is that so?

Where did you see that exactly?

Ankur Gargg wrote:Fourthly form where does the attribute length come for an array?

When you create a new array you always have to specify the length. The length of arrays is fixed - an array cannot be resized after it has been created.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Ankur Gargg
Ranch Hand

Joined: Sep 11, 2011
Posts: 55

HI Jesper



I ran this code and the output is:->
ArrayClass-->class [I
SuperClass--->class java.lang.Object
It's an int array
Modifiers---->public abstract final
Name--->int[]
java.lang.Cloneable
java.io.Serializable
0.

So can you explain the output?I am not able to figure out from where does the "length" attribute come from even if the class created does not have any attributes.

Regards
Ankur Garg

[Edit - added code tags - see UseCodeTags for details]
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3446
    
  12
Ankur Gargg wrote:I am not able to figure out from where does the "length" attribute come from even if the class created does not have any attributes.

It does have attributes


Joanne
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Array in Java