aspose file tools*
The moose likes Java in General and the fly likes how many objects will be created. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "how many objects will be created." Watch "how many objects will be created." New topic
Author

how many objects will be created.

Abdul Gafoor
Greenhorn

Joined: Nov 22, 2005
Posts: 11
int a[]=new int[10];


String ss[]=new String[10];
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8927
    
    9

How many do you think will be created?


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Abdul Gafoor
Greenhorn

Joined: Nov 22, 2005
Posts: 11
I think

this code crete only one array object
int a[]=new int[10];
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8927
    
    9

You are correct. Now what about the second one?
Dilshan Edirisuriya
Ranch Hand

Joined: Apr 22, 2006
Posts: 299
second one there are 2,
one in the stack and the other one is in pool

Dilshan Edirisuriya
SCJP


Dilshan Edirisuriya SCJP1.4, SCWCD1.4, SCBCD 5
Anil Kumar Saha
Ranch Hand

Joined: Apr 07, 2004
Posts: 111
for the second expression, it will be 22.
inside heap--> 1 String Array object,10 String Objects
inside String Literal pool--> 1 String Array object,10 String Objects.


Correct me if I'm wrong.


Regards,

Anil Kumar Saha
SCJP 1.4
http://www.agilej.blogspot.com/
Dilshan Edirisuriya
Ranch Hand

Joined: Apr 22, 2006
Posts: 299
I considered array objects only
Dilshan Edirisuriya
Ranch Hand

Joined: Apr 22, 2006
Posts: 299
Another argument now I think it's 1

cos' as it is a String "array object" it doesn't create an instance in the pool.
Jeroen T Wenting
Ranch Hand

Joined: Apr 21, 2006
Posts: 1847
Initially only the array itself will be created with null references.
The actual number of objects created by the JVM will always depend on the actual content of the arry when creating arrays of object references.


42
Dilshan Edirisuriya
Ranch Hand

Joined: Apr 22, 2006
Posts: 299
yes I agree
Tony Morris
Ranch Hand

Joined: Sep 24, 2003
Posts: 1608
Originally posted by Anil Kumar Saha:
for the second expression, it will be 22.
inside heap--> 1 String Array object,10 String Objects
inside String Literal pool--> 1 String Array object,10 String Objects.


Correct me if I'm wrong.


You're wrong. The answer is 2.

This thread appears to have become more complex than is necessary to answer the original question - which has nothing to do with "the pool" (the apparently abstract concept that few understand but many like to talk about).


Tony Morris
Java Q&A (FAQ, Trivia)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how many objects will be created.