Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How many Object is created?

 
Santanu Guha
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All ,

Can you tell me how many Objects are created created in Heap and in "String Literal Pool" when i execute the below code in java : --
Is tere any Pool memory affected by "Santanu"
?
StringBuffer sb = new StringBuffer("Santanu");

Thanks in Advance
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One string one StringBuffer.
next.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49789
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch (after 2½ years ). There's no such thing as "urgent" here.
 
Rob Spoor
Sheriff
Pie
Posts: 20608
63
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David O'Meara wrote:One string one StringBuffer.
next.

And one char[] inside the StringBuffer.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49789
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
. . . and a char[] inside the String?

4 and counting
 
Siddhesh Deodhar
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can analyze output of de assembler and can conclude on number of objects created.

Run javap -c <class name> on your class and see the output.
 
Mike Simmons
Ranch Hand
Posts: 3090
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Santanu Guha wrote:It's UGENT !!!

Fixed.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic