Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

1).what is the difference between below examples

String s="vijay";

String s=new String("vijay");

Answer Posted / ravi

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 ?    26 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

take an array with -ve and +ve value both.find out the nearest value of 0(zero).if two values are same like(-2 and +2)then extract +2 is nearest of 0(zero).

1949


how to create daemon thread in java?

1023


What is void class in java?

936


What is the set interface in java programming?

1164


What is the list interface in java programming?

1063


What do you understand by Header linked List?

1058


What is a short in java?

994


Is java written in c?

929


What is the relationship difference the canvas class and the graphics class?

1031


What is the major drawback of internal iteration over external iteration?

986


What is the size of integer?

1075


What is a class reference?

1056


What are thread groups?

961


Is arraylist sorted in java?

963


what are the states associated in the thread? : Java thread

1022