1. Java based

1.1 What is optimistic Lock?

  • Optimistic locking: Assume that every time you go to retrieve data, you assume that no one else will modify it, so it won’t be locked. But when updating, it will determine whether others have updated the data during this period. Usually use the situation where you read more and write less.
  • Pessimistic locking: Assume that every time the worst-case scenario occurs, someone will change the data every time they try to get it, so every time they try to get the data, it will be blocked until it gets the lock. Used when you write more than you read.

Extended information: www.cnblogs.com/renhui/p/97…

1.2 Volatile Keyword

  1. Guaranteed visibility, not guaranteed atomicity
  2. Disallow instruction reordering
  3. It’s not cached. It’s fetched from main memory every time

Extended information: www.cnblogs.com/zhengbin/p/…

1.3 HashMap principle, what is a red-black tree?

  • 1.7 Array + Linked list: If the linked list is too long, the query efficiency degrades
  • 1.8 Array + list + red black tree, when the list length is greater than 8 to red black tree
  • The default initial size of a HashMap is 16, and the initial size must be a power of 2, with a maximum size of 2 to the power of 30. The linked list node Entry class stored in an array is implemented in the Map.Entry interface, which implements common operations on nodes. The default threshold of a HashMap is Capacity x 0.75F. If the number of storage nodes exceeds this threshold, the HashMap is expanded.
  • Thread safe container, solve the problem of concurrent use of ConcurrentHashMap (efficient) or Collections. SynchronizedMap (). Collections. SynchronizedMap () is actually add a synchroni each method Ze, in fact, is similar to HashTable.

Red and black tree

  • Balanced binary search tree
  • Nodes are red or black
  • The root node is black
  • Each leaf node is a black NULL node.
  • Two children of each red node are black
  • All paths from any node to each of its leaves contain the same black node
  • Insertion involves discoloration and rotation

Extended information: blog.csdn.net/justloveyou… www.360doc.com/content/18/…

1.4 JVM Memory Allocation

Chapter 2 in the Java Virtual Machine Book

  • Program counter
  • Java virtual machine stack
  • Local method stack
  • The Java heap
  • Methods area
  • Run-time constant pool
  • Direct memory

1.5 the String and StringBuffer, StringBuilder distinction

  • String and StringBuffer StringBuilder, eventually the underlying storage and operation is a char array. But the String inside the char array is final, and StringBuffer, StringBuilder is not, that is, the String is immutable, want the new String can regenerate the String. StringBuffer and StringBuilder only need to modify the underlying char array. Relatively speaking, the cost is much lower.
  • Most methods of String return a new String, and frequent regenerating can generate a lot of garbage.
  • StringBuffer is thread-safe,StringBuilder is thread-unsafe. Because StringBuffer methods are locked with synchronized, StringBuilder methods are not.
  • Use StringBuffer or StringBuilder (note single-threaded versus multi-threaded) to add or delete a lot of data. I’ll take what I need, now that I know how it works.

2. Android basics

2.1 Major changes of Android versions (what are the major changes from Android 6.0 to 10.0?), compatibility and adaptation

The Android 5.0

  • Material Design
  • The ART of the virtual machine

The Android 6.0

  • Application Permission Management
  • Official fingerprint support
  • Doze Power Management
  • Runtime permission mechanism -> Dynamic permission application is required

The Android 7.0

  • Multi-window mode
  • Supports the Java 8 language platform
  • You need to use a FileProvider to access photos
  • Apk installation requires compatibility

The Android 8.0

  • Notification, channel -> adaptation
  • Picture in picture
  • Automatic filling
  • Background restrictions
  • Adaptive desktop icon -> Adaptation
  • Implicit broadcast restrictions
  • Enable background Service restriction

The Android 9.0

  • Use Wi-Fi RTT for indoor positioning
  • Bangs API support
  • Multi-camera support and camera updates
  • The hide API is not allowed to be called
  • A network request HTTP that restricts plaintext traffic

Android 10

  • Diablo mode
  • Privacy enhancement (background access positioning)
  • Restrict program access to the clipboard
  • Application of black box
  • Permission subdivision must be compatible
  • Background location independent permission compatible
  • The unique identifier of the device must be compatible
  • The background Activity must be compatible
  • Non-sdk interfaces must be compatible

