difference between String a; and String a=new String();?
y do v need to assign memory to the variable?

Answers were Sorted based on User's Feedback



difference between String a; and String a=new String();? y do v need to assign memory to the variab..

Answer / saroj kumar biswal

String a;
jvm creates a reference & allocates memory for storing hashcode value

String a=new String();
jvm creates a object to String class in heap memory & returns the unique hexadecimal equivalent of that memory location which is stored in reference variable a as hashcode.

We dont need to assign memory to variable.because in java memory management is taken care by jvm automatically.Programmer need not worried about memory allocation issue.But yes jvm allocates memory for variable to store hashcode, if it is a referenced variable.If it is primitive type variable then jvm will not allocate extra memory for that variable.Because primitive types stored in object & there is memory allocated for object by jvm.

Is This Answer Correct ?    5 Yes 0 No

difference between String a; and String a=new String();? y do v need to assign memory to the variab..

Answer / janardhan

String a; :---

JVM will create String object in SCPM(String constant pool
memory)only.

String a=new String();:---

JVM will create String object in two memories
1. Heap memory
2. String constant pool memory.

Is This Answer Correct ?    2 Yes 1 No

Post New Answer

More Core Java Interview Questions

What is java command?

0 Answers  


How to check if a list is sorted in java?

0 Answers  


What is method Overloading in the perspective of OOPS?

6 Answers  


Why does my function print none?

0 Answers  


What are the supported platforms by java programming language?

0 Answers  






Define Compiling?

3 Answers  


what are class,constructor and primitive data types?

2 Answers   IBM,


Can an abstract class be final?

10 Answers  


What is the difference between overriding & overloading?

0 Answers  


Question 6 [9] 6.1 In what situations (in general) would you use a TreeMap? (3) 6.2 In what situations (in general) would you use a HashSet to store a collection of values?

1 Answers  


What is multithreading ???? How to stop multithrading in java????

1 Answers   Cognizant,


What is the difference between stringbuffer and stringbuilder class?

0 Answers  


Categories