ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
tip   SiteMap shows list of All Categories in this site.
Google
 
Categories  >>  Software  >>  Core Java  >>  Java J2EE  >>  Java Related
 
 


 

 
 Core Java interview questions  Core Java Interview Questions
 Advanced Java interview questions  Advanced Java Interview Questions
 Swing interview questions  Swing Interview Questions
 EJB interview questions  EJB Interview Questions
 Servlets interview questions  Servlets Interview Questions
 Struts interview questions  Struts Interview Questions
 JDBC interview questions  JDBC Interview Questions
 JMS interview questions  JMS Interview Questions
 SunOne interview questions  SunOne Interview Questions
 J2EE interview questions  J2EE Interview Questions
 Weblogic interview questions  Weblogic Interview Questions
 Websphere interview questions  Websphere Interview Questions
 Java Networking interview questions  Java Networking Interview Questions
 Java J2EE AllOther interview questions  Java J2EE AllOther Interview Questions
Question
what is mutability?which one is mutable String or StringBuffer?and why?give 
examples of each which shows the mutability of each String or StringBuffer
 Question Submitted By :: Debraj
I also faced this Question!!     Rank Answer Posted By  
 
  Re: what is mutability?which one is mutable String or StringBuffer?and why?give examples of each which shows the mutability of each String or StringBuffer
Answer
# 1
Mutability means which can be changed. StringBuffer is a 
mutable bcoz the contents of the SB object we can change, 
it can't create new reference location even though we 
change the value it already referenced. But in case of 
String it reference location is changed every time if u 
change the content.
 
Is This Answer Correct ?    13 Yes 1 No
Surya Simhadri
 
  Re: what is mutability?which one is mutable String or StringBuffer?and why?give examples of each which shows the mutability of each String or StringBuffer
Answer
# 2
if use 
 String s="raj";
here string object created in string content pool(scp).it
(scp)doesn't allow duplicate objects.so it is immutable

String s=s+"ramu";
here  string object created in heap allows duplicate 
objects.so it is immutable
in heap 

String s=rajramu;

if use string buffer every time it will create object in 
heap.heap allows duplicate object.so it is mutable
StringBuffer sb=new StringBuffer("raj");
StringBuffersb1=sb.append("ramu");

if u hav any questions related java just call me:9952942104

finally it create duplicate value in heap.
 
Is This Answer Correct ?    3 Yes 2 No
Rajender
 
 
 

 
 
 
Other Core Java Interview Questions
 
  Question Asked @ Answers
 
What is numeric promotion?  1
Can a Byte object be cast to a double value?  2
Package1 and Package2 both have a method name lets say "methodA" with different implementation. When I import both the packages in a java class how can I use both the methods? Ericsson3
What is the difference between abstract class and interface?  2
Can we declare static variables in JSP page. TCS3
What modifiers are used with a top level class?  2
When we can access the static data member without creating the object what is the need of the object in java. ssinformatics4
what is custom tags with example? AMDOC1
What is the immediate superclass of Menu?  1
What is the immediate parent class of the Applet class?  1
What are null interfaces in JAVA ? and give me some examples?  3
can we have virtual functions in java? Wipro7
Differentiate constructor and a method and how are it be used? Wipro5
What is anonymous class?  2
how to print output with out using sop statements UHG3
they asked class A{} class B{} class c{} all the three class saved as a single file,there is no main method in the file and anothe class M.java class m { psvm(String args[]) { // here the parent class can access } } DNS1
What is the Set interface?  2
Why we use static and synchronized in method for single thread model example: public static synchronized add(){}  1
what is Assertion? Wipro2
suppose in a class there is a code like this: { Set hs=new Hashset(); hs.add(new Emp("kathy",1000)); hs.add(new Emp("kathy",2000)); } how can u avoid the above code in your class as set won't allow duplicate objects?  2
 
For more Core Java Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com