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
What must a class do to implement an interface in java programming?
What is private static in java?
How many types of parsers are there?
What is compiler and what its output.
What is externalizable?
What is the difference between an argument and a parameter?
Can a top level class be private or protected?
What are annotations in java?
Is treeset sorted in java?
How do you bind variables?
What is public static?
Explain about transient variables in java?
What are the two types of streams offered by java 8?
Why arraylist is not synchronized in java example?
Explain the JDB in depth & command line.