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 is the escape character in java?

509


What is passing value java?

506


What are basic data types?

559


Why chararray() is preferred over string to store the password?

524


what is synchronization? : Java thread

561






What is difference between path and classpath variables?

563


Explain inner classes ?

645


Why lambda expression is used in java?

568


Write a program to find maximum and minimum number in array?

550


How to handle a web browser resize operation?

541


Can we override protected method in java?

578


Why hashset is used in java?

532


Can a source file contain more than one class declaration?

510


What is the difference between iterator and enumeration ?

510


what do you mean by marker interface in java?

541