July 21, 2009 at 11:32 AM
1) To save memory, java can refer two string references to the same underlying string object on the heap. So if you try to change the string object that refers to more than one reference, it can mess up your program.Therefore String objects are made immutable.
This provides better memory management.Generally thousands of string literals objects are created in any of the application.To avoid the individual memory allocation to all the string objects JVM creates the string literal objects in a dedicated string constants memory pool and allots the a same reference to all the string having the same value.
2) In Java,when you call a method,a copy of the value of each actual parameter is passed to the method and allows you to change that copy inside the method which does not cause any effect on the actual parameter.This explains that Java is Pass-by-value.