Some personal interview questions

The difference between jdk and jre

jre is the environment for running Java programs, and a tool for compiling Java code in jdk, including some simple libraries

The difference between Oracle jdk and open jdk

The former is updated slowly and the latter is updated quickly, the former is after the acquisition, and the latter is before the acquisition

The difference between Java and javax

javax is extended, and then the two are combined

How the thread is started

Implement the Runnable interface and inherit the Thread class

If a class inherits the Thread class, it is not suitable for multiple threads to share resources, and the implementation of the Runnable interface can facilitate resource sharing.

Types of collections, which are ordered and unordered

List, set, map, queue,
list are ordered, set and map unordered
set bottom layer is map, map is the
only value of key and value set, the value of list may not be unique, the subscript of map is unique, and the value is not unique

Hashmap bottom layer

The bottom layer is a hash table
before jdk1.8, using array + linked list form
after jdk1.8, conflicts less than 8 use array + linked list form, >=8 use red-black tree
Why not balanced binary tree? Because the balanced binary tree is still a linear tree under certain circumstances,
then if you set the capacity, it will be in the form of a power exponent.

MySQL tuning

emmm

The characteristics of the transaction

The four characteristics, acid
ACID, refer to the abbreviation of the four basic elements for the correct execution of database transactions. Including: Atomicity, Consistency, Isolation, Durability

GC garbage collection algorithm

Commonly used are 标记清除, 复制, 标记整理and 分代收集algorithm

Mark clear

The mark removal algorithm is divided into two stages: "marking" and "clearing". Mark all objects that need to be recycled, and collect them uniformly after marking. This routine is very simple and has shortcomings. The subsequent algorithms are all improved on this basis.

In fact, it is to mark the dead object as free memory, and then record it in a free list. When we need a new object, the memory management module will look for free memory from the free list to allocate it to the new object.

Human words: Mark the dead and useless objects and record them in a free list. When you want to new an object, take it from the free memory.
Insert picture description here

Copy algorithm

Divide the memory into 2 sides equally, one side is empty and the other side is used. Use the side that is used for normal use. Put the trash, unused, and still-used ones together. Then when they are full, remove the trash, put the still-used ones on the other side, and empty your own side.
Insert picture description here

Tag sorting algorithm

The replication algorithm will have certain efficiency problems when the object survival rate is high. The marking process is still the same as the "mark-sweep" algorithm, but the subsequent steps are not to directly clean up the recyclable objects, but to make all surviving objects to one end Move, and then directly clean up the memory outside the boundary
Insert picture description here

Generational collection algorithm

This algorithm does not have any new ideas, but divides the memory into several blocks according to the life cycle of the object. Generally, the Java heap is divided into the new generation and the old generation, so that the most appropriate collection algorithm can be adopted according to the characteristics of each generation. In the new generation, a large number of objects are found dead each time a garbage collection, and only a few survive, then the replication algorithm is selected, and the collection can be completed only by paying a small amount of the replication cost of the surviving objects. In the old age, because the object has a high survival rate and no extra space for its allocation guarantee, it is necessary to use the "mark-clean" or "mark-sort" algorithm for recycling.

Human words: It is to divide the memory, put different types in no batch of spaces, and then which spaces are cleared according to the above algorithm

Three paradigm

The first normal form: that is, the columns of the table are atomic and cannot be decomposed, that is, the information in the columns cannot be decomposed.
Human words: each field can't be divided anymore, it is already the smallest element

Second normal form: In the case of satisfying the first normal form, a primary key is the second normal form

Third normal form: In the case of satisfying the second normal form, non-primary key fields cannot depend on each other

What engine does MySQL use

Innodb: default, support transaction security, support row-level locks, used to add and modify,

By default, it
supports transactions, is transaction safe, provides row-level locks and foreign key constraints, and has a buffer pool for buffering data and indexes

Applicable scenarios: used for transaction processing, with ACID transaction support, applied to tables that perform a large number of insert and update operations

MyISAM: does not support transactions, foreign keys, locks, used for checking