2.2 Principles of hot repair

The principle of

  1. When Android loads a class, it uses the parent delegate mechanism to load a class. The parent class loads the class first, and the child class loads the class if it can’t find it.
  2. A look at the ClassLoader source code shows that the findClass method is implemented by each subclass, such as BootClassLoader or BaseDexClassLoader. PathClassLoader is inherited from BaseDexClassLoader, and its findClass is also implemented in BaseDexClassLoader.
  3. FindClass in The BaseDexClassLoader uses another object, DexPathList, to find the corresponding class, which is unique to Android. In the DexPathList object, there is a property called dexElements. DexElements is used to store the loaded dex array. The class is found in this dexElements array.
  4. DexElements holds the Element object. FindClass is ultimately implemented by Element, and Element is implemented by an Element attribute, DexFile. I looked at it and it was implemented in Native.
  5. Go back to the DexPathList object in step 3 above and look for classes in the dexElements array, from the front of the array to the back.
  6. So when we make the bug-fixed class into a dex, and then use reflection and other techniques to put dexElements at the front of the system, when we find the class through the PathClassLoader, we can find the bug-fixed class first, and then stop looking for it later Yu achieved thermal repair. This way the buggy class won’t be used. Should be an old saying, near water tower first get the month.
  7. The reflection in point 6 goes as follows: get the PathClassLoader, then get the Reflection into the DexPathList object in the parent class, and then get the reflection into the dexElements array in the DexPathList object. The patch (dex) is then converted into an Element object and inserted in front of the dexElements array (copied, merged, and put back by reflection).

In one sentence

Put the repaired classes at the top of dexElements so that they are loaded first when the class is loaded.

2.3 the MVC and MVP, MVVM

The first thing you need to know is why do you design a technical framework? It must be for low coupling and high development efficiency. So don’t design for design’s sake.

MVC

In Android, the View and Controller are generally acted as an Activity. When the logic is very large and the operation is very complex, the Activity code is very large and difficult to maintain.

  • Model: Model layer, business logic + data store, etc
  • View: User interface, generally XML +Activity
  • Controller: The control layer, usually an Activity

MVP

From my personal point of view, it’s mostly used this way now, which is neither complicated nor decoupled.

  • Model: Model layer, business logic + data storage + network request
  • View: The View layer,View drawing and user interaction, generally activities
  • Presenter: A presentation layer that connects V layer and M layer to complete their interaction

MVVM

In order to separate the M and V layers more, so MVVM.

  • Model: Model layer, business logic + data storage + network request
  • View: The View layer,View drawing and user interaction, generally activities
  • ViewModel: A combination of the Presenter and View data model. Two-way binding, changes to the View are reflected in the ViewModel, changes to the data are reflected in the View.

2.4 Benefits of componentization

  1. Any modification requires compiling the entire project, which is inefficient.
  2. Decoupled, conducive to multi-team collaborative development
  3. Function of reuse

2.5 APP Startup process

I wrote an article earlier about the Android_App startup process (including the Activity startup process).

  1. Launcher startActivity
  2. AMS startActivity
  3. The Zygote fork process
  4. Activity main()
  5. The ActivityThread process loops
  6. Start the Activity to start the lifecycle callback…

2.6 Activity Startup process

Look at the 2.5 recommended article there

  1. Activity startActivityForResult
  2. Instrumentation execStartActivity
  3. AMS startActivity
  4. ApplicationThread scheduleLaunchActivity
  5. ActivityThread. H handleMessage – > performLaunchActivity
  6. Activity attach
  7. Instrumentation callActivityOnCreate

2.7 APP volume optimization

Optimize this area. Big S wrote an article that was particularly useful,The original text is here

  • You can use the Lint tool to detect the absence of useful files. In addition, you can enable resource compression to automatically delete unnecessary resources.
  • Use as many drawable objects as possible, some images do not require static image resources, and the framework can draw images dynamically at run time. Try to write Drawable yourself, if you don’t need to use THE UI to cut the graph, it takes up less space.
  • Reuse resources. For example, on a triangle button, click the front triangle up means to fold up, and click the back triangle down means to expand. Under normal circumstances, we will use two pictures to switch, but in fact, we can completely change by rotation.
  • For example, if the coloring of the same image is different, we can use the Android :tint and tintMode properties, and the lower version can use ColorFilter
  • Compress PNG and JPEG files. PNG file size can be reduced without loss of image quality.
  • Using WebP file formats, you can use WebP file formats instead of PNG or JPEG files. You can use AS to convert existing BMP,JPG,PNG, or static GIF images to WebP format.
  • Use vector graphics. SVG
  • Code obfuscation – Use the proGuard code obfuscation tool, which includes compression, optimization, obfuscation, and more. This is all too familiar.
  • Plug-in: Put function modules on the server and download them as required to reduce the size of the installation package.

