little knowledge of java daily record - to be more

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/study_notime/article/details/94390206

**, private modifications have ways to get access was reflected by the way, what the implications are?
As a private first class, methods, variables have access to the same public, protect, like, have for object-oriented An access permissions modification. That is, we often say that the packaging concept. It was not against, absolutely can not access security. The following example code on their own to write:
Here Insert Picture DescriptionHere Insert Picture DescriptionHere Insert Picture Description

** reflection method was too getFields and getDeclareFields difference:
getFields can only access public fields, if you inherit a parent, you have to include the parent class public methods, but getDeclareFields return to the current category have all modified (private, protect, public ) was field. But does not include any field parent obtained.
Similarly
access method
getMethods
getDeclaredMethods
access to the internal classes
getClasses
getDeclaredClasses
access constructor
getConstructors
getDeclaredConstructors

**, java class initialization sequence to obtain
initialization sequence: Implementing Classes: Static variable -> Static Method -> Common Variable -> General Method -> Constructor
Interface - parent - child classes: interfaces Static variable - parent class Static variable - parent class static methods - static variable subclass - static method subclass - Common parent - the parent class constructor - Common subclass - construction of subclasses.

**, the JVM method to obtain a permanent-generation region have to understand
the method area is shared area, storing the virtual machine has been loaded to obtain such information, a constant, static constants, the code information and the like to give in-time compilation.
1 permanent generation is, you said permanently generations, this translation will be stored in different regions, including the class definition, structure, fields, constants, including the method (data and code) and class-related data. It can -XX: be adjusted MaxPermSize: PermSize and -XX. If it's running out of space, will lead java.lang.OutOfMemoryError: PermGenspace exception. The start JDK8, the permanent generation has been completely removed, it is replaced by another memory area is also known as yuan space.
2 the data storage
method of storing the area information of each class are:
1. The class loader reference (classLoader)
2. runtime constant pool
all constants, field references, method references, the attribute
3. Data field
name of each method, the type of (full path name, such as class or interface type), modifiers (e.g., public, abstract, final), the attribute
4. the method of data
name of each method, the return type, parameter types (sequentially), modifiers, attribute
5 the method codes
the start position of the byte code of each method, the size of the operand stack, local variable size, the local variable table, and the exception table for each exception handling, end position, the processing code is offset in the program counter, and is constant pool index exception classes captured

**, (resulting reference address storage jvm virtual machine stack local variable stack frame table) obtained by a stack of two ways to get access memory reference object
1, or indirectly via the handle to the instance data cell (the stack reference address obtained handle address pool)
JVM will open up a portion of the heap memory pool used as a handle java, which includes the address of the object to obtain object instance to obtain the address of two parts in the process zone
2, through direct access pointer (an example of data obtained from the direct address)
direct access to the instance of the data object by the address.
Difference:
when the object is easy to recycle, choose a handle to access the pool when GC prone to be a good point. When the object is used to obtain, when accessed frequently, you have direct access pointer better way.
Note: hotspot using pointers have direct access manner.

** give distinction between Class.forName () and ClassLoader
classs.forName () calls its internal classLoader also have to load the class, except that forName forName will call a method, the method has a boolean parameter, if ture class will be loaded and initialized (initialize the static method, a static variable, etc.). The classLoader only classes loaded.
Example: spring is easy ioc, is performed using the class loader classLoader give (parent delegation mode -bootstrapclassLoader (boot class loader, loads the specified path have JAR, libraries), Extendion ClassLoader (extension class loader, loading the environment variable libraries have specified path), applicationClassLoader, application class loader, loading of the path designated by the user get library, the code is usually employed in the preparation). jdbc have used in class.forName () method of class load (jdbc the driver needs to register itself with the driverManage, and driverManage is static too, needs to be initialized, complete the registration in the class.)
added: custom loader needs to be rewritten the method of findclass classLoader, define and use the last generated class object.
Here Insert Picture Description**, socket java the
socket is available for a tcp encapsulation protocol, the operating system is an abstract concept, can be programmed directly from the upper layer application.
socket can be understood as: client IP protocol client port server ip server port
port to establish socket connections have to distinguish between the process was different.
socket programming:
Client: The system can automatically assign port and automatically obtain ip
clientfd = socket {...} connect ( clientfd, Ip server, server port, .....); send (clientfd , data); receiver (clientfd, ...) ; close ();
server: 1, the client needs to listen may request transmission. 2, a plurality of available transmission according to the client request, distinguished socket.
listenfd = socket {...}; bind (listenfd, have native IP and port, ...); the listen (listenfd, ...);
the while (to true) {
connfd = Accept (listendfd, ...);
the receive (connfd, ...) ;
the send (connfd, ...)
}
use Close ();
connfd equivalent to the client completed a three-way handshake links. Users send this link to reliable sources.
Each socket is through the client ip client server ip port server port plus agreement. When accessing the server have the same process, the server does not need to create a new port. In order to distinguish the end socket may be obtained with the client ip obtained through the client port.

