Waiting for enlightenment....
|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
Waiting for enlightenment....
Waiting for enlightenment....
Prateek Rawal wrote:Excellent help Abhimaram!
![]()
|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
Prateek Rawal wrote:Also i have two doubts:
1) Is String Pool different from Heap? Or Pool + Non-Pool = Heap?
Prateek Rawal wrote:
2) They said, there would be no GC questions on Strings in SCJP, however, can there be questions on Strings about how many objects are created? and how many of them are in pool and how many are in Non-Pool Memory?? it seems quite probable, isn't it?
|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
Prateek Rawal wrote:
Here, one apple literal pool object is create, and a builder object is created with value apple, but what about
s1.toString()...what does it do???
Does it return the apple object on the pool as Ankit told???
|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
String Literal Pool is a part of the heap!
The toString method of a String object never creates a new String object, neither in the heap nor in the constant pool, it just returns the String object itself i.e. this.
The toString method of a String object never creates a new String object, neither in the heap nor in the constant pool, it just returns the String object itself i.e. this.
Waiting for enlightenment....
can there be questions on Strings about how many objects are created? and how many of them are in pool and how many are in Non-Pool Memory?? it seems quite probable, isn't it?
in the diagram String pool is shown different from Heap
SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Waiting for enlightenment....
Returns a string representing the data in this sequence. A new String object is allocated and initialized to contain the character sequence currently represented by this object. This String is then returned. Subsequent changes to this sequence do not affect the contents of the String.
SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Waiting for enlightenment....
Prateek Rawal wrote:where does the string object created by toString() method of StringBuilder get created?
In the non-pool memory i suppose, as one String object with same value is already there in the pool
Correct me if i'm wrong
Strings are immutable because String literals with same content share the same storage in the string common pool. Modifying the content of one String directly may cause adverse side-effects to other Strings sharing the same storage. JDK provides a StringBuffer class (in package java.lang) to support mutable strings. A StringBuffer object is just like any ordinary object, which are stored in the heap and not shared, and therefore, can be modified without causing adverse side-effect to other objects.
|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
Waiting for enlightenment....
Prateek Rawal wrote:IMO you are slightly going wrong,
|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
Waiting for enlightenment....
Abimaran Kugathasan wrote: will create a StringBuilder object in the heap not in the String Literal Pool, But will create a String object in the String Literal Pool necause there is no ABC literal in that pool.
SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Waiting for enlightenment....
Consider Paul's rocket mass heater. |