2.8 App startup optimization

  • Use the Window shown in advance to quickly show a program and give users quick feedback on the experience. A palliative is a palliative.
  • Avoid Heavy app initialization at startup. Some SDK initialization is asynchronously loaded (such as Umeng, Bugly and other services can be asynchronously loaded if it is not necessary), such as map and push, etc. If it is not needed at the first time, it can be delayed in the main thread (such as splash screen page), and then initialized after the program has been started. For the network, the image request framework must be initialized in the main thread.
  • Avoid I/O operations, deserialization, network operations, nesting layout and other time-consuming operations during startup

Read more:

  • Interviewer: Toutiao got off to a fast start. What do you think might have been optimized?
  • It’s been 9102 years, but what are some new ways to optimize the cold start of Android?

2.9 App layout optimization

  • If the parent control has a color that it needs, then you do not need to add a background color to the child control
  • If the child control has a background color and can completely override the parent control, the parent control does not have to set the background color
  • Minimize unnecessary nesting
  • You can use LinearLayout and FrameLayout, but don’t use a RelativeLayout because it’s relatively complex and time-consuming to map.
  • Include and merge are used together to increase reuse and reduce hierarchy
  • ViewStub loads on demand and is more portable
  • ConstraintLayout is selected for complex interfaces to reduce levels

2.10 App Memory Optimization

  • Frequently use string concatenation using StringBuilder or StringBuffer
  • Replace HashMap with ArrayMap and SparseArray
  • Avoiding memory leaks
    • Collection class leakage (collection keeps referring to added element objects)
    • Memory leaks from singletons/static variables (long lifetime holding short lifetime references)
    • Anonymous inner classes/non-static inner classes
    • Memory leak caused by resource not being closed
  • Memory leak detection of several tools: LeakCanary, TraceView, Systrace, Android Lint, the Memory Monitor + mat

2.11 What Are memory Leaks

  • Collection class leakage (collection keeps referring to added element objects)
  • Memory leaks from singletons/static variables (long lifetime holding short lifetime references)
  • Anonymous inner classes/non-static inner classes
  • Memory leak caused by resource not being closed
    • Network, file and other streams forget to close
    • Forget unregisterReceiver() on exit when manually registering for broadcasts
    • Forget stopSelf() after Service execution completes
    • Observer mode frameworks such as EventBus forget to manually unregister

2.12 APP thread optimization

The Thread pool avoids the existence of a large number of threads and reuses threads within the Thread pool, thus avoiding the performance overhead brought by the creation and destruction of threads. At the same time, it can effectively control the maximum number of concurrent threads in the Thread pool and avoid the blocking line phenomenon caused by a large number of threads preempting system resources. Chapter 11 of Exploring the Art of Android Development is recommended.

classification

  • FixedThreadPool A fixed number of thread pools
  • The CachedThreadPool has a variable number of non-core threads, and the idle threads have a timeout mechanism, which is suitable for performing a large number of tasks that require less time
  • ScheduledThreadPool The number of core threads is fixed, and there is no limit on non-core threads. It is used to perform scheduled tasks and repetitive tasks with a fixed period.
  • SingleThreadPool has only one core thread to ensure that all tasks are executed in the same thread order, unifying external tasks into a single thread so that there is no need to deal with thread synchronization between these tasks. advantages
  • Reduces the time spent creating and destroying threads and the cost of system resources
  • Not using a thread pool can cause the system to create so many threads that it can run out of system memory and “overswitch” points
  1. If the number of threads in the thread pool does not reach the number of core threads, a core thread is directly started to perform the task
  2. If the number of threads in the thread pool has reached or exceeded the number of core threads, any are inserted into the task queue for execution
  3. If the task in 2 cannot be inserted into the task queue, since the task queue is full, a non-core thread will be started to execute the task if the number of threads does not reach the maximum specified by the thread pool
  4. If the number of threads in 3 has reached the maximum number of threads in the pool, the task will be rejected and ThreadPoolExecutor will call the rejectedExecution() method of RejectedExecutionHandler to notify the caller

