Java basic learning Summary (with some common eclipse operations), javaeclipse
I. this keyword
1. Use this to call the member variables and member functions of this class.
2. Use this to call the constructor.
2. static Keywords of static variables
1. contains static member variables and member functions. You can use the class name directly.
2. There is only one static member variable.
3. this cannot be used in static functions.
4. Static code blocks assign values to static member variables.
Iii. inherit extend
1. Use inheritance to reduce repeated code.
2. Use super to call the constructor method of the parent class.
3. the constructor of the parent class must be called in the constructor of the subclass. The compiler adds super () by default ();
4. inheritance can only inherit member functions and member variables. The constructor of the parent class cannot be inherited. So we have the super keyword.
5. override is also called override. Among the two classes with parent-child relationships, the parent class and the Child class each have a function. The definitions of these two functions (return values, function names, and parameter lists) are completely the same.
Upward Transformation (assign the subclass object to the parent class for reference)
2. A reference can call those members (variables and functions), depending on the type of the reference.
3. which method is called by a reference depends on the object pointed to by the reference.
Downward Transformation (assign the parent class object to the reference of the subclass)
1. For downward transformation, the premise is to first transform the parent class reference to the parent class, and then assign the object of the parent class to the reference of the Child class.
Iv. abstract Functions)
Abstract Functions are functions without function bodies.
Classes defined using abstract are called abstract classes.
1. abstract classes cannot generate objects. Is used to be inherited.
2. If a class contains abstract functions, the class must be declared as an abstract class.
3. If there is no abstract function in a class, the class can also be declared as an abstract class.
4. the abstract class can also have constructor and can be called through super.
5. package name)
1. The-d parameter must be used during compilation. The function of modifying the parameter is to generate the corresponding folder according to the package name.
2. The full name of a class should be "package name" + "." + "class name ".
Package name naming rules:
1. All letters in the package name must be in lower case.
2. The package name is generally written by your domain name;
Vi. Access Permissions
1. public can modify classes, member variables, and member functions.
There are no restrictions. classes in the same package or different packages can be freely accessed.
2. private can modify member variables and member functions.
It can only be used in this class.
3. default (without the permission modifier, the default permission) can be used to modify classes, member variables, and member functions.
In the same package, you can freely access it.
If the child class and the parent class are not in the same package, the Child class can inherit the member variables and member functions with the default permission in the parent class, but cannot be used due to insufficient permissions.
4. The protected permission has the same functions as the default permission, but this permission can only modify member variables and member functions.
Protected is generally used to inherit the relationships between classes, parent classes, and child classes. Sub-classes can use the parent class protected member variables and member functions.
5. Permission level: public> protected> default> private
VII. Basic interface syntax
1. Use interface Definition
2. All methods in the interface are abstract methods.
3. All methods in the interface have the public permission.
4. Implement the interface using the implements keyword
5. One class can implement multiple interfaces
6. One interface can inherit multiple interfaces
Simple factory mode: interfaces are transformed upwards. All new objects are encapsulated into a class.
8. Exceptions in Java
Exception: the normal instruction stream is interrupted.
Check exception: the Java Virtual Machine requires code that may encounter exceptions and should be thrown.
Uncheck exception: the Java Virtual Machine does not know the exception Code.
10. Common eclipse operations
1. Push the subclass Method to the parent class method.
2. Several Methods for reconstruction and Extraction
3. Modify the signature of the Function Method
4. Duplicate statement Composition Method
5. Rebuild the class name automatically
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.