Summary of java basic knowledge

Irving the procedural ape 2020-11-11 10:10:16
summary java basic knowledge


java Back end 5 Year experience and technical summary
1. introduction  
Graduation has been 5 Over the year , this 5 Special thanks to the technical management staff for their respect during the year , And the help of colleagues , I learned a lot . this 5 Through some detours in the year , There are also some problems , I've also suffered from being a developer and being a firefighter for system maintenance and release . So I decided to sort out what I had learned , Let's share it with you . 
After a year, I realized that there were many misunderstandings before , such as : 
Preference for collection , Often collect all kinds of information, video jam hard disk , And then contentedly watch the capacity do not act . 
No emphasis on foundation , I always feel that many basic things don't need to be looked at again , In fact, there are many things I don't understand , In terms of computer programs, there must be a reason for any result , Don't just know the principle , That's from the processing plant . Now? ide It's so convenient to look at the code ,ctrl+ Click to enter JDK View implementation details . 
reach for what is beyond one 's grasp , In the case of weak Computer Foundation , Always want to do the structure , Get distributed , Big data and so on . 
No emphasis on Performance , Only the function can be realized ,sql Query can be optimized , Is there an algorithm , Do you want to clear large objects . 
No emphasis on scalability , Close coupling between modules , Common methods are not extracted into tool classes , Call relationship confusion and other issues . 
…… 

PS: If you also encounter many problems in the process of study or work , You can check my bulletin board , Answer as you ask , And some of the things I've been working on these days Java Learning manual , Interview questions , development tool ,PDF Document book tutorial , If you need it, you can share it for free .


This article does not focus on these , So only a small part of , Let's get to the point .

2. elements of grammar

2.1 Java Class initialization order  
This is the order of class initialization in all cases , If there is no definition in the actual class, skip : Parent static variables —— Parent static code block —— Subclass static code block —— The parent class is not a static variable —— Parent class non static code block —— Parent constructor —— Subclass nonstatic variables —— Subclass non static code block —— Subclass constructor  
2.2 Value passing and reference passing  
Maybe a lot of people are dismissive of it , I thought I had been working for a year , Not familiar with this ? But this is not the case ,JDK Are you familiar with everything in Chinese ? Start with the simplest example , You think after the code in the figure below has been executed fatherList What is the element in ? 
 
This is a basic example of value passing and reference passing , You think it's easy , I'm ready for a challenge , So look at the following ,StringBuffer Well understood. , But when you do it again, you find that the output is not the same as expected ?String Isn't it a reference type , How could this happen ? If you can't understand , So please have a look String Implementation of the source code , Understand the implementation principle of its allocation in memory . 
 
2.3 Use of collections  
This part is used by almost everyone , And we are all familiar with it . The figure below is from the Internet , For your review . But the use of the characteristics of the set for clever combination can solve many complex optimization problems .Set Non repeatability ,List The order of ,Map The key/value pair ,SortSet/SortMap The order of , I have a lot of complicated business in my work, which I use skillfully , Involving company confidential information , I won't post the code . The longer you work, the more you discover it and the more ingenious . 
 
2.3 exception handling  
1. Look at try、catch、finally Very easy to , If combined with transaction propagation , It becomes extremely complicated . 
2.finally It doesn't have to be enforced ,return stay catch/finally Medium treatment ( I suggest you try it yourself ). 
3.catch You can continue to throw custom exceptions in ( And pass the exception step by step to the control layer , Using facet grabbing to encapsulate exceptions , Back to the caller ). 
2.4 Object oriented idea  
First, object oriented , We all know the abstract 、 encapsulation 、 Inherit 、 Polymorphism . But how much do you know from your actual work experience , How to use estimates skillfully in a project, let alone . 
Common opportunities each need to use to build a base class , For example, each control layer method may have to pass security Get a login user id, It is used to operate different data according to different users , You can abstract an application layer base class , Implement access id Of protect Method . Empathy DAO Layer can use generics to extract a base class containing addition, deletion, modification and query . 
Polymorphic Override: The reference variable of the base class can not only point to the instance object of the base class , You can also point to an instance object of its subclass , If you point to an instance object of a subclass , The method it calls should be the method of the running object . It's very common to use in policy mode . 
When it comes to object orientation , It's inevitable to talk about design patterns , At work , A technology guru wrote a similar strategy model ( More complicated ), Very clever solution to all kinds of business, the same method , And realized the order 、 The repair order 、 Business decoupling , I admire it very much . I think a lot of interviews will ask about the single case model , Don't understand the suggestion to have a look .

