concept String object in category java

This is an excerpt from Manning's book Java SE 11 Programmer I Certification Guide.
As a result, Java creates a String object with the value "Harry" in the pool of String objects referred to by the variable str3. This action is depicted in figure 5.4.
Figure 5.4 The sequence of steps that executes when Java is unable to locate a String in a pool of String objects
![]()
When the following line of code executes, Java can find a String object with the value "Harry" in the pool of String objects:
String str4 = "Harry";Java doesn’t create a new String object in this case, and the variable str4 refers to the existing String object "Harry". As shown in figure 5.5, both variables str3 and str4 refer to the same String object in the pool of String objects.
Figure 5.5 The sequence of actions that executes when Java locates a String in the pool of String objects.
![]()

This is an excerpt from Manning's book OCA Java SE 8 Programmer I Certification Guide.
String objects that are created using the assignment operator (=) are stored in a pool of String objects, but String objects that are created using the operator new aren’t stored in the pool of String objects.
As a result, Java creates a String object with the value "Harry" in the pool of String objects referred to by the variable str3. This action is depicted in figure 4.3.
Figure 4.3. The sequence of steps that executes when Java is unable to locate a String in a pool of String objects
![]()
When the following line of code executes, Java is able to find a String object with the value "Harry" in the pool of String objects:
String str4 = "Harry";Java doesn’t create a new String object in this case, and the variable str4 refers to the existing String object "Harry". As shown in figure 4.4, both variables str3 and str4 refer to the same String object in the pool of String objects.
Figure 4.4. The sequence of actions that executes when Java locates a String in the pool of String objects
![]()
Figure 4.4. The sequence of actions that executes when Java locates a String in the pool of String objects
![]()