Memory usage for String as formal argument
We know that String is an immutable object, So when we pass any string value to a method call then, specifically, string is passed by value.
For example consider following example
**********************************************************example code**********************************************************
Class myClass
{
String lsName = 揌ello?
verifyVariable(lsName);
厖
//Do some processing
厖.
method2(lsName);
厖
//Do some processing
厖.
method3(lsName);
厖
//Do some processing
厖.
private void verifyVariable(String fsParam)
{
System.out.println(fsParam);
厖
//Do some processing
厖.
}//End Of verifyVariable
private void method2(String fsParam2)
{
厖
//Do some processing
厖.
}//End Of
private void method3(String fsParam3)
{
厖
//Do some processing
厖.
}//End Of
}//End Of Class
**********************************************************End Of example code**********************************************************
Query
1.In the above example decalring a final constant for String 搇sName?will help in utilization of memory Or Not? This constant is then passed to different method call. All the formal String argument will refer to one String Object.
The reason to ask this question is because as per my understanding of Java In above example , 4 different String objects are created
One for LsName, One for fsParam, One for fsParam2 and One for fsParam3
Is this understanding correct? As per my friend only two instance of String object is created, One for lsName and One for all other methods
2. Is there any way which we can measure the actual memory utilization by writing some java program for above example?
I really appreciate if you can answer my qbove queries.

