Each typeProgramming LanguageThey all have their own ways to manipulate elements in the memory. SometimesProgramYou must note the type of data to be processed. Are you directly manipulating elements or using some indirect representation based on special syntaxes (for example, pointers in C and C ++) to manipulate objects.
All of this in Java is simplified. Everything is regarded as an object, so a single fixed syntax can be used. Although everything is regarded as an object, the operated identifier is actually a reference of the object ). You can use the reference view as the remote control and the object as the TV. You only need to hold the remote control to maintain the connection with the TV. When someone wants to change the channel, the actual control is the remote control (reference), and then the remote control controls the TV (object ).
In addition, even if there is no TV, the remote control can exist independently. That is to say, if you have a reference, you do not need to associate an object with it. For example, if you want to manipulate a word or sentence, you can create a string reference.
String S;
Here, only references are created, not objects. If a message is sent to s at this time, a runtime error is returned. This is because s is not actually associated with anything (that is, no TV set ). Therefore, a secure approach is to create a reference and initialize it at the same time.
String S = "ASDF ";