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

Which package is used for pattern matching with regular expressions?

851


what invokes a threads run() method? : Java thread

765


Are static members inherited to sub classes?

882


What do you mean by checked exceptions?

750


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

759


What is the effect of keeping a constructor private?

679


A person says that he compiled a java class successfully without even having a main method in it? Is it possible?

812


Define how does a try statement determine which catch clause should be used to handle an exception?

809


How to make a class or a bean serializable?

734


What is methodological framework?

784


What are streams?

851


What is OOP's Terms with explanation?

864


What is concurrent hashmap and its features?

758


What is method overloading in java ?

753


What is the difference between call by reference and call by pointer?

724