2.13 How does Android skin change work

Resetting Factory2 for LayoutInflater to intercept the creation of views and then making its own controls to skin them as much as it wants.

The specific principle can be referred to an article I wrote before Android-skin-support skin replacement principle comprehensive analysis

2.14 Fresco principle, Glide principle, the difference between the two, which is more efficient storage

This part is not understood temporarily, join todo

2.15 DialogFragment black border

www.jianshu.com/p/c8044b2c2…

2.16 Handler mechanism: The Android message mechanism

I’ve written before about everything you need to know about the Android_Handler mechanism. This section explains why loop does not block the main thread.

The key to the Handler mechanism is an understanding of ThreadLocal, the thread private data. Use ThreadLocal to store Looper inside the thread. Perfect!

2.17 Android Architecture

Application layer, application framework layer, system runtime layer, hardware abstraction layer and Linux kernel layer

2.18 What are the Common Layouts

  • FrameLayout LinearLayout, RelativeLayout, ConstraintLayout CoordinatorLayout, etc

2.19 There are several ways to store Android data

  • SharedPreferences: little things that are eventually stored as key-values in XML files.
  • file
  • The database
  • ContentProvider
  • network

2.20 the View, the SurfaceView

  • View is the base class for all controls in Android
  • The View works for active updates, while the SurfaceView works for passive updates, such as frequent interface refreshes.
  • The View refreshes the page in the main thread, while the SurfaceView opens a child thread to refresh the page.
  • The View does not implement double buffering when drawing; the SurfaceView implements double buffering in the underlying mechanism.

2.21 JNI Invocation Process

I have also written a simple demo before,JNI Java and C mutual calls and basic operations

Next door Lao Li tou has a great series of articles, the address is here

2.22 What Can I Do if Components Reference Each other

  • Call external methods provided by other components: I’ve seen a way to define a ComponentBase using the “interface + implementation” approach In the middle layer, there are interfaces that each component provides for method calls. Each component implements these interfaces when it initializes, and then pulls them from ComponentBase when other components need them.
  • Interface jump :ARouter

2.23 To customize the View pie chart, click the event and draw the text

You can follow Hencoder’s article to learn this systematically.

2.24 Android Digital Signature

Verify user identity and data integrity

2.25 Fragment: What is the difference between 2.25 Fragment and Activity

  • When an Activity needs to be modularized
  • Adaptation on different devices, such as platforms and mobile phones
  • Compared with Fragment, Activity is very bulky. Generally, Fragment is suitable for small interface modules. Or a TAB on the front page or something.

2.26 RxJava principle

Observer mode, chain

Friendly rxJava2.x source code parsing trilogy

RxJava for Android developers

2.27 EventBus principle

Not very well understood, rarely used, seems to be a framework based on the observer pattern.

EventBus principle analysis

2.28 Principle of View rendering

It mainly analyzes the process of measure,layout and draw. I have written a relatively complete article before, as follows.

Dead knock Android_View works everything you need to know

2.29 Retrofit and OkHttp principles, interceptors

  • For Retrofit, the source code is very, very good. Mainly through dynamic proxy + get method above annotation etc., and then assemble the request network parameters, and finally use OkHttp to request the network
  • OkHttp’s interceptor chain is cleverly designed in the classic chain of responsibility pattern. Finally, the last chain handles the network request and gets the result.

I just wrote an article about it before, as follows:

Dead knock Android_Retrofit principle analysis

Dead knock Android_OkHttp3 principle exploration

2.30 Click event delivery mechanism. What kinds of events are there

Activity–> Window–>DecorView –> View tree from top to bottom. MotionEvent is a click event in Android

Major Event types

  • ACTION_DOWN Event that the mobile phone touches the screen for the first time
  • ACTION_MOVE is triggered when the phone is swiped on the screen and will be called back multiple times
  • ACTION_UP is triggered when the finger leaves the screen