**, database level to four have four isolation characteristics
set: written as w locks, read locks r, two transactions, A transaction, B transaction
1, read uncommit uncommitted read. There will be dirty read. A write at this time to acquire the lock, A uncommitted transactions, release the write lock, B acquire a read lock, transaction rollback A, B read out the data in question. (Read uncommitted)
2, committed read Read the commit. Non-repeatable reads occur. A acquire a read lock, A uncommitted transactions, the release read lock A, B acquires a write lock, B releases write locks, B transaction commits, get a read lock A, A read data, found that the data has changed, the transaction is committed. (Read data updating or deletion)
. 3, Repeatable Read repeatable read, there will be performed phantom read, A, B order transaction, transaction modifies data A, B transaction data inserted (inserted data is data immediately A Review ), a find the transaction did not modify (in fact, just insert the data B). (Newly inserted data read)
. 4, Serializable sequential read. When a transaction modifies A, B transactions insertion operation.

1, atomicity: the same transaction, database operations either succeed or fail.
2. Consistency: before and after a transaction, regardless of whether the operation is successful, the database are in a complete state of
3, isolation: among multiple transactions on a database of operating independently of each other
, persistence 4: Submit a transaction, then the affect the operation of permanent
Note: a transaction, if satisfied atomicity, consistency satisfied. A plurality of transaction, atomicity and isolation satisfied, the consistency is satisfied.

mysql isolation level
isolation level is repeatable read. Magic will be read by mvcc innodb multi-version concurrency control to solve the problem
transaction version number, when a new transaction, the version number is incremented
system version number, the version number of the current operation of the transaction is equal to the version number

New data, the bank's new version number is the version number of the transaction
delete data, delete the version number is diverted to the transaction version number

To meet the conditions of the current transaction version <new data version number of the current transaction version number> Delete query data version number.

**, java static and non-static
1, a static (constant, method) will be initialized when the class is loaded, it can be directly accessed through the class. Non-static is initialized during use.
2, static efficiency was higher than the non-static. Some will be non-static safety checks before use, for example, have to determine whether the object belongs to NULL.
3, static life cycle was higher than non-static. From the static load it has been saved, regardless of whether or not being used.
4, static scene for a number of commonly used tools, to provide some functionality, without having to access non-static methods. Which led to the shortcomings do not extend (inheritance, polymorphism) of

**, machine learning concept
1, through a number of phenomena, some analysis, expected results
2, along with the greater amount of data to obtain the expected results will be the higher of
3, divided into three categories of machine learning, supervised learning , unsupervised learning, semi-supervised learning.
4, supervised learning: via some input, through a calculation function to obtain a proper output
5, unsupervised learning: for the data by associating something some input.
6, semi-supervised learning: a combination of both.

** The server returns code
200, access normal
400, syntax problem, the server can not understand the
401 owners, this thing does not authorize you to access Gesha ah
403 master servers do not want to pay attention you
404 owners, could not find ah, see if you knock URL right
500 master server crashes
503 master server may be too busy, and so will you try it
301 redirect.

**, spring was in the dependency injection (DI) and Inversion of Control (IOC)
often have to hear the word, is often asked to get the interview points. Many previous Baidu looked very official, very professional, way below the vernacular was to write about their own understanding.

