File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Object creation on Array Initialisation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Object creation on Array Initialisation" Watch "Object creation on Array Initialisation" New topic
Author

Object creation on Array Initialisation

Neha Daga
Ranch Hand

Joined: Oct 30, 2009
Posts: 504


the code above creates 3 objects on heap, one array and two thread objects. and the array will hold reference to these object in corresponding index position.
That's fine.


here only one object is created on heap. what about the primitive values that are being assigned to array, where are they stored???

is it the bit pattern of those values that is stored in the corresponding index position's allocated memory.


SCJP 1.6 96%
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9321
    
  17

here only one object is created on heap. what about the primitive values that are being assigned to array, where are they stored???

The values are stored in the array itself. Each element in the array will store the int value. When you create an array of references (like your first example), then each element in the array stores the reference variable (and the reference variables points to an objects on the heap), in case of a primitive value, the actual value is stored in the array...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Jeevan Reddy
Ranch Hand

Joined: Nov 10, 2009
Posts: 142
Ankit Garg wrote:
here only one object is created on heap. what about the primitive values that are being assigned to array, where are they stored???

The values are stored in the array itself. Each element in the array will store the int value. When you create an array of references (like your first example), then each element in the array stores the reference variable (and the reference variables points to an objects on the heap), in case of a primitive value, the actual value is stored in the array...


Thanks for the explanation

SCJP 1.6 (94%)
http://faq.javaranch.com/java/JspFaq
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Object creation on Array Initialisation