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       Ask Questions on ANYTHING, that arise in your Daily Life at     FORUM9.COM
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
When you say String is immutable, what do you mean by that?
Say I have String s = "Ness"
s= s+"Technologies";
What will happen? If the value gets appended, then what is
the meaning of immutable here?
 Question Submitted By :: Maria
I also faced this Question!!     Rank Answer Posted By  
 
  Re: When you say String is immutable, what do you mean by that? Say I have String s = "Ness" s= s+"Technologies"; What will happen? If the value gets appended, then what is the meaning of immutable here?
Answer
# 1
every time a new String object gets created in this case.
 
Is This Answer Correct ?    5 Yes 2 No
Harmetkrishanan
 
  Re: When you say String is immutable, what do you mean by that? Say I have String s = "Ness" s= s+"Technologies"; What will happen? If the value gets appended, then what is the meaning of immutable here?
Answer
# 2
Every time a new String objects gets created in this case, 
but if assigned value is not same. If assigned, value is 
same, then it points to same memory location, even if it is 
another variable. For ex;
String s="Test";
String s2="Test";

  Now s, s2 points to the same memory location.
 
Is This Answer Correct ?    4 Yes 0 No
Bln
 
 
 
  Re: When you say String is immutable, what do you mean by that? Say I have String s = "Ness" s= s+"Technologies"; What will happen? If the value gets appended, then what is the meaning of immutable here?
Answer
# 3
Once you have assigned a value to a "String Object" (i am 
saying an "object" not the "object reference")that value 
can never change. This is immutability.

by defining "s = s+Technologies" we are pointing the 
REFERENCE to newly created "string object" with the 
modified string. So the previous string object is 
considered to be lost.

This concept has explained very well in String, I/Os 
chapter of Kethy Siera, SCJP 5.

All the best
 
Is This Answer Correct ?    6 Yes 0 No
Haribabu
 
  Re: When you say String is immutable, what do you mean by that? Say I have String s = "Ness" s= s+"Technologies"; What will happen? If the value gets appended, then what is the meaning of immutable here?
Answer
# 4
Now u add s= s+"Technologies";
so it will NessTechnologies because you append. and assign
new varible,means that new addition is assigned to s

take one example for more clarity

String x = "Java";
x.concat(" Rules!");
          System.out.println(x);

output is x=java
because string is immutable.............think hard on it


Consider the following another example---------and think
about that

public class NewClass {

    public static void main(String as[])
    {
        String s="abc";
      String  s1=s+"cde";
        System.out.println(s);
          System.out.println(s1);


String x = "Java";
x.concat(" Rules!");
          System.out.println(x);
    }

}
output is
s=abc;
s1=abcde
x=java

since u have added cde in s but still from the output it is 
abc...............means string is immutable,

For more contact me
Anjani Kumar jha
09623154095
CDAC,PUNE
 
Is This Answer Correct ?    1 Yes 0 No
Anjani Kumar Jha
 

 
 
 
Other Core Java Interview Questions
 
  Question Asked @ Answers
 
What is a super class and how super class be called?  3
How OOPS concept is achieved in Java? JPMorgan-Chase4
Without creating a new object, How you can retrieve a String or other object?  1
I/O blocking means?  1
What is the differenc between Enemuration interface and iterator interface according to accessing?  4
Can we instantiate Interfaces? Ericsson4
can any one tell me when do u go for inheritance and polymorphism  1
what is difference between throw and throws in exception?  15
What is the Layout for ToolBar?  1
what is Portal(web based online portal)? AIG1
What is the difference between abstract class and interface?  2
In which way does a Primitive data type is passed ? Sun-Microsystems2
What is synchronization? How it can be achieved?  2
Can we have a abstract class withought any method? What is a purspose of this?  1
Can an exception be rethrown? Wipro4
what is a package?  7
Hi, well i am unable to understand that why it is mandatory to have same hashcode, if two objects are same? Thanks in advance.  5
what are ER diagrams?  2
what is diff bet iterator and enumeration?  2
which swing component is similar to rich text box in .net/vb  1
 
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