why String class is immutable.




Answers were Sorted based on User's Feedback



why String class is immutable...

Answer / vikrant

Once a string object is created no changes can be made to
it. If a string is modified in code a new object will be
created. That is why string is immutable

Is This Answer Correct ?    24 Yes 7 No

why String class is immutable...

Answer / rakesh soni

Any Program have 'Performance' and 'Memory' issue.
1. If you want to save your 'memory' then use the 'String'
class but 'Performance' will be decrease, because every time
new object create and old object memory collect by Garbage
Collector, so performance decrease.
And
2. If you want 'Performance', than use 'StringBuffer' or
'StringBuilder' object. These class's object consume more
memory but not create new object, so 'Performance' will
increase but with memory overhead.

So take decision according your code and issue. :)

Is This Answer Correct ?    8 Yes 1 No

why String class is immutable...

Answer / kirthika

everytime a string object is created, it enters into the string pool and thereby this concept was mainly to enhance the response time if the same string is used elsewher..
therefore string class is immutable..

Is This Answer Correct ?    4 Yes 4 No




why String class is immutable...

Answer / naru

String object is immutable that's why security maintain of
file chech .when connection is establic first os check the
String object if string is mutable that is big pain in
security issue...

Is This Answer Correct ?    2 Yes 4 No

why String class is immutable...

Answer / rakesh

For save the memory and reduce the response time.
StringBuffer provide an alternet for String class object,
which is muttable.

Is This Answer Correct ?    5 Yes 9 No

Post New Answer



More Core Java Interview Questions

justify c is portable

1 Answers  


I Have a class abstract with one abstract method, so that method should override in the subclass, but i dont want to override, if i am not override what will happen? If compilation will occur then i dont want to give compilation error, then what we need to do??? See the sample program. public abstract class AbstractExample { public abstract void sampleMethod(); } public class AbstractExampleImple extends AbstractExample { }

2 Answers   Mphasis,


If a method is declared as protected, where may the method be accessed?

0 Answers  


how can we use the servlet as standalone apllication?should we need to extend any class?

2 Answers   Logica CMG,


Explain about the interpreter in java?

0 Answers  






I need some details about an employee. i have only the employee id in my presentation layer(JSP).I entered that ID and click "Show Details" Button. Question is how the JSP pass that id to Controller layer and DAO and what mechanism we are using to retrive data from DB and how the data passed to JSP as a Output. Please explain in detail.

1 Answers   TCS,


Name the components that are termed to be Heavy-weight component but available in Light-weight components?

0 Answers  


Is java pure object oriented or not? if yes, give the valid reason.

13 Answers   Syntel, Emphasis, Wipro, NIIT,


explain Anonynous inner class?

6 Answers   TCS,


explain the concept of inheritance with an example?

9 Answers   Polaris,


If your team member writes code with lots of static variables and static methods, will it cause any side effects?

3 Answers   KPIT,


what is an anonymous class?

6 Answers   TCS,






Categories