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
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 |
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 |
Explain the access modifiers for a class, method and variables?
What is a java predicate?
what is the difference between thread and runnable types? : Java thread
Explain the difference between treeset and treemap in java?
Difference between static synchronization vs. Instance synchronization?
What is close method? How it's different from Finalize & Dispose?
0 Answers InfoAxon Technologies,
What is variable and constant explain with example?
Name the methods that used to get and set the text label displayed by a Buttonobject?
What primitive Java types? Howmany are they and what are their names?
What if constructor is protected in java?
What is an Applet ?
What is the gregoriancalendar class in java programming?