2004-8-5? 23:20 ???? In fact, I have long I want to write an idea of learning a notes. Today, I finally decided to write, I wrote a bad place, everyone gave me correctly! In fact, it is a simplified version of Tij
The first chapter object introduction ?????? In fact, this chapter is OOP's idea. What is abstract, interface, inheritance, etc. In the future study, these knowledge will be integrated in it.
The second chapter is all objects ?????? In the Java program, all things are all objects, even the Java program itself is also an object ?????? 1, Reference is the key to the manipulation of the object ???? ???????? C language is the use of pointers to manipulate the object, but Java? It is used to manipulate the object, I am used to the relationship between his handle, handle, and objects, like the TV remote control and TV, which is the case, then the remote control and TV sets can be independent? ??????????, for example: string name; ?????????? This Java statement only creates a cake (remote control), does not produce actual objects (TV), If you want your wife, you haven't given your name before you haven't born your child, and the handle is not connected to the actual object. This look is not recommended, a handle that does not point to the object is called when the compiler will be wrong, should use string name = "baby"; or use string name = new string ("baby"); here New It means to generate a String type object, and this string is called Baby. These two methods can achieve the establishment of an object.
Second, all objects need you to build ?????? 1, store there ???????????? a, register? Here is the core storage space, we can't manipulate ????????????? b, stack (STACK) here is fast, high efficiency, because the data stored here is required to have specific size and survival time limit, use elasticity, usually store Is our object handle, and the object does not exist here ????????????? c, heap (HEAP) is a universal storage space, he is better than Stack, do not need to know Really store data in HEAP, nor does it know how long this space needs to be allocated, good elasticity, so it is used to store objects, but speed is much slower than stack ???????????? D, Static Storage Space This is a specific member stored as static. The Java object itself is not allocated here ????????????? e, constant storage space here is stored The constant in the program does not change, the safest ????????????? f, non-ram? Stream or persistent object ????? 2, basic data type ?? ?????????? BBOT DOUBLE SHORT INT Long Float double VOID? The basic data type data is not created, directly INT i = 0, does not use the Heap space, he is put in the stack Fast, fast! But if you want to store basic data types with Heap, you should use this type of overcraft 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 ???????????? Java uses and definition to be more secure than the array in C, when you define an array Is an array of stored object handles, and the value indicated by each handle is set to null, that is, does not point to any object, you don't need to destroy the object ?????? 1, basic type of living range? ????????????? Java's basic type of via is determined by a pair of braces, the variables defined in the living space can only be used for the end of the living space. "{?? ?????? INT i = 1; ??????? {?????????????? INT i = 100; // error! Such definitions are always not allowed in Java! The compiler will think I has been defined ???????} ???} ?????? 2, the survival range of the object ????????????? Life and basic types are different. When you use new to generate an object, even if you leave the braces, the object still exists ??? {??????????? String Name = New Sting ("Baby"); ???} ?????????? Handle Name will disappear outside the large brackets, but the String object he pointed to continues to take up memory. But everyone will think that a large number 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 objects, then what is the object of the object? By using the class.
Using the class key in Java to define a class ???????, for example: Class Women {// Class Body} This, you define a Women class, of course this class does not have any properties ??????? 1 , Data members and methods ?????????????? A class, there is a member, one is a data member, one is a method. The data member can be a basic data type or an object, and the basic data type is automatically given him an initial value five, method, parameter, return value when the system is declared. Method, parameter, return value ????????? The method includes name, parameter, return type, method such as ??????? Void Name (INT i) ?????? {?????????????? Return; ????????} where the name Name () ????? Parameter INT i ????? Returns the type VOID ???? Method {}, for a Class, name parameters The combination must be unique, the parameters can also be empty, there is a object called Test Allow you to call a return value to string method gettest (), then string name = test.gettest (); Name Type must be returned The value of the value is the same. ??????? When passing an object to a method, it is actually transmitted by the handle of the object (except for the basic data type), and the passable object type must be the same as the parameter type of the parameters in the method. When you don't need a method, you can set the return type of the method to Void, and the return in the method is used to leave the method, don't need to wait until he is executed, if the method returns When the type is not Void, you can use Return to return a value as the same value is not finished. . . . . . .