Java Backend 1-year Experience and Technology Summary (1)

1. The introduction

It has been more than a year since I graduated. During this year, I have learned a lot thanks to my technical management staff and colleagues for their help. During this year, I have taken some detours, encountered some difficulties, and suffered from the frustration of being a developer but often being a firefighter for system maintenance and release. Then decided to comb the thing that oneself have learned, share for everybody.

After a year, I realized that there were many misunderstandings before, such as:

Fond of collecting, often collect all kinds of information video crammed into a hard drive, and then contentedly watch capacity inaction.

Not heavy foundation, always feel a lot of basic things do not need to see, in fact, do not understand a lot of places, computer program any result will have a reason, do not only use do not know the principle, that is the processing plant. Now the IDE is so convenient to view the code, CTRL + click into the JDK to see the implementation details.

Ambitious, in the case of the computer foundation is not solid, always want to do architecture, distribution, big data and so on.

Do not pay attention to performance, only to achieve the function, SQL queries can be optimized, whether there is a clever algorithm, whether to remove large objects.

Not paying attention to expansibility, close coupling between modules, common methods are not extracted into tool classes, and the call relationship is chaotic.

This article is not focused on these, so only a few of them are listed, let’s get to the point.

2. Grammar basics

2.1 Value passing and reference passing

Maybe a lot of people are dismissive of this, thinking that I have been working for a year, are you still not familiar with this? But that’s not the case. Is everything familiar in the JDK? To start with a simple example, what do you think the elements of fatherList will look like after the code is executed?

1 year working experience as a Java backend programmer

Here’s a basic example of value passing and reference passing. You think it’s easy enough to get excited about the challenge. Look at the following. String is a reference type. If you don’t understand, take a look at the String implementation source code to see what an immutable class is and what a meta-free pattern is.

1 year working experience as a Java backend programmer

2.2 Use of collections

This part is used by almost everyone and is familiar to everyone. The picture below comes from the Internet for review. However, many complex problems can be solved by clever combination and application of the characteristics of set. Set non-repeatability, List ordering, Map key-value pairs, SortSet/SortMap ordering, I have skillfully used these in many complex business in my work, involving confidential information of the company, I will not post the code. The longer I work, the more I find these and the more ingenious I find them.

1 year working experience as a Java backend programmer

2.3 Exception Handling

1. It’s easy to look at try, catch, and finally, but when combined with transaction propagation, it becomes extremely complicated.

2. Finally does not have to be executed. Return handles the situation in catch/finally (it is recommended to try it yourself).

3. User-defined exceptions can continue to be thrown in catch (and the exceptions are passed step by step to the control layer, encapsulated by section capture, and returned to the caller).

2.4 Object-oriented thinking

When it comes to object orientation, everyone knows about abstraction, encapsulation, inheritance, and polymorphism. But how much do you know from actual work experience, not to mention how to skillfully use estimates in projects?

For example, each control layer method may need to obtain a login user ID through security, which is used to operate different data according to different users. An application layer base class can be abstracted to implement the protect method to obtain the ID. Similarly, the DAO layer can use generics to extract a base class that contains additions, deletions, changes and reviews.

When it comes to object-oriented, it is inevitable to say design mode. In work, a technical master wrote a similar strategy mode (more complex), which is very clever to solve the same method of various businesses, and realize the decoupling of order, work order and business. I admire it very much. I think a lot of interviews will ask the singleton model, have no understanding of the suggestion to have a look. 1. Those with 1-5 work experience, who do not know where to start in the face of the current popular technology and need to break the technical bottleneck can add group. 2. I have been in the company for a long time and have been comfortable, but I hit a wall in the interview when I changed my job. Need to study in a short period of time, job-hopping can be added to the group. 3. If you have no working experience, but have a solid foundation, and are familiar with Java working mechanism, common design ideas and common Java development framework, you can add groups. 4, feel very good B, general needs can be done. But the knowledge points learned are not systematic, it is difficult to continue to break through in the field of technology can be added. Ali Java advanced cattle live explain knowledge points, share knowledge, the above five topics are all the teachers for many years of work experience and summary, with everyone to establish their own technical system and technical knowledge in a comprehensive and scientific way!

