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
 
In the first round, there are 30 aptitude and 30 java questions. We are suppose to finish both the papers within 60 minutes. I cleared this round. Next was test for programming skills. In this section, Some 7 n's were asked. 1. What is the difference b/w sleep(1000) and wait(1000) 2. what is the diff b/w static block and static function? 3. Write a program to validate IP address using string tokenizer. 4. Write a program to create singleton class 5. write a function to reverse the string 6. Write a prog to print prime nos upto n. EX: If n=9, It shld print 1,2,3,5,7 7. One program on collections- Write a program to print no. of times a number is repeating in an array. EX- {1,3,1,2,5,7,3,7,34,3,8,3} It should print: 1- 2 times 3- 4 times and so on 7. Write a func to print fibonocci series After this I had technical interview, which went on for. 60 mins or so. There were qn's about multi threading, Exception handling and collection classes. Knowledge about collections was very important for the post I was interviewed for. Huawei1
Under what circumstances an object reference be cast to an interface reference?  3
Difference between Web-based applications,Client- Server applications and Distributed applications? Infosys2
Why null interfaces are used in Java?  2
What is an event?  1
what release of java technology are currently available what do they contain?  1
can we create a instance for intwerface?  3
What advantage does an entity bean have over a sessin bean? Adobe3
What is meant by serialisation and deserialisation?  3
what are depricated methods ? Satyam4
What is dynamic binding?  2
How can a class be accessed, If no access modifiers are declared?  2
How to find the size of an array a)array.length() b)array.length c)array.size() d)array.size Accenture6
who can we create the object of a class? in how many ways we can create it (max 5)  1
What is the difference between Abstract Class and Interface AMDOC6
when asub class inherits a super class and overrides a public method of super class in sub class(public method in super class). why these methods needs to be public in sub class. (otherwise compile time error).  2
what is webservices? CTS1
What is the life cycle of Thread ? HCL7
How to avoid the runtime exception ?  2
what are Checked & Unchecked exceptions ?  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