Several approaches to focus on

  • dispatchTouchEvent(event);
  • onInterceptTouchEvent(event);
  • onTouchEvent(event);

The above three methods can be represented by the following pseudocode:

public boolean dispatchTouchEvent(MotionEvent ev) {
    boolean consume = false;// Whether the event is consumed
    if (onInterceptTouchEvent(ev)) {// Call onInterceptTouchEvent to check whether the event is intercepted
        consume = onTouchEvent(ev);// If intercepted, call its own onTouchEvent method
    } else {
        consume = child.dispatchTouchEvent(ev);// Does not intercept the dispatchTouchEvent method that calls the child View
    }
    return consume;// The return value indicates whether the event is consumed, true terminates the event, and false calls the parent View's onTouchEvent method
}
Copy the code

For more details, see my previous article on the Android View event distribution mechanism

2.31 How do I generate anR? How long does Service trigger anR (20 seconds)? How do I solve anR? How to solve that inexplicable ANR?

/data/anr/ testamp.txt/data.txt/data.txt/data.txt/data.txt/data.txt/data.txt/data.txt/data.txt/data.txt You can refer to my article to get anR logs,Android does not root to view anR exceptions

2.32 Dialog and Activity are the same Window?

Not the same.

  • The Attach method for the Activity, which instantiates a PhoneWindow instance for the Activity
  • The Dialog constructor also instantiates a PhoneWindow instance

2.33 the Window, the Activity, the relationship between the Dectorview

The Activity instantiates a Window that has a DecorView(root layout) inside it.

Take a look at this article, made by ruthless programmers. Explore the Android Window mechanism

2.34 What is the difference between ConstraintLayout and RelativeLayout in rendering?

todo

2.35 Where are the onClick events and onTouchListener callbacks?

If a View needs to handle events and it sets OnTouchListener, the onTouch method of OnTouchListener will be called back. If onTouch returns false, onTouchEvent will be called, and vice versa. In the onTouchEvent method, the onClick method of OnClickListener is called when the event is action. UP, which shows that OnClickListener has a low priority.

2.36 How can Applications Survive?

This is really not how to understand, mainly is not recommended to keep alive, improve user experience. Especially android high version, Google is blocked very strict, do not recommend to live.

I saw an article in my uncle’s place for your reference

Effect statistics of Android Survival scheme in 2018

2.37 How is the LinearLayout measured? How is weight measured, if any?

I’m going to make a measurement, and then I’m going to have some space left, and then I’m going to measure the View that has weight, and I’m going to divide up the space that’s left.

2.38 Screen Adaptation

AndroidAutoLayout previously, according to the width and height of the control zoom, very classic, many projects may still use, but has stopped updating. Then there is the famous Today’s Headlines solution, which has been around for a while. The principle is to change density.

Screen width = design width * Density

Then there is the AndroidAutoSize library, which integrates toutiao solution and improves many problems. It is easy to use and perfect.

3. The other

3. Four Java references

  • Strong reference, default is, would rather OOM, not recycle
  • Weak reference, insufficient memory will be reclaimed
  • Soft references, which will be collected on GC
  • A virtual reference, which tracks the garbage collection process and receives a system notification when an object is collected by the collector.

3.1 What was the most difficult thing in the project? How is it solved?

Everyone’s situation is different, so think ahead about the most challenging aspects of a project you’ve worked on.

3.2 Git Basic Operations

I suggest you learn from Mr. Liao Xuefeng’s course.

3.3 Kotlin advantage

  1. Fully compatible with Java
  2. Air safety
  3. Support for lambda expressions
  4. Support extension functions
  5. Less code, faster development

The downside is that sometimes the code can be less readable.

3.4 What is a Kotlin coroutine?

A thread framework that provides a set of apis for manipulating threads.

3.5 Binary tree, breadth first traversal, depth first traversal

Recommend the cartoon algorithm of Xiao Grey

3.6 the TCP, HTTP, HTTPS, socket

3.7 Agile Development

3.8 Which design patterns do you often use and the application of common design patterns

3.9 What do you think about the salary after 3 years

3.10 Your strengths

3.11 Career Planning (What to do in 3 years and 5 years)

3.12 Differences between applications, processes, and threads