The first chapter object introduction is actually the idea of OOP, knowing what is abstract, interface, inheritance, etc., in fact, these I think there is no need to put it out to write a chapter, this will not introduce, in the future study In this knowledge, these knowledge will be integrated in it.
Chapter 2 Everything is in the Java program, all things are all objects, even if the Java program itself is, it is an object. Reference is the key C language that manipulates the object, but Java? It is used to manipulating the object, we are used to calling his handle, handle, and object relationships like TV remote control and television. Since this, the remote control and TV can appear independently. For example: String name; this Java statement will only generate handle (remote control), do not produce actual objects (TV sets), just like your wife has not given a child, you have gave a good name, and the handle did not Connect to the actual object. In fact, such a child write code is not recommended, a handle that does not point to the object will report an error while the compiler will use string name = "baby"; or use string name = new string ("baby"); here New It means to generate a String type object, and the object of this String type is called Baby. Both methods can achieve the establishment of an object. Second, all objects need you to build 1, store there, register: Here is the core storage space, we can't manipulate B, stack: here is fast, high efficiency, because The data stored here is required to have specific size and survival time limits, and the elasticity is small, which is typically stored in our object handle, and the object does not exist here. C, Heap: Here is a universal storage space, he is better than Stack is that the compiler does not need to know the size of the data in HEAP, and it is not necessary to know how long the space needs to be allocated, good, flexible, So use to store objects, but speed is much slower than Stack. D, static storage: This is a specific member that is usually stored as static, and the Java object itself is not assigned here. E, constant storage space: This is stored here that constants defined in the program, the constant value does not change, the safest. F, Non-Ram: Flow or lasting object.
2, basic data type Boolean char BYTE SHORT INT Long Float Double VoID Basic Data Type of data is created, direct int i = 0, do not use HEAP space, he is put in Stack, fast! But if you want to use HEAP to store basic data types, you should use this type of external class to implement, for example, Integer i = new integer ("0"); note! String is not the basic data type, she is an object! You can know from his definition method! 3, array (array) Java uses and definitions to be more secure than the arrays in C, actually generating an array of storage object handles when you define an array, and each handle pointing Set to NULL, that is, not point to any object. Third, you don't need to destroy the object 1. The basic type of basic type in Java is determined by a pair of braces, the variable defined in the living space, only for the end of the living space before {INT i = 1 ; {INT i = 100; // Error! Such definitions are always not allowed in Java! The compiler will believe that I has been defined}} 2. The life of the object's living range object has the life and basic type. When you use new to generate an object, even if you leave the braces, the object is still The existing {string name = new sting ("baby");} The handle Name will disappear outside of the vacted space of the braces, but the String object he pointed to continues to take up memory, but everyone will think that a lot of useless Objects will occupy a lot of memory, how is Java solved? He uses garbage collection mechanisms, and the garbage collector will check the object created in a specific time. If these objects have no handle points to them, then he returns the useless object to clean up. Fourth, establish a new data type Class Java, is everything is all object, then what is the ability to limit the object of the object? By using the class. Java uses the class key to define a class, for example: Class Women {// Class Body} This defines a Women class. Of course, this class does not have any properties 1, and there are two members in a class, there are two members. One is a data member, one is a method. Data members can be basic data types, or objects, and the basic data type will automatically give it an initial value when the system is declared. V. Method, parameter, return value A legal method includes name, parameter, return type, method body such as Void Name (INT i) {return;}