1).what is the difference between below examples

String s="vijay";

String s=new String("vijay");

Answer Posted / ravikiran

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 6 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Can sleep() method causes another thread to sleep?

562


Explain the term virtual machine?

590


Can singleton class be serialized?

511


Why is string buffer better than string ?

594


How do you join strings in java?

519






what is difference between equals and ==?

586


How variables are stored in memory?

535


How will you print number in reverse (descending) order in BST.

575


How do I get a substring?

523


What is exception propagation?

588


How do you sort a string in alphabetical order in java?

527


What is garbage collection? What is the process that is responsible for doing that in java?

647


How many bytes is a string java?

526


When throw keyword is used?

586


What is a variable simple definition?

575