3. Multithreading

3.1 Thread Safety

This is a cliche, but it is a problem and bug prone area. Thread synchronization problem does not need to write separately, presumably everyone is clear, not familiar with the suggestion baidu.

3.1.1 Thread safety Issues

1. Be aware of shared variables if there are synchronous operations in your code.

2 More than one operation can modify the same data in the table. (This is easy to overlook. Business A may operate on table A, and business B may operate on table A. Business A and BUSINESS B may also operate on table A. Even if they are in different modules and methods, thread-safety issues arise. For example, if one person accesses the business A interface and another accesses the business B interface, each business request in the Web will be processed by A separate thread, and thread-safety issues will occur.

3. Use unsafe types, such as StringBuffer, StringBuild, HashTable, HashMap, etc. In my work, I have encountered someone in the for loop to remove the list, although the compiler does not report an error, the program can run, but the result is predictable.

4.Spring beans are singletons by default, so be careful if there are class variables (normally no one uses class variables in the control layer, business layer, DAO layer, etc.).

5. Multiple systems share a database, which is similar to a distributed system

The user repeatedly submits the problem (even if there is a restriction on reading from the database in the code does not solve the problem)

3.1.2 Thread Safety Solution

Use safe types where synchronization is required.

JDK lock, tryLock, synchronized, wait, notify, notifyAll, etc

Concurrent toolkit, for handling some problems, who knows? Strongly suggest to view the source code!

Table lock. (Not recommended unless a table is accessed very infrequently.)

Distributed, using middleware technology such as ZooKeeper.

3.2 the asynchronous

Asynchronous scenarios Do not affect the main thread and slow response services. For example, I/O operations and third-party services such as SMS verification codes, APP push, and cloud storage upload.

If there are a lot of asynchronous tasks, you need to use task queues, which can be implemented at the code level, or you can leverage Redis (too obvious an advantage).

3.3 Multi-threaded Communication

There are many articles in this area, not detailed here.

1. Sharing variables (sharing files, global variables, semaphore mechanism, etc.)

2. Message queue mode

  1. Busy, etc., locking mechanism

3.4 Multi-thread Implementation

1. Integrate Thread class, override (override here refers to override) run method, call start method execute.

2. Implement the Runable interface, implement the RUN method, and use the Runable instance to create Thread objects.

3. Implement Callable interface, implement call method, FutureTask package Callable interface, FutureTask object create thread object, commonly used asynchronous operation, it is recommended to use anonymous inner class, easy to read and use.

Additional notes:

1. Understand the join method of thread;

2. Do not think of Volitate as thread-safe (see JVM run-time memory allocation policies if you do not understand why);

3. CPU acquisition is not guaranteed immediately after the sleep time slice ends.

4.ThreadLocal can maintain a copy of variables for each thread and is often used to trade space for time in multiple threads.

Open source frameworks

4.1 the Hibernate, Mybatis

I believe that every Java programmer is familiar with these, not detailed here.

The following points need to be explained:

Hibernate level 1 cache (built-in session cache), level 2 cache (with sessionFactory cache), level 2 cache can cause concurrency problems.

2. Understanding of hibernate lazy loading principle.

Hibernate get and load methods, sava, persist, savaOrUpdate methods are different

4. Session reestablishes the association but does not synchronize or update the database

Hibernate Session association: detached object, persistent object

6.Spring Data integration, annotating configuration of properties and entities.

7. Mybatis plug-in.

8. Paging query (database).

9. Connection pooling technology

4.2 the Spring IOC

4.1.1 Spring bean

1. Bean injection annotation method is easy to read, and reference third party (database connection, database connection pool, JedisPool, etc.) adopts configuration file method.

  1. Bean scope: Singleton, Prototype, Request, Session, Global Session

3. Bean life cycle: as shown below (picture from Internet) :

1 year working experience as a Java backend programmer

4.3 Spring AOP

Basic concepts: Concerns, Aspect, pointcut pointcut, JoinPoint, Advice, Weave, Introduction.

Spring AOP supports type advice in 5, MethodBeforeAdvice, AfterReturningAdvice, ThrowsAdvice, MethodInterceptor, IntroductionInterceptor

The implementation is as follows:

Proxy-based AOP

2. Annotation-driven aspects based on @aspect. (Highly recommended: readable, easy to maintain, easy to expand, fast to develop)

3. Pure POJO section.

4. Injection Aspect section.

4.4 the Srping affairs

4.4.1 Transaction propagation

Concept: Some operations need to be atomic, and if something goes wrong, the transaction needs to be rolled back. If a transaction is rolled back, how the transaction behaves in the method calling the transaction is called transaction propagation.

In a short period of time to write not clear, it is suggested that visit www.cnblogs.com/yangy608/ar… Look at it.

Transaction propagation properties:

  1. PROPAGATION_REQUIRED– Supports the current transaction, or creates a new one if there are none. This is the most common choice.

  2. PROPAGATION_SUPPORTS– Supports the current transaction, and executes non-transactionally if there is no transaction currently.

  3. PROPAGATION_MANDATORY– The current transaction is supported, and an exception is thrown if there is no transaction currently.

  4. PROPAGATION_REQUIRES_NEW– Creates a transaction, and suspends the current transaction if one exists.

  5. PROPAGATION_NOT_SUPPORTED– Executes an operation in a non-transactional manner, and suspends the current transaction if one exists.

  6. PROPAGATION_NEVER– Executes non-transactionally, throws an exception if a transaction currently exists.

Transaction isolation level:

ISOLATION_DEFAULT: this is a PlatfromTransactionManager the default isolation level, using the database to the default transaction isolation level. The other four correspond to JDBC isolation levels

  1. ISOLATION_READ_UNCOMMITTED: This is the lowest isolation level for a transaction, allowing another transaction to see the uncommitted data of this transaction. This isolation level produces dirty reads, non-repeatable reads, and phantom reads.

  2. ISOLATION_READ_COMMITTED: Ensures that data modified by one transaction is committed before it can be read by another transaction. Another transaction cannot read uncommitted data from that transaction

  3. ISOLATION_REPEATABLE_READ: This transaction isolation level prevents dirty, non-repeatable reads. But illusionary reading can occur. In addition to ensuring that one transaction cannot read uncommitted data from another transaction, it also ensures that the following situation (unrepeatable reads) is avoided.

  4. ISOLATION_SERIALIZABLE This is the most expensive but reliable transaction isolation level. Transactions are processed for sequential execution. In addition to preventing dirty read, not repeat read, but also avoid phantom read.

4.5 Other Spring technology stacks

Spring Boot lightweight startup framework

Spring Security user rights management. According to roles and users, UserDetailsService is implemented to manage user rights.

Spring Task is a code-level scheduled task, annotated, and very easy to use. Note that if a scheduled task is abnormal and not handled, the next scheduled task becomes invalid. If the tasks are independent of each other, you can simply surround them with try and catch (we’ve failed with this before).

Spring Data annotations define entities, attributes, and so on

Spring MVC is a straightforward MVC framework. Url pass value, array pass value, object pass value, object array pass value, upload/download file types need to pay attention to.

Spring restful is very strict about naming.

It is very convenient to use spring shell command line to execute commands, put out fires, import and export data, and make reports.

5. The Web based

5.1 Starting the Web Container

1. Web. XML loading sequence: Listener -> filter -> servlet

2. Webt container startup process, Java beginners is very afraid of the configuration file, understanding these help to familiar with the configuration file blog.csdn.net/u014431852/…

5.2 Servlet, Interceptor, Listener, and Filter

Servlets receive requests and return responses, the most primitive web business processing class.

The HandlerInterceptor interface can be customized Interceptor. It is used in logging, permission checking, performance monitoring, and common behavior scenarios. It is ESSENTIALLY AOP.

The Listener is used for vertical functions, such as collecting online statistics.

Filter The Filter changes the REQUSET before the request interface processes the service, and changes the response after the service process before the response to the user. If some data is not encrypted, it is easy to use the packet capture tool and filter to cheat.

5.3 Web Project Structure

5.3.1 MVN structure

Familiar with several common MVN project structures, MVNS can be generated automatically and will not be detailed here.

5.3.2 MVN Package Management

1. Keep multiple version numbers in one file for easy management.

2. The Spring Milestone package resolves spring package conflicts.

3. MVN Dependency :tree analyzes all package dependencies and wraps those in a POM file

5.3.3 Version Control

1. The git, SVN, etc

2. Code conflict resolution

3. Branch management.

When a stable release goes live and new features are developed on top of it, be sure to create a new branch, commit code to the new branch, and finally merge the branches when a new release is released. Change bugs in the operating environment by switching to the main branch

5.4 the Http request

5.4.1 Request method

Post, GET, PUT, HEAD, DELETE, copy, move, connect, link, and patch are the most commonly used.

5.4.2 Request Header, status code

Common request headers include Accept (used for downloading files), Accept-Charset (set utF-8 character set), and Content-Type (json configuration)

Common response headers include content-type, content-Type, and content-Length.

  1. System architecture

Contact is not very much, the current use is only the server master/slave backup. Nginx reverse proxy configuration.

Multiple projects nginx configuration

Spring Mvc interacts with JSON data and configures the JSON transformation servlet.

Encapsulate return value

Custom RunEnvironmentException (status code, reason) that overrides the original Exception, and the section ExceptionHandler captures the Exception and encapsulates it into the return value (front and back loosely coupled)

The headache of repeated user submissions (quick clicks in succession) and front-end restrictions treating the symptoms rather than the root cause; Back end with SessonID in the section to achieve, and the need for front-end storage, all request data plus sessionId. Finally, jEDis storage, with interface name + user name as the key, according to different interfaces for different keys can be set separately, not only to ensure that repeated submission problems, but also to avoid malicious request problems, but also to customize the request interval. (At the beginning, I was worried that the redis cache read and write time delay would cause the limit to be invalid, but later I found it was too much. For the general small system, the performance test found that even if the request frequency was increased by 100, the limit would not be invalid.)

TestNg unit tests, performance tests, and coverage tests.

Section management date, permissions. Cache, etc.

  1. Nosql

1.Redis Java library Jedis.

Jedispool configuration.

The project uses the task queue, cache.

2. Neo4j graph database

Deal with social networking and recommendations

  1. The service side

Centos is used as an example.

Commonly used simple command: SSH, vim, SCP, ps, gerp, sed, awk, cat, tail, df, top, shell, chmod, sh, tar, find, wc, ln, |

Directory structure details :/etc/, ~/, /usr/, /dev/, /home/, and /etc/init.d/

Server: JDK, Tomcat, nginx, mysql, jedis, neo4j startup and configuration (especially for the firewall, nginx has been unable to access, search for a afternoon to find the cause, finally found the firewall problem)

Monitor server status (CPU, disk, memory), locate PID, and view logs

Nginx load balancing, reverse proxy, configuration

Automated deployment scripts

Simple shell script writing, avoid a lot of human labor.

Monitors the system. Fatal is abnormal. Emails are automatically sent.

  1. Database correlation

  2. Third-party Interface Interconnection

10.1 Payment Interface

There are many pits in wechat payment, and it took nearly two weeks to complete all the wechat payment. There are too many places to configure in wechat background.

The Alipay payment module only took 2 days to get it done.

10.2 Push Interface

Define tags and aliases for users. When data is updated, update the tags and aliases simultaneously. If asynchronous implementation is not adopted (user experience is good card)

10.3 cloud storage

A large number of files are uploaded to the cloud (qiniuyun), pay attention to create a bucket

10.4 SMS Verification

Very simple third-party interface, introduce dependencies, direct call. You need to configure a template on the third-party background to limit user access times.

10.5 the mail

Very simple little functionality, utility class.

Time is limited, so I will write so many technology stacks for now. For code writing and algorithm skills, I will spare some time to write in (2).

Mp.weixin.qq.com/s?__biz=MzU… Join “Java Advanced Architecture” public account, share open source, learn architecture, learn progress together,