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

Which is the best sorting technique in java?

932


Can we create our own wrapper class in java?

914


Is java 1.7 the same as java 7?

990


What is meant by string is immutable?

1001


Is constructor inherited?

915


why an outer class cannot be declared as private?

4226


Where is jre installed?

983


Explain about the main() method in java?

1021


How many types of keywords are there?

941


how to open and edit XML file in Weblogic???

1931


What is static method with example?

1096


What happens if a try-catch-finally statement does not have a catch clause to handle an exception that is thrown within the body of the try statement?

1040


What is ascii format?

944


How do you sort arrays in java?

880


Hi i am creating desktop application in that i want calling to mobile number. i have java telephone api (JTAPI) but i dont understand how it configure & use plese help me

1807