Java learning notes (1)

xiaoxiao2021-03-06  23

After learning Java for a while, I wanted to write the Dongdong you have learned. I will learn a summary of myself. I have to communicate with you. So I sincerely hope that everyone will point out I want Ferrated place!

One. Object

Oh, the scope of this title is too big. Here I just want to write my understanding and ideas to this.

Learning a new language is mainly to understand its way of thinking. Java is a pure object-oriented language, so understanding object-oriented thinking methods is a crucial head.

In "Thinking in Java", "Everything Objects", I am very likely to like this translation. Each thing in the world of Java is used and described in terms of objects. These objects have their own types (types), that is, objects are type other entities. For example, you see a cat on the ground, then this cat is an object (it is an entity). So what is the type? Is your mind in your mind is a definition of a cat, or how do you know that it is a cat, right.

These entities exist in the stack of the system or in the stack, although the concept is not mentioned in Java, but essentially access or sending messages for these objects or through pointers (can also be accessed through the address. Because the pointers, addresses and handles are almost the same stuff!). So in Java, it is used to use the concept of Reference to replace the pointer (Reference this word is not suitable translation), in "Thinking in Java", which is compared to the TV remote control (more objects to the TV), That is to say, access and control of the television (object) is performed by the remote control (Reference). Java makes you forget the pointer - this makes the C programmer's most proud of Dongdong, the purpose is to distinguish between the fuzzy objects and the Reference.

for example:

Cat mycat;

mycat = new cat ();

The first sentence above is declaring a Reference called Mycat, and also describing mycat is a cat (CAT) type Reference. The effect of the second sentence is to generate a CAT type object in the stack of the system, and let Mycat point to it. Since then, I have to access the object that has just been generated through mycat (now I can also say a variable, this variable is probably the object address or there have other information!). The "distinction between the fuzzy objects and the reference" is from this Java, I hope that you will treat mycat as an object (in the C language pointer variable access point to the "-> "symbol And the direct variable access member is used "." Symbol, and in Java is the same, I want the so-called "fuzzy" that this means.).

Oh, I don't know where I wrote. Now I will return to my head to continue talking about what is an object!

Simple object is the stuff with state, behavior, and type, which means that objects can have internal data (this makes the object have a state), there is a method (so objects can have behavior), as well as the same type of object You can accept the same message.

two. Interface and implementation

The interface mentioned here should not contact Java's keyword interface!

The interface describes a class that can be provided to the outside world, indicating what kind of behavior it can accept, what kind of message can be accepted.

Keyword interface is used to give a description of a group definition (of course, there are other definitions of constant groups), and do not implement code of the specific method. The class in Java can achieve any of the ports, which means a class can have a variety of features. In other words, you can look at the same thing with different angles (of course, this thing has multiple interfaces) This is a very magical feature in the Java world. For example, there is an object posing on the ground, look at it from the front, it is a cat (you can play it as a cat), from the back, look at it is a TV (you can use it as a TV) Of course, this example is a bit exaggerated, but this is fully implemented in the Java world, because this object can make the interface of the cat and TV, which makes this object at the same time have the skill of the cat and TV. Of course, this class can also achieve other methods other than these two interfaces to expand the functionality of this class. The interface just manages what message you can send to this object without implementing the code. The code implemented in the class and its hidden data constitute an Implementation.

The above says is a little dizzy, in short, the keyword class is to mix the interface and implementation in a module. The keyword interface only shows the interface (what), how to do it, let other classes Implementation (how to do). This provides a means of an interface on a level and a means of achieving separation. (Separation on the other level is to use polymorphism).

转载请注明原文地址:https://www.9cbs.com/read-40925.html

New Post(0)