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
hi to all. well can you please tell me that why String class
is immutable?

Thanks in advance.
 Question Submitted By :: Tanzeem.akhtar
I also faced this Question!!     Rank Answer Posted By  
 
  Re: hi to all. well can you please tell me that why String class is immutable? Thanks in advance.
Answer
# 1
Well it is immutable because of the memory concern. For 
every new string if there is new object then it will take 
lot of memory and if there is such requirement then there 
is StringBuffer class provided.
 
Is This Answer Correct ?    2 Yes 0 No
Hari
 
  Re: hi to all. well can you please tell me that why String class is immutable? Thanks in advance.
Answer
# 2
Since, return type of the string class cannot be altered 
with substrings or any ammendments to it .

 
Is This Answer Correct ?    0 Yes 1 No
Syed
 
 
 
  Re: hi to all. well can you please tell me that why String class is immutable? Thanks in advance.
Answer
# 3
Immutable means which cant not be changed. whenever you call
a method though an instance of String class it will give you
the result as new String object. It wont change the existing
String object.

String class objects are made immutable so that if the
String is logically same,then more than one object can refer
the same single String in memory. in this way it also saves
memory. 

Example: String a="ABC";
         String b="ABC";

in above example JVM will create only one object with the
value "ABC" and both the reference variables a and b will
refer to the same. So it is saving memory.


If you need to change a String object very frequently, it is
not adviced to use a String object as it creates a new
object whenever you change its value. Its a best practice to
use StringBuffer. it is mutable.

For more info write to me at akhilsaxenain2000@yahoo.com
 
Is This Answer Correct ?    0 Yes 0 No
Akhil Saxena
 

 
 
 
Other Core Java Interview Questions
 
  Question Asked @ Answers
 
What is means by DLL file means ? What is the use of DLL file? What are the contents of DLL file?  2
What is the minimum and maximum length of an identifier? TCS6
what is the use of abstract class and interface with example? DNS2
What is the relationship between a method?s throws clause and the exceptions that can be thrown during the method?s execution?  2
What is the exact difference in between Unicast and Multicast object ? Accenture1
What is light weight component?  3
How the elements are organized in BorderLayout?  4
What is the default initialized value of String type variable?  3
What are the names of interfaces that doesn't consists of method/s ?  3
Hi, This is ravi i have a question like this i have string "UNDERSTAND" now i want to count the letters how many times it occures.i.e from the above string the out put should be like this U-1,N-2,D-2,E-1,R-1,S-1,T-1,A-1. how can i achieve this Thnaks in advance for your response ..  4
whats the purposr of using serialization?  6
What are Transient and Volatile Modifiers?  2
If there is no implementation of MARKER INTERFACE in java. Then how compiler come to know about specification.  2
In what ways you can handle exception ?  3
What are Access Specifiers and Access Modifiers. TCS4
Difference between Superclass and Subclass?  2
what is main purpose of interface? Accenture2
Adapter classes?  3
what are the diffrences between interface and abstract class?  4
What is Transient and volatile iFlex9
 
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