当前位置:网站首页>Summary of Android interview questions of Dachang in 2022 (II) (including answers)
Summary of Android interview questions of Dachang in 2022 (II) (including answers)
2022-07-06 17:41:00 【Code is not difficult to write】
Preface
Now ,Android The employment situation of development posts is becoming increasingly severe , Want to stand out from many interviewers , Take the big factory offer, We must sort out the knowledge points comprehensively , Expand the question bank , And for the key knowledge that may be encountered in the interview , Conduct in-depth analysis .
This article is dedicated to Android Engineer prepared high salary interview real questions summary question bank , It covers many years of large factories and has been summarized + In depth analysis of core test sites , Let your second change offer harvester .
Due to space reasons, it is divided into two parts :
Upper connection :2022 Nian Dachang Android Summary of interview questions ( One )( With answers )
Android The real question of the interview
JVM The loading principle of
1. Compiling mechanism
As can be seen from the figure below java The file has been compiled once ,java Code compiled into java Bytecode (class file ). Then use different virtual machines on different platforms (JVM) explain , Interpreted as machine code , And then execute . thus it can be seen , If we want to mac Running on the system , Just install one mac Of java Virtual machine is OK . This is the same. java A compilation of , Run anywhere
2. Class loading mechanism
1. load
Loading is simply a three-step process :
First step : Get the binary byte stream, that is, the above class file .
The second step : Transform the static storage structure into the runtime data structure in the method area .
The third step : Generate an object to put into java In the pile , As a reference to the method area .2. verification
Verification is mainly to check whether the following items are correct :
class Representation of documents ( magic number ),class Version number of the document ,class Whether each part of the document is correct ( Field table 、 Method sheets, etc ), Validate constant pool ( constant type 、 Whether the constant type data structure is correct ,utf-8 Is it standard ), Metadata validation ( Parent class validation , Inheritance verification ,final verification ), Bytecode ( Instructions ) verification , Symbol reference validation ( Whether the corresponding field can be found according to the symbol 、 surface 、 Such method )
If one item is wrong , The verification will fail .3. Get ready
The preparation phase allocates memory for class variables And set class variable initialization . In the process , Only right static Class variable for memory allocation , At this time, only memory is allocated , No replication , All class variables are initialization values . If it is final Words , Will be directly mapped to the constant pool . It will be assigned directly in the preparation stage .4. analysis
The parsing phase is to read symbolic references for parsing . Resolve symbolic references to direct references ( A pointer or offset to a target ). The parsing mainly involves classes , Interface , Field , Such method .5. initialization
Initialization is the process of executing methods , For static variables , Static code block to initialize , Initialize the class .6. Use
The use phase uses this class.7. uninstall
The uninstall phase is not in use , take class To uninstall .
3. Class loader
As shown in the figure , Whenever our class is loaded , Will go to the class loader .
Our custom loader has a parent class , Namely AppClassLoader, and AppClassLoader There is also a parent class loader ExtClassLoader,ExtClassLoader There is also a parent class loader BootstarpClassLoader,BootstarpClassLoader Is the final loader .
When loading classes , Will start class loader , I will find it through the class loader defined by myself AppClassLoader, And then through AppClassLoader find ExtClassLoader, Re pass ExtClassLoader Find the final BootstarpClassLoader.
You may see it here , Everyone has doubts , Why do I have my own loader , Why go to the loader of the parent class ? This mechanism is called the parental delegation mechanism , The purpose is to load tired security . That is to say, what my parent class loads will not be loaded by the child class , This guarantees that in the end BootstarpClassLoader To load the , You can guarantee that a class will be loaded only once . And when you judge two objects the same , The most important condition is whether a loader is used to load
The difference between global and local variables
1. Global variables are also called external variables , It is a variable defined outside the function . Which function does it not belong to , It belongs to a source program file . Its scope is the entire source program . Use global variables in functions , Generally, the global variables should be explained . Only global variables that have been specified in a function can be used . The specifier for the global variable is extern. But global variables defined before a function , Use within this function is not explained
2. Local variables are also called internal variables . Local variables are defined in functions . Its scope is limited to functions , It's illegal to use this variable after leaving the function
3. In the same source file , Allow global and local variables to have the same name . In the scope of a local variable , Global variables don't work .
4. From the perspective of scope , Global variables have global scope . Global variables only need to be defined in one source file , It works on all source files . Of course , Other source files that do not contain global variable definitions need extern Keyword declares the global variable again .
- Static local variables have local scope , It is initialized only once , It's been around since the first initialization until the end of the program , The difference between global variable and global variable is that global variable is visible to all functions , Static local variables are only visible to the function body that defines them .
- Local variables have only local scope , It's an automatic object (auto), It doesn't always exist while the program is running , It only exists during function execution , After the execution of a call to the function , Variables are revoked , The memory it uses is also reclaimed .
- Static global variables also have global scope , It differs from global variables in that if the program contains multiple files , It works in the document that defines it , It doesn't work on other documents , Namely be static Keyword decorated variables have file scope . So even if two different source files define static global variables with the same name , They are also different variables .
5. From the perspective of allocated memory space :
Global variables , Static local variables , Static global variables all allocate space in static storage , And local variables allocate space in the stack .
Global variables themselves are static storage , Static global variables are also static storage . There is no difference between the two in the way of storage . The difference between the two is that the scope of non static global variables is the whole source program , When a source program consists of multiple source files , Non static global variables are valid in all source files . Static global variables limit their scope , That is, it is only valid in the source file where the variable is defined , It cannot be used in other source files of the same source program . Because the scope of static global variables is limited to one source file , Can only be used for functions within the source file , So you can avoid causing errors in other source files .
1)、 Static variables are placed in the program's static data store ( The whole picture can be seen ) in , In this way, the original assignment can be kept at the next call . This is the difference between stack variable and heap variable .
2)、 Variable usage static Tell the compiler , I am only visible in the range of variables . This is the difference between it and global variables .
As can be seen from the above analysis , Changing a local variable to a static variable changes its storage mode, that is, its lifetime . Changing a global variable to a static variable changes its scope , It limits its use . therefore static The function of this specifier is different in different places . Attention should be paid to .
Tips:
A. If the global variable is only in a single C File access , You can change this variable to a static global variable , To reduce the coupling between modules ;
B. If global variables are accessed only by a single function , You can change this variable to the static local variable of this function , To reduce the coupling between modules ;
C. Design and use access dynamic global variables 、 Static global variables 、 When a function of a static local variable , The question of reentry needs to be considered , Because they're all in static data storage , The whole picture can be seen ;
D. If we need a reentrant function , that , We must avoid using static Variable ( Such a function is called : belt “ Internal memory ” Function of function )
E. You have to use static Variables : For example, when the return value of a function is of pointer type , It must be static The address of the local variable as the return value , if auto type , Then return to the wrong pointer .
The difference between static method locks and non static method locks
1. A lock is a class object , A lock is an instance object .
2. If a class object is lock, Then all synchronization methods of the class object (static synchronized func) All by lock.
3. If the instance object is lock, All synchronization methods of the instance object (synchronized func) All by lock.
4. About locks on methods of the same class , From the object that called the method , If the object calling the method is the same , Then the locks must be the same , Otherwise it would be different . such as new A().x() and new A().x(), Objects of different , Locks are different , If A Of simple interest , Can be mutually exclusive .
5. Static method lock , Can be locked with all other static methods Mutually exclusive
Thread local ThreadLocal The role of
When using ThreadLocal When maintaining variables ,ThreadLocal Provide a separate copy of the variable for each thread that uses the variable , So each thread can independently change its own copy , It does not affect the copies corresponding to other threads .
ThreadLocal And synchronized Comparison of synchronization mechanisms
In the synchronization mechanism , Through the lock mechanism of the object, only one thread can access the variable at the same time . In this case, the variable is shared by multiple threads , Using the synchronization mechanism requires the program to carefully analyze when to read and write variables , When you need to lock an object , When to release the object lock and so on , It is relatively difficult to design and program .
ThreadLocal It's a thread local variable , It is a solution to access variables concurrently between multiple threads . and synchronized The way of locking is different ,ThreadLocal Locks are not provided at all , Instead, use space for time , Provide a separate copy of the variable for each thread , To ensure thread safety .
There are several ways to write the singleton mode
1. Hungry Chinese style
public class SingletonInstance {
// Private constructor
private static SingletonInstance (){
}
// Declare member variables
private static SingletonInstance singletonInstance = new SingletonInstance();
// Provide an external interface to obtain the instance
public static SingletonInstance getSingletonInstance(){
return singletonInstance ;
}
}
2. Slacker type
public class SingletonInstance {
// Private constructor
private SingletonInstance (){
}
// Declare member variables
private static SingletonInstance singletonInstance ;
// Provide an external interface to obtain the instance
public static SingletonInstance getSingletonInstance(){
if(singletonInstance == null){
singletonInstance = new SingletonInstance();
}
return singletonInstance ;
}
}
3.double check lock(dcl)
public class SingletonInstance {
// Private constructor
private SingletonInstance (){
}
// Declare member variables
private static SingletonInstance singletonInstance ;
// Provide an external interface to obtain the instance
public static SingletonInstance getSingletonInstance(){
if(singletonInstance == null){
synchronized (SingletonInstance.class){
// Judge twice whether it is null
if(singletonInstance==null){
singletonInstance = new SingletonInstance();
}
}
}
return singletonInstance ;
}
}
4. Static inner class
public class SingletonInstance {
// Private constructor
private SingletonInstance (){
}
private static class Builder{
// Declare member variables
private static SingletonInstance singletonInstance = new SingletonInstance();
}
// Provide an external interface to obtain the instance
public static SingletonInstance getSingletonInstance(){
return Builder.singletonInstance ;
}
}
Deadlock
Link to the original text
Deadlock , A deadlock in which several processes compete for resources while running , When the process is in this stalemate , If there is no external force , They will not be able to move forward . So let's take an example to describe , If there is a thread at this time A, Lock it first a Get the lock again b The order of getting locks , And there's another thread at the same time B, Lock it first b Relock a The order to get the lock
1. The cause of deadlock
a. Compete for resources
There are two types of resources in the system :
Deprivable resources , It refers to a process after obtaining such resources , This resource can be taken away by other processes or systems ,CPU Both main memory and main memory belong to the deprivable resources ;
The other type of resource is an inalienable resource , When the system allocates such resources to a process , You can't take it back by force , It can only be released after the process is used up , Like a tape drive 、 Printers, etc .
One of the competing resources in deadlock refers to the competitive and undeniable resources ( for example : There is only one printer in the system , Available for process P1 Use , Assume P1 The printer has been occupied , if P2 Continuing to ask the printer to print will block )
Competing resources in deadlock generation. Another type of resource is competing temporary resources ( Temporary resources include hardware interrupts 、 The signal 、 news 、 Messages in the buffer, etc ), Usually, the order of message communication is improper , A deadlock occurs
b. The order of advancement between processes is illegal
if P1 Keep the resources R1,P2 Keep the resources R2, The system is in an unsafe state , Because these two processes move forward , A deadlock may occur
for example , When P1 Run to the P1:Request(R2) when , Will cause R2 Has been P2 Occupy and block ; When P2 Run to the P2:Request(R1) when , It will also be due to R1 Has been P1 Occupy and block , A process deadlock occurs
2. The necessary conditions for deadlock
1. mutual exclusion : Processes require exclusive control of allocated resources , That is, in a period of time, a resource is occupied by only one process .
2. Request and hold conditions : When a process is blocked by a request for resources , Keep the acquired resources .
3. Conditions of non deprivation : The resources obtained by the process are not used up , Can't deprive , It can only be released by itself after use .
4. Loop waiting condition : In the life and death lock , There must be a process – Circular chain of resources .
3. The basic solution to deadlock
1. One time allocation of resources : Allocate all resources at once , So there will be no more requests :( Break request condition )
As long as one resource is not allocated , No other resources are allocated to this process :( Please keep the condition )
2. Deprivable resources : That is, when a process gets some resources , But there are no other resources , Then release the occupied resources ( The destruction of the inalienable conditions )
Orderly allocation of resources : The system assigns a number to each type of resource , Each process requests resources in ascending order , Release is the opposite ( Destroy the loop waiting condition )
——————————————————————————
To be updated ...
1. Event distribution ,dispatch and intercept and ontouchevent How is it implemented , onTouchEvent How is it implemented
2. scene 1:addView Method loading A Layout then remove(A), then addView(B Layout ) Method execution scene 2:addView Method loading A then addView(B), requestView Method in the scene 1 and 2 How are they implemented , How efficient is their implementation
3. Layout A after scale Perform attribute scaling , After zooming y Does the coordinate of the point corresponding to the axis change
4. The difference between arrays and linked lists
5.rxjava in map and flapmap difference
6.viewGroup and view Of onDraw Method difference
7.recyclerview Cache mechanism ,item Whether to execute back when invisible onBind Method
8.requestLayout,measureLayout,invalidata difference
9. Image compression loading
10. Understanding of design patterns in the project
11. Interprocess communication
12. Singleton mode double check mechanism
13. Memory optimization
14.ANR
15.webview Handle
16.hashmap How to achieve , Extended size mechanism
17. Picture compression , Arrogant compression and quality compression
18.https Of ssl
19. Which processes communicate ,binder The underlying mechanism
20.activity Inside setContentView What did you do
21.acitvity,window,surface The three difference
22.listview and recyclerview difference
23.recyclerview Level 4 cache , How to customize cache
24.GC Recycling mechanism , How is that object recycled
25. Algorithm , Enter two linked lists , Let them output a linked list together
author :Wocus
link :https://www.jianshu.com/p/c7b6c6851231
source : Simple books
The copyright belongs to the author . Commercial reprint please contact the author for authorization , Non-commercial reprint please indicate the source .
Last
Actually Android There are so many knowledge points in development , There are still so many things to ask about in the interview . So there's no other trick to an interview , It depends on how well you are prepared for these knowledge points .
At present, there is still a lack of senior engineers , A lot of senior positions pay really high salaries ( A lot of money doesn't necessarily mean you can find the right one ), So it's important to try to be a senior engineer .
Attached here are dozens of sets of bytes related to the above interview questions , JD.COM , millet , tencent 、 headlines 、 Ali 、 Meituan and other companies 19 Interview questions for . Put the technical points into video and PDF( In fact, it took a lot more energy than expected ), Contains the context of knowledge + A lot of details .
【Android Detailed knowledge points mind map ( The skill tree )】
【BATJ Android Development Engineer Interview Question Bank 】
【 Details can be sorted and scanned, and the QR code below can be obtained for free 】
边栏推荐
- 【ASM】字节码操作 ClassWriter 类介绍与使用
- 2022年大厂Android面试题汇总(二)(含答案)
- How uipath determines that an object is null
- Interpretation of Flink source code (I): Interpretation of streamgraph source code
- BearPi-HM_ Nano development environment
- Openharmony developer documentation open source project
- Huawei certified cloud computing hica
- Redis quick start
- 远程代码执行渗透测试——B模块测试
- 当前系统缺少NTFS格式转换器(convert.exe)
猜你喜欢
Development and practice of lightweight planning service tools
Re signal writeup
Flink parsing (IV): recovery mechanism
Spark calculation operator and some small details in liunx
How does wechat prevent withdrawal come true?
2022年大厂Android面试题汇总(一)(含答案)
BearPi-HM_ Nano development board "flower protector" case
[rapid environment construction] openharmony 10 minute tutorial (cub pie)
Yarn: unable to load file d:\programfiles\nodejs\yarn PS1, because running scripts is prohibited on this system
PyTorch 提取中间层特征?
随机推荐
05个人研发的产品及推广-数据同步工具
C#版Selenium操作Chrome全屏模式显示(F11)
DataGridView scroll bar positioning in C WinForm
[VNCTF 2022]ezmath wp
Xin'an Second Edition; Chapter 11 learning notes on the principle and application of network physical isolation technology
FlutterWeb浏览器刷新后无法回退的解决方案
Hongmeng introduction and development environment construction
Re signal writeup
【ASM】字节码操作 ClassWriter 类介绍与使用
[reverse] repair IAT and close ASLR after shelling
Solution qui ne peut pas être retournée après la mise à jour du navigateur Web flutter
Pyspark operator processing spatial data full parsing (5): how to use spatial operation interface in pyspark
C WinForm series button easy to use
Chrome prompts the solution of "your company management" (the startup page is bound to the company's official website and cannot be modified)
Xin'an Second Edition: Chapter 26 big data security demand analysis and security protection engineering learning notes
Display picture of DataGridView cell in C WinForm
MySQL advanced (index, view, stored procedure, function, password modification)
华为认证云计算HICA
Flink parsing (III): memory management
EasyCVR授权到期页面无法登录,该如何解决?