1. Features of object-oriented thinking
(1) is a more consistent with our thinking habits of thought (lazy thinking, I do not do things themselves, to others to do)
(2) complex things can be simplified (simple for the user, the object is still very complex)
(3) The role has been transformed, turning us from performer to conductor
(4) is constantly creating objects, using objects, directing objects to do things. (If there is an object, directly with the object, directly to us to provide services)
2. Object-oriented features
(1) Package
(2) Inheritance
(3) polymorphic
3. Class-To-object relationships
(1) A class is a set of related properties and behaviors (all students in our class have the same attributes and behaviors, such as: Name, age, and study, so that all pupils become students)
(2) The object is the specific embodiment of such things (say a classmate, he has his own unique attributes and behavior)
(3) A class is abstract (extracting the same, similar part of the same thing as the abstract), or the class is generic, and the object is special.
(4) A class can contain member variables, class variables, member methods, class methods, constructors, construct code blocks, static code blocks, and so on
4. What is the difference between a member variable and a local variable?
(1) Different positions in the class
A. Member variable: Outside of the method in the class
B. Local variables: In the method definition or on the method declaration
(2) different locations in memory
A. Member variable: In heap memory (member variable belongs to object, object into heap memory)
B. Local variables: in stack memory (local variables belong to method, method into stack memory)
(3) Different life cycle
A. member variables: As objects are created and disappear as objects disappear
B. Local variables: As the method is called, it disappears as the method's call is complete
(4) different initialization values
A. Member variable: default initialization value
B. Local variables: There is no default initialization value, which must be defined and assigned before it can be used.
Features of 5.private Keywords
(1) encapsulation refers to the properties of hidden objects and implementation details, only provide public access, private is to implement a form of encapsulation
(2) Private is a permission modifier that can modify member variables and member methods
(3) A member that is modified by private and can only be accessed in this class
(4) When the member variable is modified by the private keyword, the corresponding get and set methods need to be provided for external access
6. Talk about your understanding of this?
(1) This can only represent such objects
(2) This represents the object to which the function (method) belongs
(3) Who will call me, I will represent who
(4) This can be used to differentiate between member variables and local variables with the same name
1. What are the characteristics of the construction method?
(1) The main function of the construction method is to initialize the properties of the object.
(2) The method name is exactly the same as the class name, there is no return value type, not even void
(3) The construction method is also a method, only a special, is called immediately after the creation of the object, late can not be called alone, since it is the method, you can overload
A. Method name is the same
B. Different parameter list (different quantity, different order, different type)
C. Regardless of return value type
(4) If the custom class does not provide a construction method, the system will automatically provide a non-parametric construction method, if we give a construction method, the system will no longer provide a default parameterless construction method, if you want to use the null parameter construction, you must display the
The process of creating an object in 2.java?
(1) Load the class's bytecode file into memory
(2) Declaring a reference to the class type S
(3) Creating objects in heap memory,
(4) Default initialization value for property in Object
(5) Property for display initialization
(6) Construct method into stack, assign value to attribute in object, construct method stack
(7) Assigning an object's address value to s
3. Talk about your understanding of the static keyword?
(1) A member that is modified by the static keyword, the shared content belonging to all objects in the class can be called directly with the class name, or it can be called with the object, but is recommended to be called with the class name
(2) Loaded with class loading, takes precedence over object existence: loaded with bytecode files, there were no objects at that time.
(3) Static modified content generally we call it: Class-Related, class member (static variable: class variable, static method: Class method)
(4) There is no this keyword in a static method (because this refers to a specific object and static does not have a specific object when loaded into memory)
(5) Static methods can only access static member variables and static member methods, non-static member methods can both method static member methods and member variables, but also access non-static member methods and member variables
Simple memory: Static cannot access non-static
4. What is the difference between a static variable and a member variable?
(1) different
A. Static variables belong to classes, so they are also called class variables.
B. member variables belong to an object, so also known as instance variables (object variables)
(2) different locations in memory
A. Static variables stored in the static area of the method area
B. Member variables stored in heap memory
(3) Memory occurrence time is different
A. Static variables are loaded as the class is loaded and disappear as the class disappears
B. Member variables exist as objects are created and disappear as objects disappear
(4) Call different
A. Static variables can be called through the class name, or through object invocation
B. member variables can only be called by object name
1. What are the categories of code blocks?
(1) Constructing code blocks: Execute each time the construction method is executed
(2) Static code block: Executes as the class is loaded and executes only once
(3) Local code block: the code block defined inside the method is called a local code block, which executes as the method executes
(4) Synchronizing code blocks: in multi-threading in order to resolve thread safety issues
2. What about your understanding of inheritance?
(1) Inheritance allows a relationship between a class and a class, and a child parent class relationship
(2) Inheritance improves the reusability and maintainability of code, and increases the coupling between classes and classes.
(3) Java only supports single inheritance, does not support multiple inheritance, but Java supports multiple layers of inheritance
(4) Matters needing attention in succession:
A. Subclasses can only inherit all non-private members of the parent class (member methods and member variables)
B. Subclasses cannot inherit the constructor of the parent class, but can access the parent class construction method through the super (immediately speaking) keyword.
C. Do not inherit for part of the function
(5) When creating an object, all constructor methods in the subclass will access the constructor of the parent's hollow parameter by default
A. Because subclasses inherit data from the parent class, they may also use the parent class's data, so before subclasses are initialized, it is important to complete the initialization of the parent class data.
B. In fact: The first statement of each construction method is by default: Super () the top-most parent class of the object class.
(6) The parent class does not have a parameterless constructor method, what about the subclass?
A.super Solution: With super (...) Explicit invocation of the parent class of the structure, such as: Super (Name,age);->super ("Zs", 30);
B.this Resolved: This class is called through the argument structure, and then in this class of the structure of the argument, and called the parent class of the parameter structure, equivalent to indirectly call the parent class of the argument constructs.
C.super (...) Or this (...) must appear on the first statement of the constructor method, only one
(7) member method relationship in succession?
A. Methods of different names: direct invocation can
B. Methods with the same name: Called method overrides, which are called directly by subclass objects, are methods that have been overridden by subclasses
C. To invoke the method of the parent class, you can add super () in the method overridden by the subclass;
3. Talk about your understanding of this and super keywords?
(1) This: represents the current object reference, who calls me, I represent who
(2) Super: A reference representing the parent class of the current object
(3) The use difference between this and super
A. Calling member variables
* this. member variable calls the member variable of this class, or you can call the member variable of the parent class
* Super. Member variable calls a member variable of the parent class
B. Calling a constructor method
* This (...) Calling this class's constructor method
* SUPER (...) Calling the parent class's constructor method
C. Calling member methods
* this. The Member method calls the member method of this class, or it can call the method of the parent class
* Super. Member method calling the parent class
4. What are the overloads and overrides of a method?
(1) Overloading: In the same class, the method name is the same, the argument list is different (the number is different, the type is different, the order is different), multiple methods that are independent of the return value type are overloaded
(2) Rewrite: In the inheritance, the child parent class appears the same way (note: The return value type can be the child parent class, this we learned the object-oriented speaking), when the subclass needs the function of the parent class,
A method in a parent class can be overridden when a functional principal subclass has its own unique content. In this way, the function of the parent class is inherited, and the content specific to the subclass is defined.
(3) Notes on rewriting:
A. Private methods in the parent class cannot be overridden because the parent class private method subclasses cannot inherit at all, and since subclasses cannot inherit, there is no way to rewrite
B. Subclasses overriding parent class methods, access permissions cannot be lower, preferably consistent
C. Parent class static methods, subclasses must also be overridden by static methods
* In fact, this is not the method of rewriting, but the phenomenon is true, as to why not the method rewrite, polymorphic I will explain (static can only cover static)
D. When subclasses rewrite the parent class method, it is best to declare the exact same.
What are the features of 5.final keywords?
(1) Modifier class, class cannot be inherited
(2) modifier variable, variable becomes constant, can only be assigned once
(3) Modification method, method cannot be rewritten (sometimes all methods are important, do not need to be rewritten, need to define the class as final)
(4) Final modifier local variable: Basic type, value cannot be changed, reference type, address value cannot be changed, property in object can be changed
(5) When is the initialization time of the final modified variable?
A. Not modified by the static keyword
* Can display initialization
* Can be initialized in the constructor method
B. Modified by static
* Can display initialization
* Can be initialized in a static block of code
* Cannot be initialized in constructor method
1. Talk about your understanding of polymorphism?
(1) Polymorphism is the existence of many forms of things
(2) The precondition of polymorphism
A. To have an inheritance relationship.
B. There are methods to rewrite.
C. To have a parent class reference to the child class object.
(3) Features of member access in polymorphic states
A. Member method: Look at compile-time parent class (left), run-time see subclass (right)
B. Member variables: Look at the parent class at compile time (left), look at the parent class at run time (right)
C. Static method: Compile look Left (parent class), run look Left (parent class).
(Static and class-dependent, not rewritten, so access is still on the left)
Only non-static member methods, compile look left, run look right
(4) The benefits and drawbacks of polymorphism
A. Benefits
* Improved maintenance of code (inheritance guarantee)
* Improved code extensibility (guaranteed by polymorphism), can be used as a formal parameter, can receive arbitrary subclass of object
B. Disadvantages
* Cannot use properties and behaviors of subclasses
2. What about your understanding of abstract classes?
(1) An overview of abstract classes?
A. In some cases, the parent class knows only what methods the subclasses contain, and it does not know exactly how these subclasses implement the method
B. Extracting an abstract class from a class with the same characteristics, using this abstract class as a subclass template, thus avoiding the arbitrary design of sub-class
C. Limit the methods that subclasses must have and do not focus on implementation details.
(2) Abstract class features
A. Abstract classes and abstract methods must be decorated with the abstract keyword
* Abstract class Name {}
* Public abstract Void Method name ();//When you don't know how the method is implemented specifically
B. Abstract classes do not necessarily have abstract methods, classes with abstract methods must be abstract classes or interfaces
C. Abstract classes cannot be instantiated so, how does an abstract class instantiate?
* Instantiated by a specific subclass in a polymorphic manner. In fact, this is a polymorphic, abstract polymorphism.
D. Subclasses of abstract classes
* or an abstract class
* Either rewrite all abstract methods in the abstract class
(3) Characteristics of abstract class members
A. Member variable: it can be either a variable or a constant. Can abstract modify member variables? member variables cannot be decorated
B. Construction method: Must have.
* For subclasses to access the initialization of the parent class data.
C. Member methods: can be either abstract or non-abstract.
* Abstract methods force the subclass to do what it wants.
* Non-abstract method subclass inherited things, improve code reusability.
3.abstract keywords cannot be used in conjunction with which keywords
(1) Abstract and static
There is no method body for the method that is modified by abstract
A static modifier can be used to invoke the class name, but the class name. It makes no sense to invoke an abstract method.
(2) Abstract and final
The method of the abstract modification enforces the subclass rewrite
The final modifier does not let subclasses rewrite, so they are contradictory
(3) Abstract and private
The abstract modifier is for subclasses to see and force overrides
The private decoration does not let the subclass access, so they are contradictory
4. Talk about your understanding of interfaces?
(1) Interface overview
A. From a narrow point of view, it means interface in Java.
B. From a broad perspective, the external provision of rules is the interface
(2) interface features
A. Interface with keyword interface representation
* Interface interface Name {}
B. Class implementation interface with implements representation
* Class Name implements interface name {}
C. Interfaces cannot be instantiated
* So, how does an interface instantiate?
* Instantiate in a polymorphic manner.
D. Subclasses of the interface
* A: Can be an abstract class. But it doesn't make much sense.
* B: Can be a specific class. To override all abstract methods in an interface.
(3) interface member characteristics
A. member variables can only be constants and are static and public.
* Default modifier: public static final
* Suggestion: Give yourself manually.
B. Construction method: The interface has no constructor method.
C. Member methods: can only be abstract methods.
* Default modifier: Public abstract
* Suggestion: Give yourself manually.
5. Describe the relationship between class and class, class and interface, interface and interface.
(1) Classes and classes:
A. Inheritance, can only be single-inheritance, multi-layered inheritance.
(2) Class and interface:
A. The realization of the relationship can be achieved either single or multiple implementations.
B. It is also possible to implement multiple interfaces while inheriting a class.
(3) interface and interface:
A. Inheritance relationships, which can be either single-inheritance or multiple-inheritance.
6. What about your understanding of abstract classes and interfaces?
(1) Member differences
A. Abstract class:
* Member variable: can be variable, can also be constant
* Construction Method: Available
* Member method: can be abstract or non-abstract
B. Interface:
* Member variable: can only be constant
* Member method: can only abstract
(2) Relationship Difference
A. Classes and classes
* Inheritance, single inheritance
B. Classes and Interfaces
* Implementation, single implementation, multi-implementation
C. Interfaces and interfaces
* Inheritance, single inheritance, multiple inheritance
(3) Differences in design concepts (preferably the first example of an interview)
A. The abstract class is inherited as follows: "is a" relationship. The common function of the inheritance system is defined in the abstract class.
B. The interface is implemented as follows: "Like a" relationship. The extension functionality of the inheritance system is defined in the interface.
* Abstract classes for the nature of things, and interfaces for the expansion of the functions of things
What are the permissions modifiers in 1.java, and what are their corresponding access rights?
This is similar to a package (subclass and unrelated classes) under different packages (subclass) under different packages (unrelated classes)
Private Y
Default Y y
Protected Y y
Public y-y y y
1. When to load the class (the load time of the class)?
When a program wants to use a class, if the class has not yet been loaded into memory, the system initializes the class by loading, connecting, and initializing three steps.
(1) Creating an instance of a class
(2) Accessing a static variable of a class, or assigning a value to a static variable
(3) static method of calling class
(4) Use reflection to force the creation of a class or interface corresponding to the Java.lang.Class object
(5) Initialize subclasses of a class
(6) Run a main class directly using the Java.exe command
2. Class Loader classification?
(1) Bootstrap ClassLoader Root class Loader
* Also known as the Boot class loader, which is responsible for loading Java core classes
* such as system,string and so on. In the Rt.jar file under the Lib directory of the JRE in the JDK
(2) Extension ClassLoader Extension Class loader
* Responsible for loading the jar packages in the extended directory of the JRE.
* In the JDK of the JRE in the Lib directory of the Ext directory
(3) Sysetm ClassLoader System Class Loader
* Responsible for loading the class file from the Java command when the JVM starts, and the jar package and classpath specified by the CLASSPATH environment variable
3. Three ways to get byte-code objects?
(1) The GetClass () method of the object class to determine whether two objects are the same bytecode file
(2) static attribute class, lock object
(3) Class class static Method Forname (), reading the configuration file
4. What is the method used in reflection?
(1) Construction method
|--get: GetConstructor () and GetConstructors ()
|--execution: newinstance ()
(2) Common member methods
|--get: GetMethod () and GetMethods ()
|--execution: Invoke ()
(3) member variables
|--non-private: GetField () and GetFields ()
|--Private: Getdeclaredfield
|--access to a private member variable first executes: Setaccessible (TRUE), then executes the Set method
5. Generic erase?
Generics are only valid at compile time, will be erased during runtime, and generics will not be created after a. class file.
6. Violent reflexes?
You can get all the properties and methods in a bytecode object, including private. For private properties and methods to use violent reflection, which is obtained using the Getdeclaredxxx () method,
Then set can be accessed, that is, call Setaccessible (True)
New features of 8.jdk1.8?
(1) The method in the interface can be defined with the method body, if non-static, must be modified with the default
(2) If it's static, it's not necessary.
9. What are the three elements of network programming?
(1) IP Address
(2) Port number
(3) Agreement
What is the difference between 10.UDP and TCP?
(1) UDP: For no connection, data insecure, fast. The client and server are not differentiated.
(2) TCP: Connection-oriented (three-time handshake), data security, slightly lower speed. Divided into client and server.
(3) Three-time handshake: The client initiates a request to the server, the server responds to the request, transmits the data
11. What is the summary in multi-threading?
(1) Sleep () method? Release the execution, do not release the lock?
(2) Wailt () method? Release the lock and release the execution right?
Java Patchwork Finishing