Some basic concepts of java

xiaoxiao2021-03-06  58

Recently, I want to see the book, I understand the basic concepts of Java, in fact, I have seen it before, but I am swallowing my jujube. However, when the temperature is new, learn this should be to understand the deepening process. The main book is "Java 2 Reference Daquan" and "Java 2 Core Technology: Principle"

Java fundamental concept. The character type mainly revisits the number of bytes occupied by various character types. Short Short Total 16-bit 2-byte int integer 32-bit 4-byte long long integer 64-bit 8-byte floating point sized precision float and double precision Doublefloat single precision 32-bit 4-byte double double precision 64-bit 8 words Festival

This is more special. Java is not an ASCII character, nor is an extended 8-bit character set, but a Unicode character set, a Unicode character occupies 16 bits, 2 bytes, which can represent all the characters found by human beings, because so Java It can be more convenient to carry out internationalization, I don't know if this understanding is problematic. In fact, the value of Char is a integer (0-65536), so we assign a value to the char to use an integer or a character in the unicode text format format, which is this 16-bit Unicode The nine-bit Nine-bit Unicode characters of 0: One byte 1 Unicode character: Two bytes: three bytes corresponding to the prefix code: 0xxxxxx ASCII code 10xxxxx second or third byte 110xxxxx The first byte of the two-byte sequence 1110XXXX three-byte sequence in the first byte

two. Category and objects: Class is a logical structure, objects have physical entities. That is to say, the class does not occupy the memory space, the object occupies a certain memory space. This problem can be described from the acquisition of the class object. Box abox = new box (); actually this process is divided into two steps box abox; abox = new box (); the first step is to create an object, returning ABOX is a reference to an object. The second step is to call the constructor, allocate memory space for the object, returning the reference to this memory address, which is assigned to Abox. How is the constructor work? The constructor does not return a value because its implicit return type is the class itself. The default constructor automatically initials all instance variables to 0. Example variables are data or variables defined in a class, and members of the class are the methods and variables defined in the class.

Quote is a very interesting thing. Box a = new box (); box b = new box (); This time A and B correspond to their respective memory addresses, if A = B; this time A, B is pointing to the same memory address, ie B's memory address. That is to say, the value of the variable of the value B of the member variable in A is now changed; if the value of the member variable in B is changed, the corresponding variables of A will change. Quote is just a memory address.

There is a word in the class called abstract classes, and there are many meanings and details of abstract classes. Classes containing abstract methods must be declared as abstract class 2. Abstract classes must be covered in subclasses, otherwise they must also be declared as abstract class 3. Abstract classes can't have objects, can't get a abstract class will be exemplary 4. Abstract classes can have an abstract method or have a specific method 5. Abstract classes can create objects to reference article 5 is very useful, you can achieve polymorphism. Li Gong's brother explains the factory method in the design model is also a super-class variable of abstract classes to reference different sub-objects. Since the interface does not implement its own method, if a class does not implement the method in the interface, it must be defined as an abstract class.

three. The interface interface only defines the method name, but does not implement the method. The interface can declare the variable, but these variables will be implicit, ultimately, static, cannot be changed by a class that implements the interface. Therefore, the shared constant can be defined in the interface and then import into multiple classes. You can use the interface reference to call the implementation, what does this mean? {public void call (int p) {}}

Class Client Implements Callback {Public Void Call (INT P) {

}

}

Public static void (string arg []) { Callback C = new client (); c.call (1);

Note that the black body part of the black body () Callback C = New Client () creates a client object, but declares that the interface type, which means that c just know the method of the interface Callback, what is other than the CLIENT class that implements this interface Method, C is not known. This has some similar superclass reference subclassics. It is very useful to implement polymorphism. Many classes that implement this interface can be called with reference to the same interface.

VI. Access control

5. Some reserved words Meaning and use Static: Members of general modified classes, allowing such members to be used independently of any object, using class names. Note: 1.Static method can only call other Static method 2. You can only access the STATIC data 3. This or Super is not called in any way. (Still don't understand why)

THIS: You can use this in any method to call the current object, this is always a reference to the current object. This can be used for instance variables to hide so-called instance variables hidden, that is, when a local variable is with an instance variable, instance variables are hidden. For example, the constructor of Box (Double Awidth, Double Aheight, Double AWIDTH) {width = awidth; height = ahant; defth = adepth;} If the parameter is width, height, depth, these local variables will be and class The member variable is the same name, and the instance variable is hidden at this time. But this can avoid this. Box (Double Width, Double Height, Double Depth) {this.width = width; this.height = Height; this.depth = depth;} This direct reference object, you can solve the problem of name space, namely local variables and classes The problem of the same name of the variable. (This needs again think about it)

SUPER: There are two main uses 1. Super (parameter_list) calls the superclass constructor, but this must be the first statement of the subclass constructor. What is interesting here is how the subclass constructor calls a superclass constructor; in fact, the constructor is called in accordance with the class derived order. 2. Super.member This time is a method or instance variable that calls a superclass as an overlayer object.

Final: modified variables, methods and classes. Final variable: The content of the variable cannot be modified FINAL method: The method cannot be reloaded Final class: Class cannot be inherited

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

New Post(0)