1. Briefly describe your understanding of the HTTP protocol
Answer: The http protocol is a hypertext transmission protocol, which is carried out by the client and the server.Data communicationA protocol that stipulates the format of request and response (RequestRequest: request line + request header + request body; Response response; response line + response header + response body).
2. How many ways are there to splice Java strings?
Answer: 1. "+" method, directly splicing;
method"concat"Method: Theoretically most efficient, but both parameters must be string-type strings and cannot be null;
String a="a";
String b="b";
String c= (b);
3. "append" method
StringBuffer buf=new StringBuffer()
("a");
("c");
String d=();
**Note: (1) StringBuffer is thread-safe, StringBuilder is thread-safe (but more efficient, single-threaded recommended);
(2) In order to improve the efficiency of splicing multiple strings, you can set the estimated capacity length of StringBuffer in advance
StringBuffer buf=new StringBuffer(()+()+());
Summary: The three methods have their own advantages and are used in combination with actual conditions.
3. The difference between Exception and Error
Answer: Both inherit and Throwable
(abnormal): It is an unforeseen exception when running a Java program, and jvm will not be handled and cannot be restored. Exceptions (catching/throwing) should be handled quickly to restore normal operation of the program;
(Error): It is an error in the Java program code system, and the programmer needs to modify the program code to solve it;
IV. IOC, AOP
A: Spring is a lightweight inversion of control (IOC) and section-oriented programming (AOP) container framework;
: Control inversion, invert control of creating an object (new object) to the spring framework
**IOC container: a container with dependency injection function, which can create objects, which is responsible for instantiating, locating, configuring objects in the application and establishing dependencies;
**Spring dependency injection methods: annotation injection (common methods), set injection, constructor injection, static factory injection;
Dependency injection annotation: @Service+@Autowired/@Resource
: : Face-oriented programming, strip the same operation code, put it in a class and concentrate it, and dynamically weave these common codes through AOP;
** Mainly used for: logging, permission control,performanceStatistics, exception handling, transaction control, parameter verification, signature verification, etc.;
Section: @Aspect; Section: @Poincut; etc. annotations;
5. What characteristic conditions should be met for the prerequisites to use the equals method?
Answer: 1. Reflexivity: For any non-null x variable, the return value of (x) must be true;
2. Symmetry: For any non-null x, y variables, (y) and (x), the return values of both must be the same;
3. Transitiveness: The return values of any non-null x, y, z variables, (y), (z), (x), and three must be the same;
4. Consistency: For any non-null x and y variables, as long as they are not changed in the program, the return value of (y) multiple calls must be the same;
**==Difference between equals: ==The basic data type compares "value", and the reference data type compares address value;
equals cannot compare basic data types. The reference data type compares address values, but if equals is rewritten, the content is compared;
6. Thread-safe and non-thread-safe
Answer: 1. The results obtained by multiple threads running the same code snippet are the same as the results obtained by a single thread, and other variables are the same as expected, so the thread is safe, such as: StrungBuffer, ArrayList, HashMap, etc.;
Non-thread safety refers to: one data is read and modified by a thread, but has not been saved or further processed, and another thread also reads this data for operation, resulting in dirty data; such as: StringBuilder,Vector,HashTable
2. Root cause: There are two or more threads sharing the sameData resources;
3. Solution: Synchronize code blocks, synchronization method: synchronized keyword is used to control thread synchronization;
Lock: lock mechanism, lock() lock,unlock()Unlock;
7. New features of Java8
Answer: 1. The default method of the interface (interface extension method), keyword: default; you can add a non-abstract method to the interface, which can be used directly in the implementation class;
interface demo{
int inDemo();
default int inDemo(){
return 1;
}
}
2.Lambdaexpression