1 Introduction
Has been working for more than 3 years. During these 3 years, I especially thank the technical managers for their attention and the help of colleagues. I have learned a lot. In the past three years, I have gone through some detours and encountered some problems. I have also suffered from being a developer but often serving as a firefighter for system maintenance and release. So he decided to sort out what he had learned and share it for everyone.
After 3 years realized that there were many misunderstandings before, such as:
Prefer to collect, often collect various data and videos to fill up the hard drives one by one, and then look at the content satisfactorily without action.
I don't emphasize the basics. I always feel that many basic things don't need to be read anymore. In fact, there are many places that don't understand. There must be a reason for any result in the computer program. Don't just use the unknown principle. Now ide is so convenient to view the code, ctrl + click to enter the JDK to view the implementation details.
Gao Qianyuan, under the condition that the computer foundation is not strong, always think about doing architecture, getting distributed, doing big data and the like.
Do not pay attention to performance, only to achieve the function, whether the SQL query can be optimized, whether there is a magical algorithm, and whether large objects should be cleared.
Pays little attention to scalability, close coupling between modules, common methods are not extracted into tool classes, and the calling relationship is confusing.
……
The focus of this article is not on these, so only a small part is listed.
2. Basic Grammar
2.1 Java class initialization sequence
This is the order of class initialization in all cases. Skip if there is no definition in the actual class: parent static variable-parent static code block-child static code block-parent non-static variable-parent non-static Code block-parent class constructor-subclass non-static variable-subclass non-static code block-subclass constructor
2.2 Value transfer and reference transfer
Maybe many people disdain this, thinking that I have been working for 3 years, are you unfamiliar with these? But this is not the case, are all things familiar in the JDK? Starting with the simplest example, what do you think of the elements in fatherList after the code in the figure below is executed?
This is a basic example of value passing and reference passing. You think it's very simple and you already want to try the challenge. Then look at the following. StringBuffer is easy to understand, but when you execute it again, you find that it is not as expected. Is the output different? Isn't String a reference type, how could this be? If you can't understand it, then please take a look at the implementation source code of String to understand its implementation principle in memory allocation.
2.3 Use of collections
Almost everyone will use this part, and everyone is not new to it. The following picture is from the Internet for your review. However, clever combination of the characteristics of the collection can solve many complex optimization problems. Set non-repeatability, List order, Map key-value pair, SortSet / SortMap order, I have used many of these complicated businesses in my work, these are used cleverly, when it comes to company confidential information, I will not post The code is out. The longer you work, the more ingenious you will be.
2.3 Exception handling
1. Looking at try, catch, finally is very easy, if combined with transaction propagation, it will become extremely complicated.
2.finally does not necessarily have to be executed, return handles the situation in catch / finally (it is recommended to try it yourself).
3. Catch can continue to throw custom exceptions (and pass the exception step by step to the control layer, use the aspect to grab the package exception, and return it to the caller).
2.4 Object-oriented thinking
When it comes to object-oriented, everyone knows abstraction, encapsulation, inheritance, and polymorphism. But how much do you know in actual work experience, not to mention how to use estimation in the project.
Common opportunities each need to establish a base class, for example, each control layer method may need to obtain a login user id through security, used to operate different data according to different users, you can abstract an application layer base class Get the protect method of id. Similarly, the DAO layer can use generics to extract a base class that includes addition, deletion, and modification.
Polymorphic Override: The reference variable of the base class can not only point to the instance object of the base class, but also point to the instance object of its subclass. . It is commonly used in strategy mode.
When it comes to object-oriented, it is inevitable to say design patterns. In the work, a similar strategy pattern (a little more complicated) written by a technical expert, very cleverly solves the same method of various businesses and realizes orders. , The decoupling of work orders, business, I am very admired. I think the singleton mode will be asked in many interviews, and I have a suggestion that I don't understand yet.
A
3. Multithreading
3.1 Thread safety
This is an old question, but it is indeed a high incidence of problems and bugs. The thread synchronization problem does not need to be written separately. It must be clear to everyone that I am not familiar with Baidu.
3.1.1 Thread safety issues
1. If there is a synchronous operation in the code, pay special attention to shared variables (this can generally be realized)
2 Multiple operations can modify the same data in the data table. (This is easily overlooked. Business A may operate table a, and business B may also operate table a. Business A and B may cause thread safety problems even in different modules and methods. For example, if a person accesses business A interface Another person accesses the business B interface, and every business request in the web will be processed by a separate thread, and thread safety problems will occur).
3. Use of unsafe types, such as StringBuffer, StringBuild, HashTable, HashMap, etc. In my work, I have encountered someone who removes a list in a for loop. Although the compiler does not report an error, the program can run, but the result can be imagined.
4. Spring beans are singletons by default. If you have class variables, you need to be very careful (in general, no one uses class variables in the control layer, business layer, DAO layer, etc., it is recommended to use the final type, for example Log log, gson, etc.).
5. Multiple systems share a database, this is actually similar to a distributed system
The user repeatedly submits the problem (even if there is a limit in reading from the database in the code cannot solve the problem)
3.1.2 Thread safety solution
Adopt safe types where synchronization is required.
JDK lock mechanism, lock, tryLock, synchronized, wait, notify, notifyAll, etc.
Concurrent Concurrent Toolkit, who knows who to use when dealing with some issues. It is strongly recommended to check the source code!
Lock the data table. (Unless the access frequency of a certain table is extremely low, it is not recommended)
Involves distributed, using middleware technology such as zookeeper to solve.
3.2 Asynchronous
Asynchronous use scenarios do not affect the main thread and respond to slower services. For example, IO operations, third-party services (SMS verification code, app push, cloud storage upload, etc.).
If there are many asynchronous tasks, you need to use the task queue. The task queue can be implemented at the code level, or you can use redis (the advantage is too obvious).
3.3 Multi-thread communication
There are so many articles in this area, so I wo n’t go into details here.
1. Shared variable method (shared file, global variable, semaphore mechanism, etc.)
2. Message queue method
3. Busy wait, lock mechanism
3.4 Multi-thread implementation
1. Integrate Thread class, rewrite (overwrite here refers to override) run method, call start method to execute.
2. Implement the Runable interface, implement the run method, and create thread objects with Runable instances.
3. Implement the Callable interface, implement the call method, the FutureTask wraps the callable interface, the FutureTask object creates a thread object, and the asynchronous operation is used in common language. It is recommended to use anonymous inner classes for easy reading and use.
Additional notes are:
1. Understand the thread join method;
2. Don't think that volitate is thread-safe (for suggestions that don't understand the reason, see the memory allocation strategy at the jvm runtime);
3. There is no guarantee that the CPU will be obtained immediately after the sleep time slice.
4.ThreadLocal can maintain a copy of the variable for each thread, often used to exchange space for time in multiple threads.
4. Open source framework
4.1 Hibernate, Mybatis
I believe that every Java programmer is no stranger to these, and I wo n’t go into details here.
The main points that need to be explained are as follows:
1. Hibernate first-level cache (built-in session cache), second-level cache (sessionFactory cache can be equipped), the second-level cache will cause concurrency problems.
2. Understanding the principle of hibernate lazy loading.
3. Hibernate get, load method, sava, persist, savaOrUpdate method difference
4. The session is re-established but the relationship is not synchronized and updated with the database
5. Hibernate session relationship: detached object, persistent object
6.Spring data integration, annotation configuration attributes and entities.
7. Mybatis plugin.
8. Paging query (database).
9. Connection pool technology
4.2 Spring IOC
4.1.1 Spring bean
1. Bean injection Annotation method is easy to read, and references to third parties (database connection, database connection pool, JedisPool, etc.) adopt the configuration file method.
2. Bean scope: Singleton, prototype, request, session, global session
3.bean life cycle: as shown below (picture from the Internet):
A
4.3 Spring AOP
Basic concepts: focus, aspect, pointcut, joinpoint, advice, weave, introduction.
Spring AOP supports 5 types of notifications, namely MethodBeforeAdvice, AfterReturningAdvice, ThrowsAdvice, MethodInterceptor, IntroductionInterceptor (the name is too long)
Is implemented as follows:
1. Agent-based AOP
2. Based on @Aspect annotation driven aspect. (Highly recommended: good readability, easy maintenance, easy expansion, fast development)
3. Pure POJO section.
4. Injection Aspect.
4.4 Srping transaction
4.4.1 Business communication
Concept: Certain operations need to be guaranteed atomic, if something goes wrong, the transaction needs to be rolled back. If a transaction is rolled back, then the action of the transaction in the method that called the transaction is transaction propagation.
Unclear writing in a short time, it is recommended to visit http://www.cnblogs.com/yangy608/archive/2010/12/15/1907065.html to view.
testtesttest 想要一个翻译器 另外能互cue互相留言回复么 屏幕显示比例似乎不是很友好 太大了 界面东西有点多 感觉还可以更清晰