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
1).what is the difference between below examples

String s="vijay";

String s=new String("vijay");
 Question Submitted By :: Info_vijaykumar
I also faced this Question!!     Rank Answer Posted By  
 
  Re: 1).what is the difference between below examples String s="vijay"; String s=new String("vijay");
Answer
# 1
in first string class it create in heep memory and second 
is created object in constant memeory we cannot change the 
second one
 
Is This Answer Correct ?    2 Yes 3 No
P.sreekiran
 
  Re: 1).what is the difference between below examples String s="vijay"; String s=new String("vijay");
Answer
# 2
In first statement String s = "vijay"

Means it will create a single instance and single reference 
variable

but in second statement

String s = new String("vijay");

Means it will create a two instances and single reference 
variable
 
Is This Answer Correct ?    1 Yes 1 No
Karun
 
 
 
  Re: 1).what is the difference between below examples String s="vijay"; String s=new String("vijay");
Answer
# 3
i got your answer,what are all the two instance in 
that?.....
 
Is This Answer Correct ?    0 Yes 0 No
Info_vijaykumar
 
  Re: 1).what is the difference between below examples String s="vijay"; String s=new String("vijay");
Answer
# 4
the two instances are created with the same name but one is 
storing in constant pool and another one is saved in the 
non constant pool.
 
Is This Answer Correct ?    1 Yes 0 No
Karun_cts
 
  Re: 1).what is the difference between below examples String s="vijay"; String s=new String("vijay");
Answer
# 5
Thanks a lot Karun....
 
Is This Answer Correct ?    0 Yes 0 No
Info_vijaykumar
 
  Re: 1).what is the difference between below examples String s="vijay"; String s=new String("vijay");
Answer
# 6
am unable to get constant pool and non constant pool?

can you please explain it and send it to my id.

sushreekp@gmail.com
 
Is This Answer Correct ?    1 Yes 0 No
Susrhee Kanta
 
  Re: 1).what is the difference between below examples String s="vijay"; String s=new String("vijay");
Answer
# 7
the first case does: if u write first case , one object and 
one refernce will be created. object will be created in 
string pool.
But when u write 2nd case , two object and one refernce 
will be created , one in string pool and one in heap.
 
Is This Answer Correct ?    0 Yes 0 No
Navneet Raushan
 
  Re: 1).what is the difference between below examples String s="vijay"; String s=new String("vijay");
Answer
# 8
as kiran said in the first answer that the string created 
in the heap memory can be changed,is it that the memory in 
the heap can be changed.I read it as heap provides a stable 
storage.Please clarify.Thanks in advance.
 
Is This Answer Correct ?    0 Yes 0 No
Ramya
 
  Re: 1).what is the difference between below examples String s="vijay"; String s=new String("vijay");
Answer
# 9
Hi All,
  Here one object is stored in the heap and you said that 
you can change that, but  bydefault String objects are 
immutable(ReadOnly), how can u change it?
 
Is This Answer Correct ?    0 Yes 0 No
Uday
 
  Re: 1).what is the difference between below examples String s="vijay"; String s=new String("vijay");
Answer
# 10
first one will create an object on the heap
second one will create two objects one will saved on the 
heap and another will get saved on the string pool
 
Is This Answer Correct ?    0 Yes 1 No
Ravikiran
 
  Re: 1).what is the difference between below examples String s="vijay"; String s=new String("vijay");
Answer
# 11
Guys please don't miss guide.

Karun you r absolutely right, but there is one big
difference between them

String s="vijay"; --> This is string literal

String s=new String("vijay"); --> String Object

Definitely first one gives the better performance than
second one, why because..

JVM maintains an internal list of references for interned
Strings( POOL of unique strings) to avoid duplicate string
objects in heap memory. when ever the JVM loads string
literals from class file and executes, it checks whether
that string exists in the internal list or not. If it is
already exists in the list then it does not create new
string and it uses the references to the existing String
object. JVM does this type by checking tinternally for
string literal but not for string object which it creates
through 'new' keyword

You can explicitly force the JVM todo this type of checking
for string objects which are created through 'new' keyword
using "String.intern()" method. This forces the JVM to check
the internal list and use the existing String object if it
is already present.
 
Is This Answer Correct ?    9 Yes 0 No
Ravi
 

 
 
 
Other Core Java Interview Questions
 
  Question Asked @ Answers
 
why interfaces are faster than abstract classes?  2
real time example for deadlock,starvation,livelock  4
Read data from console and print in one file. That would be in C:\temp ? Thanks, Bose Oracle1
write a progam hashmap & hashtable? IBM2
can abstract class have constructor how can you achive this ? Fidelity3
how can we import the user defined package without classpath?  1
why marker interfaces are there in java Digital-Group3
There are 2 classes, 1 LandAnimal and another WaterAnimal. There is another class Animal which wants to have the properties of both LandAnimal and WaterAnimal. How will you design this situation? KPIT3
What are the limitations for static method?  3
What is meant by class loader and how many types are there? Apple1
what is java Tech-Mahindra1
What is the difference between overloading and overriding a function? Infosys7
what are the oops concept in java explain with real time examples Tech-Mahindra4
What is exception and error? and what is the difference between them?  2
Features of Java?  4
can we create a instance for intwerface?  3
How do you set security in applets? Wipro1
What is casting?  3
How to create an instance of a class without using "new" operator? Plz help me out properly.Thank u. CSC8
Hi Friends, can you explain instance in java. In general instance means "occurence of something" . In java what is instance.  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