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

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What do you mean by multithreaded program?

777


Which eclipse is best for java?

762


Is java a software?

721


How to declare objects of a class ?

827


What are the concepts of 'OOPS'?

837


Give an example of use of pointers in java class.

775


How to sort a collection of custom Objects in Java?

837


What is the difference between sop and work instruction?

710


Does java set allow duplicates?

785


Compare Mutex and Semaphore in java.

775


Explain creating threads by extending thread class ?

781


Do we have pointers in java?

730


What does s mean in regex?

785


Describe how to implement singleton design pattern in struts.

779


can I implement my own start() method? : Java thread

765