3. Multithreading

3.1 Thread safety  
This is a trite question , But it's a problem bug High incidence area . Thread synchronization does not need to be written separately , I think everyone knows , Not very familiar with the proposal of Baidu . 
3.1.1 Thread safety problem  
1. If there is synchronization in the code , Special attention should be paid to sharing variables ( This one is generally aware of ) 
2 Multiple operations can modify the same data in the data table .( This is easy to ignore , Business A Possible operation table a, Business B You can also manipulate tables a, Business A、B Even in different modules and methods , It can also cause thread safety problems . If a person visits a business, for example A Interface , Another person visits the business B Interface , stay web Each business request is processed by a separate thread , There will be thread safety issues ). 
3. Unsafe type use , for example StringBuffer、StringBuild,HashTable、HashMap etc. . I've met people at work for Cycle are list Of remove, Although the compiler does not report errors , The program can run , But it turns out that . 
4.Spring Of bean The default is singleton , Be careful if you have class variables ( Generally, no one is at the control level 、 The business layer 、DAO Class variable , In other words, the suggestion is final type , Log for example log,gson etc. ). 
5. Multiple systems share databases , This is actually similar to a distributed system  
User repeated submission ( Even if there are restrictions on reading from the database in the code, it can't solve the problem ) 
3.1.2 Thread safety solution  
Use secure types where synchronization is needed . 
JDK Locking mechanism ,lock、tryLock,synchronized,wait、notify、notifyAll etc.  
Concurrent Concurrent toolkit , In dealing with some problems , Who knows . It is highly recommended to check the source code ! 
Data table locking .( Unless a table has very low access frequency , Otherwise, it is not recommended to use ) 
Involving distributed , Using middleware technology such as zookeeper Etc . 
3.2 asynchronous  
Asynchronous usage scenarios do not affect the main thread , And slow response business . for example IO operation , Third party service ( SMS verification code 、app push 、 Cloud storage upload, etc ). 
If there are many asynchronous tasks , You need to use a task queue , Task queues can be implemented at the code level , You can also use redis( The advantage is so obvious ). 
3.3 Multithreaded communication  
There are many articles in this field , I'm not going to go into details here . 
1. How to share variables ( Shared files 、 Global variables , Semaphore mechanism, etc ) 
2. Message queuing  
3. Busy etc. , Locking mechanism  
3.4 Multithreaded implementation  
1. Integrate Thread class , rewrite ( The rewriting here refers to override)run Method , call start Method execution . 
2. Realization Runable Interface , Realization run Method , With Runable Instance creation thread object . 
3. Realization Callable Interface , Realization call Method ,FutureTask packing callable Interface ,FutureTask objects creating thread object , Asynchronous operation , Anonymous inner classes are recommended , Easy to read and use . 
What's more, it should be noted that : 
1. understand thread Of join Method ; 
2. Don't think volitate It's thread safe ( If you don't understand the reason, go and see jvm Runtime memory allocation strategy ); 
3.sleep It's not guaranteed to be available immediately after the time slice is over cpu. 
4.ThreadLocal Ability to maintain variable copies for each thread , It is often used to trade space for time in multithreading . 

4. Open source framework

4.1 Hibernate、Mybatis 
Believe in each java Programmers are familiar with all this , No more details here . 
The main points to be explained are as follows : 
1.hibernate First level cache ( built-in session cache ), Second level cache ( Can be assembled sessionFactory cache ), L2 caching can cause concurrency problems . 
2.hibernate Understanding of delayed loading principle . 
3.hibernate Of get、load Method ,sava、persist、savaOrUpdate Method difference  
4.session The association relationship is rebuilt, but it is not synchronized and updated with the database  
5.hibernate session Connections :detached object 、persistent object  
6.Spring data Integrate , Annotation mode configuration properties and entities . 
7.mybatis plug-in unit . 
8. Paging query ( database ). 
9. Connection pool technology  
4.2 Spring IOC 
4.1.1 Spring bean 
1.bean Inject Annotations are easy to read , Quote a third party ( Database connection , Database connection pool ,JedisPool etc. ) In profile mode . 
2. bean Scope :Singleton,prototype,request,session,global session 
3.bean Life cycle : As shown in the figure below ( The picture comes from the Internet .........

版权声明
本文为[Irving the procedural ape]所创,转载请带上原文链接,感谢

  1. 【计算机网络 12(1),尚学堂马士兵Java视频教程
  2. 【程序猿历程,史上最全的Java面试题集锦在这里
  3. 【程序猿历程(1),Javaweb视频教程百度云
  4. Notes on MySQL 45 lectures (1-7)
  5. [computer network 12 (1), Shang Xuetang Ma soldier java video tutorial
  6. The most complete collection of Java interview questions in history is here
  7. [process of program ape (1), JavaWeb video tutorial, baidu cloud
  8. Notes on MySQL 45 lectures (1-7)
  9. 精进 Spring Boot 03:Spring Boot 的配置文件和配置管理,以及用三种方式读取配置文件
  10. Refined spring boot 03: spring boot configuration files and configuration management, and reading configuration files in three ways
  11. 精进 Spring Boot 03:Spring Boot 的配置文件和配置管理,以及用三种方式读取配置文件
  12. Refined spring boot 03: spring boot configuration files and configuration management, and reading configuration files in three ways
  13. 【递归,Java传智播客笔记
  14. [recursion, Java intelligence podcast notes
  15. [adhere to painting for 386 days] the beginning of spring of 24 solar terms
  16. K8S系列第八篇(Service、EndPoints以及高可用kubeadm部署)
  17. K8s Series Part 8 (service, endpoints and high availability kubeadm deployment)
  18. 【重识 HTML (3),350道Java面试真题分享
  19. 【重识 HTML (2),Java并发编程必会的多线程你竟然还不会
  20. 【重识 HTML (1),二本Java小菜鸟4面字节跳动被秒成渣渣
  21. [re recognize HTML (3) and share 350 real Java interview questions
  22. [re recognize HTML (2). Multithreading is a must for Java Concurrent Programming. How dare you not
  23. [re recognize HTML (1), two Java rookies' 4-sided bytes beat and become slag in seconds
  24. 造轮子系列之RPC 1:如何从零开始开发RPC框架
  25. RPC 1: how to develop RPC framework from scratch
  26. 造轮子系列之RPC 1:如何从零开始开发RPC框架
  27. RPC 1: how to develop RPC framework from scratch
  28. 一次性捋清楚吧,对乱糟糟的,Spring事务扩展机制
  29. 一文彻底弄懂如何选择抽象类还是接口,连续四年百度Java岗必问面试题
  30. Redis常用命令
  31. 一双拖鞋引发的血案,狂神说Java系列笔记
  32. 一、mysql基础安装
  33. 一位程序员的独白:尽管我一生坎坷,Java框架面试基础
  34. Clear it all at once. For the messy, spring transaction extension mechanism
  35. A thorough understanding of how to choose abstract classes or interfaces, baidu Java post must ask interview questions for four consecutive years
  36. Redis common commands
  37. A pair of slippers triggered the murder, crazy God said java series notes
  38. 1、 MySQL basic installation
  39. Monologue of a programmer: despite my ups and downs in my life, Java framework is the foundation of interview
  40. 【大厂面试】三面三问Spring循环依赖,请一定要把这篇看完(建议收藏)
  41. 一线互联网企业中,springboot入门项目
  42. 一篇文带你入门SSM框架Spring开发,帮你快速拿Offer
  43. 【面试资料】Java全集、微服务、大数据、数据结构与算法、机器学习知识最全总结,283页pdf
  44. 【leetcode刷题】24.数组中重复的数字——Java版
  45. 【leetcode刷题】23.对称二叉树——Java版
  46. 【leetcode刷题】22.二叉树的中序遍历——Java版
  47. 【leetcode刷题】21.三数之和——Java版
  48. 【leetcode刷题】20.最长回文子串——Java版
  49. 【leetcode刷题】19.回文链表——Java版
  50. 【leetcode刷题】18.反转链表——Java版
  51. 【leetcode刷题】17.相交链表——Java&python版
  52. 【leetcode刷题】16.环形链表——Java版
  53. 【leetcode刷题】15.汉明距离——Java版
  54. 【leetcode刷题】14.找到所有数组中消失的数字——Java版
  55. 【leetcode刷题】13.比特位计数——Java版
  56. oracle控制用户权限命令
  57. 三年Java开发,继阿里,鲁班二期Java架构师
  58. Oracle必须要启动的服务
  59. 万字长文!深入剖析HashMap,Java基础笔试题大全带答案
  60. 一问Kafka就心慌?我却凭着这份,图灵学院vip课程百度云