Does not support transactions, does not support foreign key constraints, does not support row-level locks, the entire table needs to be locked during operation, but the number of rows in the table is saved, so the execution is particularly fast when executing select count(*) from tablename

Applicable scenarios: used to manage non-transactional tables, provide high-speed retrieval and full-text retrieval capabilities, suitable for tables with a large number of select operations, such as log tables

MEMORY: for precise search

The table is created using the content in the memory, and each memory actually corresponds to only one disk file. Because it exists in memory, the memory access speed is very fast, and the engine uses a hash index, which can be located at one time. It does not need to find the branch node from the root node like a B-tree, so the access speed is very fast for precise query, but it is not When searching accurately, such as like, this kind of range search, hash will not work. In addition, once the service is shut down, the data in the table will be lost because it is not stored in the disk.

Applicable scenarios: Mainly used for tables with infrequent content changes, or as an intermediate lookup table. Be cautious when updating the table because the data is not written to the disk, and consider the storage of the data before shutting down the service

The difference between == and equals

In the basic types (int, float), == and equals are the same

In the reference type (String), ==compare the addresses of the two, equalscompare the value in the address

String 、Stringbuffer 、Stringbuilder

The principle of the three, the difference

In the storage char array of String, there is a final limitation, that is, it will not be inherited by other classes. For
example, to modify things in String, its essence is not to modify, but to create a new char[] array, assign it to it, and then assign char[] to String

Stringbuffer has no final restriction, there is synchronization lock
Stringbuilder has no final restriction, no synchronization lock

Which are safe and which are not safe

String and Stringbuffer are safe because String has final and Stringbuffer has synchronization lock.
Stringbuilder is not safe because there is no final and synchronization lock.

Respective scope of application

Single-threaded data volume is large, using Stringbuilder
multi-threaded data volume is large, using Stringbuffer

How to remember?

String has a final all know it
Stringbuffer Well, there is buff, so there and 处理多线程
Stringbuilder still buildin nothing, therefore 不安全, we can only deal with 单线程大things

MySQL data types

Numerical type

tinyint smallint mediumint int bigint float double mecimal
Where the precision mecimal>double>float

Time type

date time datetime timestamp

Character type

char varchar BLOB text

Java basic types

布尔、byte、short、int、long、float、double、char

The difference between tcp and udp protocol

Insert picture description here
UDP is used for network calls and TCP is used for SMS sending

Speed

udp is faster than tcp

In number

udp: one-to-one, one-to-many
tcp: one-to-one, point-to-point

reliability

TCP is reliable, because the 3-way handshake
udp is unreliable, just send, no handshake

3-way handshake

Insert picture description here
Insert picture description here

Client-send data packet with SYN flag-one handshake-server server
-send data packet with SYN/ACK flag-two handshake-
client client-send data packet with ACK flag –Three handshake – server

Why do you need to shake hands

The purpose of the three-way handshake is to establish a reliable communication channel. When it comes to communication, it is simply the sending and receiving of data. The main purpose of the three-way handshake is to confirm that the sending and receiving between themselves and the other party is normal.

The first handshake: Client cannot confirm anything; Server confirms that the other party is sending normally, and it is receiving normally

Second handshake: Client confirmed: sending and receiving are normal by itself, sending and receiving by the other party are normal; Server confirming: sending and receiving by the other party is normal, and receiving by itself is normal

The third handshake: Client confirmed: sending and receiving by itself is normal, sending and receiving by the other party is normal; Server confirming: sending and receiving by itself is normal, and sending and receiving by the other party are normal

Therefore, the three-way handshake can confirm that the dual sending and receiving functions are normal, and one is indispensable.

The difference between HashMap and TreeMap

Insert picture description here
Implementing the NavigableMap interface gives TreeMap the ability to search for elements in the collection.

Implementing the SortMap interface gives TreeMap the ability to sort the elements in the collection according to the key. The default is to sort by key in ascending order

Guess you like

Origin blog.csdn.net/yi742891270/article/details/113916660