Basic Structure of Java
1. Each Java program can contain multiple class definitions, but only one class can be public, and the Java source file must be named after the public class.
2. about package Introduction: (1) Although the ". ", can reflect the hierarchy of the middle of each package, but each package is independent, the top package does not contain classes in the sub-package. (2) The order of package and import is fixed, and the package statement must be in the first line.
3. the Java language requires that the storage path of the Java source file correspond to the package name declared in the file. For example, the monkey class in monkey. Java is located in the HgS. Angel package. Correspondingly, the monkey. Java file is located in the HgS/Angel subdirectory of the src directory.
4. method override and method overload: (1) override requires that the parameter signature be consistent, and method overload requires that the parameter signature be different (2) method override requires that the return type be consistent, method overloading does not require this (3) method coverage has special requirements on the method access level and thrown exceptions.
5. polymorphism (1) for a variable of the reference type, the Java compiler processes it according to the declared type. example: base who = new sub (); WHO. subvar; WHO. submethod () errors occur when using subclass attributes and methods. (2) for an object of the reference type, the Java VM processes the object based on the Type it actually points. creature c = new dog (); animal A = (animal) C; // normal, C actually points to the dog object DOG d = (DOG) C; // normal cat = (CAT) C; // The dog object cannot be converted to a cat object. (3) Java allows a type of reference variable to reference the subclass instance, and can convert the type of the referenced object (see (2 ), according to the actual pointing object type ). (4) binding rules: ● bind the instance method to the instance method of the actually referenced object; ● bind the static method to the static method of the declared type; ● variable (member/static) bind to declared variables.
6. = & Equal: = when both sides are referenced objects, the same object must be referenced and the result is true. ● The equal () and = of the object are the same, ● In the JDK library, some classes overwrite the object method. If the two object types are consistent and the content is consistent, true is used.
7. An instance of a class can be seen as an instance of the direct parent class and indirect parent class. m instanceof object must be true.
8. abstract ● modifier class, which indicates an abstract class and cannot be instantiated; modifier, which indicates an abstract method and does not provide specific implementation. ● There can be no abstract methods in an abstract class, but there must be an abstract class in an abstract method. ● An abstract class cannot be instantiated, but a reference can be created to reference an instance object of a non-Abstract subclass. ● abstract and static
9. final ● The final class does not allow sub-classes, methods cannot be overwritten, and classes are not extended; ● The final method does not allow the quilt class method to overwrite; ● The final variable indicates a constant, values can be assigned only once.
10. Static ● static modifier variable, static variable; ● static modifier method, static method; ● static modifier program code block, static code block. When the Java Virtual Machine loads a class, the code block is executed.
11. static variable ● when the Java Virtual Machine loads a class, it will allocate memory to the static variables and only allocate memory once. Each static variable has only one copy in the memory. ● For instance variables, each time an instance is created, the memory will be allocated once. instance variables can have multiple backups in the memory, which does not affect each other.
12. static Method ● because a static method can be called directly without the instance of the class to which it belongs, the static method cannot use the reference keyword this of the current object, you cannot directly access the instance variables and methods of the class. You can only directly access the static variables and static methods of the class. ● instance methods can access instance methods, instance variables, static methods, and static variables.
13. Static code block: A class can contain static code blocks. It does not exist in any method body. When loading classes, Java virtual machines execute them in sequence as they appear in the classes.
14. java allows one constructor to call another constructor using this, but it must follow the following rules: ● this must be the first statement of the constructor; ● you can only use this to call other constructors.
15. default constructor: constructor without parameters. If one or more constructor is defined for a class with parameters, the class will lose the default constructor.
16. The subclass constructor calls the parent class constructor: ● it can only be called through Super ● The Calling statement must be placed in the first statement in the constructor.
17. finalize (): The program cannot fully rely on the finalize () method of the object to complete the final work, but should complete the final work in the method that is sure to be executed. through programming, garbage collection is affected, although programmers cannot control JVM's garbage collection mechanism. However, it can be affected by programming, so that the object meets the garbage collection conditions. There are several differences: ● assign null values to useless objects. ● Assign a value to the referenced variable again. For example: person P = new person ("AAA"); P = new person ("BBB"); in this way, new person ("AAA ") this object is garbage ---- it meets the garbage collection condition. ● Let the interconnected objects be called "island" objects person p1 = new person ("AAA"); person P2 = new person ("BBB "); person P3 = new person ("CCC"); P1 = P2; P2 = P3; P3 = p1; P1 = NULL; P2 = NULL; P3 = NULL; before null is set for P1, P2, and P3, there is a triangular relationship between them. If they are set to null, the love triangle still exists, but the three variables are not used. The three person objects form an isolated island and finally die on the stack. ● Forced garbage collection system. GC (), runtime. GC () is actually mandatory here. It is the programmer's will and suggestion. When to execute it is the JVM's garbage collector. Calling garbage collection does not necessarily ensure that unused objects can be deleted from the memory. The only guarantee is that the Garbage Collector runs once before the program throws an outofmemaryexception in rare cases.
18. java parameter transfer method: http://hi.baidu.com/mltong2008/blog/item/b73a434b8ec837f783025c38.html ● pass basic type: type value ● pass reference: Pass reference address value, if the referenced object is changed in the function, it will be similar to passing the value... when an object in Java is passed as a parameter, the address of the object in the memory is copied to the parameter.
19. automatic Call of the default constructor of the parent class: the constructor of the Child class does not use the super () statement to display the constructor of the parent class. When this method is used to create a child class object, the Java virtual machine automatically calls the default constructor of the parent class. if the parent class does not provide the default constructor, a compilation error occurs.
20. this, super Keyword: overwrite the default scope of the Java language to make the blocked methods and variables visible. ● integration: the local variables in the method have the same name as the member variables of the class. ● Scenario 2: A subclass method overwrites the method of the parent class. Scenario 3: The subclass defines the member variables with the same name as the parent class.
21. Internal Summary: http://www.cnblogs.com/jerrychoi/archive/2010/03/12/1684394.html.
22. member variables are parsed during compilation; member functions are parsed at runtime.