Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where can I find the source code for Java arrays? [closed]

Tags:

java

arrays

Where can I find the source code for java arrays?

Example:

double[] arr=new double[20];

All array's with any dimension implements Cloneable and Serializable` interface. I searched the source code but couldn't find the code for this.

like image 571
Emil Avatar asked Oct 19 '10 04:10

Emil


People also ask

Where is an array stored in Java?

Memory is allocated in Heap are for the Array in Java. In Java reference types are stored in the Heap area. As arrays are also reference types, (they can be created using the “new” keyword) they are also stored in the Heap area.

How do you reference an array in Java?

Declaring a Variable to Refer to an ArrayAn array's type is written as type[] , where type is the data type of the contained elements; the brackets are special symbols indicating that this variable holds an array. The size of the array is not part of its type (which is why the brackets are empty).

How do I retrieve an element from an array?

get() is an inbuilt method in Java and is used to return the element at a given index from the specified Array. Parameters : This method accepts two mandatory parameters: array: The object array whose index is to be returned.


2 Answers

Have a look at this for an explanation. But basically the array type is built-in to the jvm and you need to analyze the source code for the jvm you are running in order to truly know how it works.

like image 67
Matt Phillips Avatar answered Oct 14 '22 17:10

Matt Phillips


Here is the javadocs for java.util.Arrays and here is the implementation of java.util.Arrays in openjdk. Google Code search is a good way to go about it.

UPDATE 1: Link updated. Posted the wrong link.

UPDATE 2: As pointed out by thilo, the jvm implementation of Array is here

like image 43
zengr Avatar answered Oct 14 '22 18:10

zengr