当前位置:网站首页>Eight part essay that everyone likes
Eight part essay that everyone likes
2022-07-06 16:56:00 【LuckyShawn】
One 、 Basics
1. Basic data type
- integer :byte(8)、short(16)、int(32)、long(64)
- floating-point :float(32)、double(64)
- Boolean type :boolean(8)
- Character :char(16)
2.String、StringBuffer、StringBuilder
- String from char[] Array composition , Used final modification , Is immutable , It can be understood as a constant , Thread safety ; Yes String Each time a change is made, a new String object , Then point the pointer to the new reference object .
- StringBuffer Thread safety ;StringBuiler Thread unsafe .
- To manipulate a small amount of character data String; Single thread operation of a large amount of data with StringBuilder; Multithreading a lot of data with StringBuffer.
Two 、 aggregate
1.List( Linear structure )
- ArrayList Object[] Array implementation , The default size is 10 , Support random access , Continuous memory space , Insert end time complexity o(1), Insert first i Location time complexity o(n - i). Capacity expansion , The size changes to 1.5 times ,Arrays.copyOf( Bottom System.ArrayCopy), Copy to new array , Pointer to the new array .
- Vector similar ArrayList, Thread safety , The default growth of capacity expansion is the original 2 times , You can also specify the length of the growth space .
- LinkedList Based on linked list ,1.7 Double linked list ,1.6 It is a two-way circular linked list , Canceling the loop can better distinguish the head from the tail .
2.Map(key-value Key value pair )
HashMap
- Underlying data structure ,JDK 1.8 It's an array + Linked list + Red and black trees ,JDK 1.7 No red and black trees . The list length is greater than 8 when , Turn it into a red-black tree , Optimize query efficiency .
- The initial capacity is 16, adopt tableSizeFor The guaranteed capacity is 2 Power square . Addressing mode , High XOR ,(n-1)&h modulus , Optimize speed .
- Expansion mechanism , When the number of elements is greater than the capacity x Load factor 0.75 when , Capacity expanded to the original 2 times , Create a new array , Then move to the new array .
- be based on Map Realization . Thread unsafe .
HashMap (1.7) Multithreaded circular linked list problem
- In multithreaded environment , When expanding the capacity ,1.7 Under the HashMap Will form a circular linked list .
- How to form a circular linked list : Suppose there is a HashMap Capacity of 2 , Subscript in the array 1 Position in A -> B Linked list storage . There is a thread on the map do put operation , Due to triggering expansion conditions , Need to expand . At this time, another thread also put operation , Capacity expansion is also required , And completed the expansion operation , Since copying to the new array is a header insert , therefore 1 The position changes to B -> A . At this time, the first thread continues to expand , Copy first A , And then copy it B , To determine B.next Whether it is empty time , Because the second thread does the capacity expansion operation , Lead to B.next = A, So in the A Put it in B front ,A.next It's equal to B , Cause the circular linked list to appear .
HashTable
- Thread safety , The method basically uses Synchronized modification .
- The initial capacity is 11 , Capacity for 2n + 1 .
- Inherit Dictionary class .
3、 ... and 、 Multithreading
volatile
- In multithreaded environment , Ensure the visibility of variables . Used volatile After modifying variables , After the variable is modified, it will be synchronized to main memory immediately , Every time this variable is used, it will be refreshed from main memory .
- prohibit JVM Instruction reordering .
- Why the singleton mode double check lock variable is used volatile modification ? prohibit JVM Instruction reordering ,new Object() There are three steps : Apply for memory space , Assign a memory space reference to a variable , Variable initialization . If reordering is not prohibited , It is possible to get an uninitialized variable .
Four 、JAVA virtual machine
1. Memory model
- Pile up Shared by threads , Deposit new Out object , This is the main working area of the garbage collector .
- Stack Thread private , It is divided into Java Virtual machine stack and local method stack , Store the local variable table 、 Stack operation 、 Dynamic links 、 Method exit information , The execution of the method corresponds to the process from entering the stack to exiting the stack .
- Method area Thread sharing , Store the loaded class information 、 Constant 、 Static variables 、 Real time compiler compiled code and other information ,JDK 1.8 The method area is replaced by a meta space , Use direct memory .
2. Class loading mechanism
- Parent delegation mode
When a class needs to be loaded , Judge whether the current class has been loaded . Classes that have already been loaded will directly return , Otherwise, it will try to load . When loading , First, the request will be delegated to the parent loader loadClass() Handle , So all requests should eventually be sent to the top-level boot loader BootstrapClassLoader in . When the parent loader cannot process , It's up to me to deal with . When the parent loader is null when , Will use boot class loader BootstrapClassLoader As a parent loader .
3. It can be used as GCRoot The object of
- a) Objects referenced in the virtual machine stack ( Local variables in stack frames )
- b) Object referenced by a class static property in a method area
- c) The object referenced by a constant in the method area
- d) Local method stack Native Method reference object
5、 ... and 、 database
1. Clustered index and non clustered index
- All use B+ Trees as data structures
- The data in the cluster index exists in the leaf node of the primary key index , obtain key Or get data ; There is a separate space for non clustered index data .
- The leaf node of the auxiliary index in the cluster index stores the primary key ; In the non clustered index, the leaf node stores the address of the data ;
- The advantage of clustered index is to find data when you find the primary key , Just one disk IO ; When B+ When the nodes of the tree change , The address will also change , At this time, the non clustered index needs to update all addresses , Increased overhead .
2. Why use B+ Tree as index
disk IO The number of times is an important index to measure the quality of index data structure
B+ Tree as database index :
1. A single node stores more elements , Make the tree fatter , Of the query IO Fewer times
2. All data is placed on leaf nodes , All queries need to find leaf nodes , Query performance is stable
3. Because leaf nodes form an ordered linked list , Easy range query .
3. When can I use it B Tree index
- The primary foreign key needs to be indexed
- It is best to index the data columns that are often queried
- For data columns that need to be queried quickly or frequently within the specified range , Because the index is sorted , Its specified range is continuous , Queries can take advantage of the sorting of indexes , Faster query time
- Often used in where Data column in clause , Index on where Clause , For data columns that need to be accelerated or retrieved frequently , These data columns that often participate in the query can be queried according to the sort of index , Faster query time .
边栏推荐
- Typescript basic operations
- 这群程序员中的「广告狂人」,把抖音广告做成了AR游戏
- @RequestMapping、@GetMapping
- 7-8 likes (need to continue to improve)
- ~87 animation
- 字节跳动技术新人培训全记录:校招萌新成长指南
- Fdog series (III): use Tencent cloud SMS interface to send SMS, write database, deploy to server, web finale.
- [unsolved]7-14 calculation diagram
- 音视频开发面试题
- Monomer application concept
猜你喜欢
"One year after graduation, I won ACL best paper"
字节跳动新程序员成长秘诀:那些闪闪发光的宝藏mentor们
Fdog series (4): use the QT framework to imitate QQ to realize the login interface, interface chapter.
字节跳动技术面试官现身说法:我最想pick什么样的候选人
~69 other ways to use icon fonts
redux使用说明
Shell_ 01_ data processing
Audio and video development interview questions
Many papers on ByteDance have been selected into CVPR 2021, and the selected dry goods are here
~73 other text styles
随机推荐
7-5 blessing arrived
TCP的三次握手和四次挥手
Typescript basic operations
[unsolved]7-14 calculation diagram
string. How to choose h and string and CString
~78 radial gradient
Eureka single machine construction
Cmake error: could not create named generator visual studio 16 2019 solution
Codeforces Global Round 19
Mp4 format details
Native JS realizes the functions of all selection and inverse selection -- Feng Hao's blog
Jedis
数据传送指令
ByteDance new programmer's growth secret: those glittering treasures mentors
Error: case label `15 'not within a switch statement
Cartesian tree (modified)
LeetCode 1562. Find the latest group of size M
The 116 students spent three days reproducing the ByteDance internal real technology project
Solr new core
Conception du système de thermomètre numérique DS18B20