What is the overall advantage (in terms of memory management, etc.) of creating a separate constants file, like below class "Constants", over directly writing in Java file like stringVar.equals("name")
?
public final class Constants {
// Hide the constructor
private Constants(){}
public static String NAME="name";
}
I know that even if we write use "name" 2 times (as below), only one literal will be created in String pool?
stringVar1.equals("name")
and stringVar2.equals("name")