I would like to know what is the difference between 2 ways of declaring String as the example below:
String str = "Java String";
String str = new String("Java String);
Simply put, new String("Java String"); explicitly creates a new and referentially distinct instance of a String object;
String s = "Java String"; may reuse an instance from the string constant pool if one is already available.
So if you have already created a String object with the value of "Java String", no new String will be created here.