1, the basic structure of memory in Java:
Stack: A reference to a local variable or object;
Heap: Something new comes out (object)
Method Area: constant pool, etc.
Static domain: global variables, etc.
The variable will be out of the stack at the end of its life cycle, and the space in the heap will be reclaimed by the system because there are no variables in the stack to reference it
2. Types of variables in Java: 1) by data type: base data type & Reference data type
2) vary by declaration location: member variables & local Variables
3. The difference between a member variable and a local variable:
--different declaration positions;
--Modifiers for member variables: public, private, protected, default
Local variable has no modifier (same as the method modifier);
--local variables must be initialized before they can be used (no default value)
If the member variable is not initialized, the default value is assigned according to the type of the variable;
--local variables exist in the stack space in memory
The member variable exists in the heap space (the reference to the class where the member variable resides is in the stack space);
4, variable number of formal parameters
--Example:
1 Public void print (String ... args) {2 for (int i = 0; i < args.length; i++) {3 System.out.println (Args[i]); 4 }5 }
Note: If there is a variable number of formal parameters in the method, it must be declared at the end of all parameters, that is, a method can only declare a variable number of formal parameters.
Personal understanding: This variable number of arguments is consistent with the array, so you can pass in an array directly when calling the method.
5. Parameter passing mechanism: parameter Passing in Java is a value pass.
Personal understanding: Regardless of whether the pass is a basic data type or a reference data type, the method is called to pass the value of the argument to the parameter, rather than passing the argument directly into the method.
6, modifier of the class is only public or default.
7, about the This keyword: note 1) This () must be written in the first row of the constructor, 2) at least another constructor does not use this ();
8, Javabean:1) type is public
2) There is a public constructor with no parameters
3) There is a property, and there is a corresponding get, set method.
9, Package: Declare the source file is in the same packet, written in the first line of the program.
10. Import Static ...: Imports the static property or method that formulates the class.
11. Java only supports single inheritance.
12, polymorphism premise: 1) There is an inheritance relationship; 2) subclasses must have overrides to the parent class method.
Personal understanding: When instantiating an object of the parent class, if new is its subclass, only the overridden method in the subclass can be called and no other method in the subclass can be called.
13, object A instanceof Class A to determine whether the object A is an instance of Class A, if return true, and vice versa return false.
Note: If true, object A must be an instance of the parent class of Class A.
14. The polymorphism of the subclass object does not apply to the attribute, not to the method.
15, for each basic data type, there is a corresponding wrapper class, because after JDK5.0 added the characteristics of packing and unpacking, so there is no need to wrap the class of various methods to achieve with the basic data type conversion.
When allowed, the method can also be used to convert (such as Integer integer = new Integer (5), int i = Integer.intvalue ()).
16. Static can be used to modify properties, methods, blocks of code (or initialization blocks), inner classes.
17. The static modified property becomes a class variable that exists not dependent on the object and is loaded as the class is loaded (as is the case with static methods). This corresponds to an instance variable, which exists only after the object has been created.
18. It is possible to use this class of static properties or methods within a static method, but not a non-static property or method. Conversely, a non-static property or method can call a static property or method.
Personal understanding: A static property or method is created when the class is loaded, not a static property or method that is created only after the class instantiates the object. And the life cycle of a static property or method is also longer than non-static.
19. Five members of a class: properties, methods, constructors, code blocks, inner classes.
20, about the property assignment operation: 1) default initialization, 2) display initialization or code block initialization (executed sequentially), 3) constructor assignment, 4) method assignment.
21. The final tagged class cannot be inherited; The fianl tag method cannot be overridden by a quilt class; The final tag's property can only be initialized once, and this property is a constant, usually named in uppercase letters.
Constants cannot use default initialization, assign values that can be displayed, or assign values in code blocks, constructors. The static final modified variable is a global constant.
22, abstract class: 1) can not be instantiated, 2) has a constructor, can be used by subclasses. 3) The class in which the abstract method resides must be an abstract class.
If a class inherits from an abstract class, you must override the abstract method in the abstract class.
23. Abstract class instances created by polymorphism can only invoke methods that have been overridden by subclasses.
24. Interface is a set of definitions of abstract methods and constant values; An interface is an abstract class of custom, containing only the definitions of constants and methods, without the implementation of variables and methods.
--A class can implement multiple interfaces (because Java is single-inheritance, so the interface can achieve multiple inheritance effects).
--The interface defines a feature that can be implemented by all classes.
--the interface does not have a constructor, so the interface cannot be instantiated.
--interfaces can inherit other interfaces, and can implement multiple inheritance.
25, the interface and the specific implementation of the class also exist polymorphism.
26, the interface can implement anonymous class objects. Example: Onclicklistener OCL = new Onclicklistener () {
void OnClick (View v) {}
};
27, Interface Summary: 1) Through the interface can achieve the same behavior of unrelated classes, and do not need to consider the hierarchical relationship between these classes;
2) Through the interface can indicate a number of classes need to implement methods, generally used to define the object's expansion function;
3) interfaces are primarily used to define specifications. Contact coupling relationship.
28. Inner class:
--Classification: 1) member inner Class (outside method), 2) Local inner class (method).
--The inner class is a member of an external class with a modifier (4), which can be modified with the static final, using the properties and methods of the outer class.
--Instantiation of an inner class of a non-static class: Instantiate an Outer class object, and then instantiate the inner class by invoking the constructor of the inner class.
Java Notes--basics