String StringBuffer Interview Questions
Read well String StringBuffer Interview Questions.
- What is a String in Java?
In Java, String does not terminate with \0. String is a class from java.lang package and can be manipulated with String class methods. - How strings are immutable?
In case of variables, if a variable value is changed, the value in the location is changed but not the location itself. That is, varibale memory address does not change and it is the same before changing and after. But in case of strings, it is very different. When a string value is changed, the new value is stored in a new location and the old location with old value is garbage collected. This happens any number of times whenever a string is reassigned. For this behavior, the strings are said to be immutable (cannot be changed). - When String exists, why it is necessary to introduce StringBuffer?
String’s immutable nature decreases performance. To overcome this, Java designers introduced StringBuffer as StringBuffer is mutable. - Explain StringBuffer's mutability?
When a string stored in StringBuffer is changed, the location of the StringBuffer is not changed. There will be very less overhead of memory manipulation. This increases performance (there is StringBuilder also in Java).
Pass your comments and suggestions to improve the quality on this tutorial "String StringBuffer Interview Questions".
my self sundar.sir, i read java from yure blog but i want spring and webservice notes like yure blog with easily undestable format.plz suggest me…i am not easily to go with internet first basic plz suggest me .
I will place them shortly and subject is also ready. If you are at Hyderabad, mail me I get hard copies.
Sir can you check the definition of String?
“In Java, String is not an array of characters”
Just I changed. If you are not satisfied, comment again.
Thank you sir that’s fine
we can also say string is a sequence of characters
Hi Sir,
In the case of strings,we are having literal pool,the same concept is not available in other wrapper classes.
Please update me the reason.
It is given to increase the performance as strings are used very often in programming.
actually when compile your program thread suspend that the message are occure what type of exception i cant understand plz help me….
Note: mth4.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
What you have given in Note is only deprecated warning because suspend and resume methods are deprected.
Designers deprecated for the reason when a thread in synchronized state is suspended, it cannot be accessed by any other needy thread.