当前位置:网站首页>Study notes of Gu Yujia on July 27, 2022
Study notes of Gu Yujia on July 27, 2022
2022-07-28 04:20:00 【Sister haha】
Inner structure of class :
attribute 、 Method 、 Constructors 、 Code block 、 Inner class
Code block :
Code blocks can also be called initialization blocks , A member of a class , It encapsulates logical statements in the method body .
adopt { } The parcel . Code block has no method name , No parameters , no return value , Only the method body .
It does not require explicit calls through objects or classes , When the class loads or creates objects , forwardly ( Implicit ) call .
- Static code block
When a class is loaded, it will be called once , Do some initialization work

2. Instance code block

Every time you create an instance, it will be called , Rarely used ( Create an object and call once )
· There can be multiple static blocks , However, in development, a static block is usually written
static static state ( Class properties , Class method )
You can modify properties 、 Method 、 Code block
Class name . Property name calls directly
use static Modified structure , Does not belong to any object
1. When decorating attributes , For output Class name . Property name ( Independent of objects , It can be used without objects )
2. When modifying a method , For output Class name . Method name
static Memory resolution
1. Static variables or static methods exist in the method area , Static structures will not be garbage collected
2. Does not belong to an instance object , Only exists in the method area . Call static structure , Direct use Class name . The way .
Mutual calls between instance methods and static methods
1. In the static method You can't call Example method
If you want to use , must object . Method name
2. Example method Can be called directly Static methods
Static structural loading , Load as class loads .
Non static structure , Load as objects are created .
stay Java Calling instance method in , There must be a subject ( There must be someone to adjust ). The method is not first-class citizens , Can't call directly .
Static methods are class names wherever they are . Method name , The class name can be omitted between static methods of the same class .
Constants in the interface default public static final
In development , Basically, the declarations of constants are public static final
Static methods do not override this concept
Arrays.toString( )、Arrays.sort( )、Integer.parseInt( )、String.valueof( )—— Static methods
this and super
Whether it's this still super, Cannot be used in static structures .
this Can represent subclass objects ,super Nothing means
this. Method super. Method
Static structures belong to classes , Static structures exist prior to objects
this and super There must be an object to appear , There must be examples .
Static structures include code blocks as well as code
Interview questions
The parent class is better than the child class , Static blocks are better than others
(1) Parent class output order : A static block > Instance block > Constructors

(2) Subclass output order ( The parent class has static blocks 、 Instance blocks and constructors , Subclasses also have static blocks 、 Instance blocks and constructors ).

When there is no inheritance , Just one class , A static block —— Instance block —— Constructors
When there is inheritance , Parent static block —— Subclass static block —— Parent instance block —— Parent constructor —— Subclass instance block —— Subclass constructor
Structure of classes :
attribute 、 Method 、 Constructors 、 Code block 、 Inner class
External class ( As far as possible need not )
You can declare another class outside the class
One public Declarative classes , The class name must be the same as .java The same file name for
External classes are two classes
Inner class :
Perform nested operations of other class structures within a class
The linked list we wrote before ,Node Classes are mainly SuperLinked
We can Node Class is defined in SuperLinked in
Design patterns
Design pattern is a reusable solution abstracted by people for software development .
Communication between software development engineers “ jargon ”
Object oriented design principles
- Opening and closing principle (Open Close Principle)
Open to expansion , Turn off for changes ( Inherit , Implementation interface )
We can go through “ Abstract constraints , Packaging changes ” To realize the principle of opening and closing
Define a relatively stable abstraction layer for software through interfaces or abstract classes
Encapsulate the same variables in the same implementation class
- Richter substitution principle
When a subclass inherits a parent class , In addition to adding new methods to complete the new functions , Try not to rewrite
- Dependence Inversion Principle
Interface oriented programming , Don't be implementation oriented ( class ) Programming
- Each class tries to provide an interface or abstract class , Or both
- The type declaration of variables should be interfaces or abstract classes
- No class should be derived from a concrete class
- When using inheritance , We should follow the principle of Richter substitution
- Interface isolation principle
Use multiple isolated interfaces
- Dimitar's law
- Synthetic multiplexing principle
- A single principle : A class does only one thing
The singleton pattern
A class can only have one instance
The hungrier singleton
No matter whether it will be used in the future , The instantiated object , It 's created first ( Very anxious )
The way to achieve this is to directly new Instantiation .
Lazy singleton pattern ( Delay loading )
When to call getInstance This method , When to initialize (new)
This laziness is completely wrong in a multithreaded environment , There is no guarantee that it is a singleton state
Inner classes realize simple interest
It is also a kind of lazy , This lazy style has no thread problem
It combines the advantages of hungry and lazy
As long as you don't call getInstance Method , You won't use inner classes
Once the inner class is used once, it will only be initialized once , Things that have been used in the future INSTANCE Static constants
Arrow function :JDK8 New features
Functional interface : If an interface has only one abstract method , This excuse becomes a functional interface .
You can annotate @DunctionalInterface identification
Normal operation :
Unconventional operation :
simplified :
![]()
Arrow function
![]()
This structure can be divided into three parts
- Parentheses wrap formal parameters , Type no
- ->
- -> Overridden method body
When the rewritten method body has only one sentence , It can be simplified to this extent
When the overridden method only has a return value , It can be reduced to this
Summarize arrow functions :
- With parameters , There is a return value
If the method body is just a return value (i , j) -> i + j
- With parameters , No return value
If the method body has only one sentence (i , j) ->
边栏推荐
- 网页源代码查看竟然有这么多方法!你都知道吗?
- Servlet usage
- Kingbasees security guide of Jincang database -- 6.2. Configuration files related to authentication
- openpose的一些个人理解
- H. 265 web player easyplayer realizes webrtc video real-time recording function
- Istio's Traffic Management API
- 功耗:Leakage Power
- Glusterfs file is not mounted, permission: R-S
- Information system project manager (2022) - key content: Project Procurement Management (12)
- Docking with Hang Seng express ― dolphin DB NSQ plug-in tutorial
猜你喜欢

XML file usage and parsing

servlet使用

40: Chapter 4: Development File Service: 1:fastdfs: (1): introduction to fastdfs;

高数_第4章__曲线积分

idea2022更改本地仓库,配置阿里云中央仓库

【无标题】

21 days, fat brother personally takes you to play oauth2

Un7.27: common commands of redis database.
![[day03] process control statement](/img/4d/d66140962b7e121a2fea2c366a972a.png)
[day03] process control statement

Detailed explanation of pl/sql parameters ("box model")
随机推荐
CV2. Threshold(), CV2. Findcontours(), CV2. Findcontours image contour processing
Fedformer MOE module
[day03] process control statement
金仓数据库KingbaseES安全指南--5.1. 数据库的传输安全
【luogu P4590】游园会(DP套DP)
null安全与异常
Construction and use of FTP server and NFS server
H265/HEVC名词解释-- CTU,CTB,CU,CB,TU,PU,TB,PB,LCU,Slice,Tile,Chroma,Luma,I帧,B帧,P帧
Shell rental reptile
jdbc使用
servlet使用
Virtual machine class loading mechanism
.net upload files through boundary
ServletContext、request、response
Citrix virtual desktop tcp/udp transmission protocol switching
20-Openwrt crond crontab
About me writing a custom cell
Notes to subject 2
Classification cluster analysis
Go grpc: a solution of connection reset by peer










