当前位置:网站首页>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 .
边栏推荐
- 搭建flutter环境入坑集合
- 谢邀,人在工区,刚交代码,在下字节跳动实习生
- LeetCode 1545. Find the k-th bit in the nth binary string
- Yao BanZhi and his team came together, and the competition experts gathered together. What fairy programming competition is this?
- MP4格式详解
- LeetCode 1560. The sector with the most passes on the circular track
- Cmake error: could not create named generator visual studio 16 2019 solution
- ~Introduction to form 80
- ~83 form introduction
- LeetCode 1447. Simplest fraction
猜你喜欢

Solve the single thread scheduling problem of intel12 generation core CPU (II)

The "advertising maniacs" in this group of programmers turned Tiktok advertisements into ar games

Erlang installation

SQL quick start

ByteDance new programmer's growth secret: those glittering treasures mentors

I'm "fixing movies" in ByteDance

音视频开发面试题

One hundred questions of image processing (1-10)

LeetCode 1020. Number of enclaves

Fdog series (4): use the QT framework to imitate QQ to realize the login interface, interface chapter.
随机推荐
~82 style of table
koa中间件
MP4格式详解
Restful style interface design
字节跳动技术新人培训全记录:校招萌新成长指南
The QT program compiled on CentOS lacks a MySQL driven solution
Codeforces Round #771 (Div. 2)
Some instructions on whether to call destructor when QT window closes and application stops
~81 long table
逻辑运算指令
The 116 students spent three days reproducing the ByteDance internal real technology project
js垃圾回收机制和内存泄漏
Educational Codeforces Round 122 (Rated for Div. 2)
7-10 punch in strategy
Go language uses the thrift protocol to realize the client and service end reports not enough arguments in call to oprot Writemessagebegin error resolution
LeetCode 1560. The sector with the most passes on the circular track
Mongodb在node中的使用
Li Kou leetcode 280 weekly match
Design of DS18B20 digital thermometer system
Shell_ 03_ environment variable