JAVA path (2): java path
This is the second time I learned JAVA. I feel like I have learned many ideas and principles.
This blog only has some understanding of JAVA. The specific definition and usage are provided in Encyclopedia.
Why did I record my learning process in my blog, because I want someone to know that I am learning it, so as to form a kind of supervision for me, so that I cannot give up easily.
A brief summary of JAVA:
1: What is object-oriented programming, it is a programming idea.
By abstracting things into entities with properties and behaviors, we can clearly program the sense of attention, protect program security through modifiers and standardized judgment, and simplify the amount of code through inheritance. (Do not summarize this point before reviewing polymorphism)
Object-Oriented Programming means that things are abstracted as objects (BASICS) --> encapsulation (Security) --> inheritance (conciseness ).
2: constructor meaning:
The constructor is a way to instantiate objects by class. It opens up a space in the heap through the new keyword to construct an instance object.
PS: Construct a code block-a class usually needs to overload the constructor. In this case, using the constructor code block can simplify the code. It is used to add the code in the block to the constructor code before calling the constructor code.
For example:
{
System. out. println ("I am constructing a code block ");
}
Public std (){
System. out. println ("I am constructor 1 ");
}
Public std (String name, int age ){
System. out. println ("I'm constructor 2 ");
}
When the constructor std () or std (String name, int age) is called, the compiler puts the content of the constructor code block into the constructor.
For example:
Public std (){
System. out. println ("I am constructing a code block ");
System. out. println ("I am constructor 1 ");
}
PPS: During subclass initialization, no matter whether the constructor of the subclass calls itself has parameters, it calls the non-argument constructor of the parent class by default, how important is a class construction method without parameters.
3: static keywords
Static: I understand that it is used to make objects or methods public objects or public methods. It is to open up a public area in the memory. Every object instantiated by class can access static variables or static methods.
Static variables are associated with the class. all instances of the class share a static variable. They are accessed by class name, static variable name, class name, and static method name.
When Will static variables be used? For example, the count variable is used for metering. Static methods cannot call instance variables, but can only call static variables. At the same time, it cannot call this, and it does not belong to any instance.
Static code block, which is first loaded and can be used for static variable initialization.
4: this and super
Super is the keyword that is used when a subclass calls the attributes of a parent class member. During subclass initialization, the non-parametric constructor of the parent class is called by default. Even if the sub-class is called with a constructor, it still calls the non-parametric constructor in the parent class.
This refers to the instance object itself. You can use this to call the constructor this (), or call the member attribute this. variable name; this. Method ();
Super and this cannot be called at the same time
5: Encapsulation
Encapsulation improves program security and standardization. During programming, you must be clear about the scope and significance of the four modifiers private, default, protect, and public. Their limitations gradually weakened.
In addition to modifiers, users must reject input when entering illegal data. For example, in the set method, the age range is limited.
PS: pay special attention to the standardization of various naming rules.
6: All classes directly or indirectly inherit from the object class. Subclass often overwrites its equal method and toString method. When a class is modified with the final keyword, it is the final class and cannot be inherited. If a variable is modified, it cannot be changed and becomes a constant. How to remember the final keyword, final (final ).
I saved a lot of useful materials:
1: java Naming rules
2: Use of package and import
3: usage of the this keyword
4: single Responsibility Principle
5: Encapsulation
6. encapsulation of comprehensive Cases
7: javadoc commands
8: Inherit top and bottom
9: Object-oriented
10: Single-Profit Mode
Link: https://pan.baidu.com/s/12EJ8fDzm-HidOgxkKedlWw password: 91hr
If you are interested, you can download and learn more, and you are welcome to correct the problem. Later, we will update a blog post on JAVA file input and output, command line running scripts, and so on to help you complete the job.