As we all know, java is an object-oriented programming too. In the program we have to process, you will inevitably encounter a class need to use another class was the case. Similar to: The above Person class, we need to go to school, need the help of reading ReadBook class to create an object, and then call was reading method. We can say that this class needs to Person (dependent) ReadBook this class. Similarly rely Play this class to play the game. When the spring was not yet born when it was written like this, too. The beginning is when people write very convenient, feel good, but as the business too complex, find a class needs to rely too much class, was the relationship between each class has become very complicated mess. We had to code optimization. Chang will be used to put the factory pattern (follow-up was specifically introduced java design patterns) like this: in short, by a subclass inherits a ReadBook with PlayGame Interest parent, what you need to get pass the corresponding type on it. Such Person This class would just be a Inerest this class on the line. It looks really simplifies some dependencies. But later, still looking at the code too much, each class must use to initialize, to construct it, or too much trouble. People can not think through other ways to manage the relationship between these classes too, and later appear spring through xml file to maintain. In the configuration file to configure these classes and get a reference type, that is, we often say that bean, like this: this is enough yet, clearly not enough, spring also need to parse the configuration file by bean xml file parser, according to bean by java reflection afford instance of the class, then obtained by the above similar method call to create an instance available under factory mode, dependent on the need to create an instance of the class obtained. Dependencies can be annotated by. spring general thinking is this realization, many specific details have to go to see the source code, of course, complicated than it says a lot.
Bold Style



Here Insert Picture Description

Here Insert Picture Description

So what is called inversion of control it? Before spring is yet to come, you have to rely on class time, through their own need to manually instantiate this class. But now it is not the same, spring offers a ioc. Is like a container, all classes are on the inside, when what you need, and you will talk about container (configuration bean), I want this, the container will give you. Previously to create by their own example, is now managed by the ioc container, controlled by the authority itself into a container, it is called inversion of control.

**, spring was in aop Oriented Programming
Aspect Oriented Programming, in short, find the entry point to the program. That was the actual project application is. With the development of software industry, as business needs too complicated. The project required security, performance and quality have improved.
A simple pay for the project will include the following basic modules: user information, order center, payment center, back office management. This business module must rely on a number of other features, such as: log management, transaction management, security management and other public module.
Novice programmer might write:
Here Insert Picture Description
function realization, but the entire code, business-related code base is covered, it is not necessary, experienced programmers will be improved, use the Template Method design pattern, the template method in short mode is to set a parent, these common functions to achieve in the parent class, business class code to inherit the parent class by subclass can simply override the business-related methods of the parent class. Like this:
Here Insert Picture Description
Here Insert Picture Description
include other sub-categories too, also inherits the parent class, only care about their business code on it, do not care about those public functions. It seems to solve the problem, but the problem again. If written above. When some sub-class does not need the parent of all the methods, not all subclasses require logging or performance test functions, write, so that each subclass inherits the business needs to go, what to achieve, is not a waste. The order of those functions in the parent class, a subclass can not change, can only achieve unconditional acceptance of the parent class. Too rigid, so the need to use another design pattern. The decorator pattern. Is to continue upward in a template method abstract parent class, business class and all classes inherit features him, similar to the following:
Here Insert Picture Description
when a required function corresponding to only the corresponding instantiation, like:
the Common Common OrderMng new new = (new new TransactionMng ());
common.excute ();
If you need to add log management, then add the line:
Common = new new OrderMng the Common (new new TransactionMng (LogM new new ()));
common.excute ();
sequence may also be exchanged.
Use the decorator pattern, is not to look out, business code and function code basically separated.
So spring is by what means to accomplish this is so. And decorator similar, but the advantage is that by maintaining these two xml files completely separated. At compile time, reads the configuration information aop will maintain the two together. But this is to maintain a static state, so by spring coupled with the dynamic proxies (the follow-up blog will detail dynamic proxies) to generate a proxy class, will require a dynamic section of the code (public functions) into the proxy class. Completion.

Guess you like

Origin blog.csdn.net/study_notime/article/details/94390206