[JAVA] String literals and instances

(New engineer Fugi and you. I think I'm writing Java code today)

An instance of the String class

"... and it's about time to make a string with the String class"

String string1 = "Hello";
String string2 = new String("Hello");

"I tried to change the writing style with playfulness." "This will make my seniors laugh!"

To seniors

"Senior, I wrote the code, so please take a look." "It's funny" "Hmm, which one ...?" "Oh?" "Are you different from Puyi and you don't understand this difference?" "...? What's the difference?" "Differences in how to initialize the String class" "Difference ... Both have an instance of the String class. Is it different from making it? " "It can be said that it is, and it can be said that it is not." "One is a literal, the other is an instance."

 String string1 = "Hello"; // Literal
 String string2 = new String ("Hello"); // Instance

"Eh" "Really"

Invoking senior Gachilek

"What is the new character string?" "I'm in the heap area of memory" "Heap area ...? (; ^ Ω ^)" "Roughly speaking, it feels like a'material storage'." "It's a good idea to put the data necessary to execute the program." "Ah, I see." "I'll go back to the story." "For the new character string to be placed in the heap area" "After the string created by the assignment operator is placed on the heap" "The reference is registered in a string literal pool" "Mojiretsu Literal Pool?" "Saya" "The next time the same string that was registered here is created" "The program is a string of strings registered in a string literal pool. Return a reference and create a new instance. " "I understand somehow." "If you do the same string, you will use the same instance again, right?" "Well, if you say it, that's right." "In the first place, creating an instance is for a computer. It ’s a tough job. ” "Since, the String class that I often use does that hard work. I think I'll be able to do as much as I can. " "Hohe" "I learned" "Thank you (* ´ω `)"

reference

https://it-trend.jp/development_tools/article/32-0041 Takashi Kawaba "Java Object-Oriented Thorough Explanation" (Shuwa System)

Recommended Posts

String literals and instances
Classes and instances
[Ruby] Classes and instances
String and stringbuffer and string builder
About classes and instances
[Java] String comparison and && and ||
Ruby classes and instances
java (classes and instances)
[Java] About String and StringBuilder
String concatenation and line breaks
About classes and instances (evolution)
Consideration about classes and instances
About Ruby classes and instances
Creating Ruby classes and instances
String, heap area and constant pool
Writing code with classes and instances
Organize classes, instances, and instance variables
String
Studying Java 8 (String Joiner and join)
Classes and instances Java for beginners
String operations this and that-Java edition-
Azure Container Instances! Lightweight and explosive container usage!
Java programming (classes and instances, main methods)
Memorandum (Ruby: Basic Grammar: Classes and Instances)
Write code using Ruby classes and instances