[Android Junior Gluten] In this market that requires advanced development, how can junior developers get out of the interview?

Java basics

1. What is optimistic locking?

  • Optimistic lock : Assuming that every time you get the data, you think that others will not modify it, so it will not be locked. However, when updating, it will be judged whether others have updated the data during this period. Generally used for reading more and writing less Happening.
  • Pessimistic lock : Assuming that every time is the worst case, others will modify it every time they get the data, so every time they get the data, they will be locked, so that others who want to get the data will be blocked until it gets the lock. Used when writing and reading less.

2. volatile keyword

  1. Guarantee visibility, not atomicity
  2. Disable instruction reordering
  3. No cache, every time it is fetched from main memory

1.3 The principle of hashmap, what is the red-black tree?

  • 1.7 Array + linked list, when the linked list is too long, it will cause query efficiency degradation
  • 1.8 Array + linked list + red-black tree, when the length of the linked list is greater than 8 converted to a red-black tree
  • The default initial size of HashMap is 16, the initial size must be a power of 2, and the maximum size is 2 to the 30th power. The Entry class of the linked list node stored in the array is implemented in the Map.Entry interface, which implements the general operations on the node. The threshold of HashMap defaults to "capacity * 0.75f". When the number of storage nodes exceeds this value, the map will be expanded.
  • For containers with unsafe threads, use ConcurrentHashMap (efficient) or Collections.synchronizedMap().Collections.synchronizedMap() to solve concurrency problems. In fact, each method adds a synchronize, which is similar to HashTable.

Red black tree

  • Balanced binary search tree
  • Node is red or black
  • The root node is black
  • The nodes of each leaf are black empty nodes (NULL)
  • The two child nodes of each red node are black
  • All paths from any node to each of its leaves contain the same black node
  • Discoloration and rotation are involved when inserting

4.jvm memory allocation

Chapter 2 in the Java Virtual Machine Book

  • Program counter
  • Java virtual machine stack
  • Native method stack
  • Java heap
  • Method area
  • Runtime constant pool
  • Direct memory

1.5 String,StringBuffer,StringBuilder 区别

  • String, StringBuffer, StringBuilder ultimately store and manipulate char arrays. However, the char array in String is final, while StringBuffer and StringBuilder are not. That is to say, String is immutable, and new strings can only be Regenerate String. StringBuffer and StringBuilder only need to modify the underlying char array. Relatively speaking, the overhead is much smaller.
  • Most methods of String are to re-new a new String object to return, and frequent re-generation is easy to generate a lot of garbage
    ...

2. Android Basics

1. Major changes in Android versions (what are the major changes from Android 6.0 to 10.0), compatible and adaptable

Android 5.0

  • Material Design
  • ART virtual machine

Android 6.0

  • Application permission management
  • Official fingerprint support
  • Doze power management
  • Run-time permission mechanism -> Need to apply for permission dynamically

Android 7.0

  • Multi-window mode
  • Support Java 8 language platform
  • Need to use FileProvider to access photos
  • Install apk needs to be compatible

Android 8.0

  • Notification, Channel -> Adaptation
  • Picture in Picture
  • Autofill
  • Background restrictions
  • Adaptive desktop icon -> adaptation
  • Implicit broadcast restriction
  • Enable background service restrictions

Android 9.0

  • Use Wi-Fi RTT for indoor positioning
  • Liu Haiping API support
  • Multi-camera support and camera updates
  • Calling hide api is not allowed
  • Network request http that restricts plaintext traffic

Android 10

  • Dark mode
  • Enhanced privacy (can you access the location in the background)
  • Restrict program access to the clipboard
  • Application black box
  • Permission subdivision must be compatible
  • Separate permissions for background positioning must be compatible
  • The unique device identifier must be compatible
  • Open Activity in the background must be compatible
  • Non-SDK interface restrictions need to be compatible

2. Principle of hot repair

principle

  1. When loading a class, Android will use the parent delegation mechanism to load a class, first let the parent class load it, and if it can't find it, let the child class load a certain class.
  2. By looking at the ClassLoader source code, it is found that the findClass method is implemented by each subclass itself, such as BootClassLoader or BaseDexClassLoader. The PathClassLoader is inherited from BaseDexClassLoader, and its findClass is also implemented in BaseDexClassLoader.
  3. In the findClass of BaseDexClassLoader, another object DexPathList is used to find the corresponding class, which is a unique implementation in Android. There is an attribute dexElements in the DexPathList object. dexElements is used to store the loaded dex array. The search class is found from this dexElements array.
    .........

One sentence summary

Put the repaired class at the top of dexElements, so that when the class is loaded, it will be loaded first to achieve the purpose of repair.

3.MVC,MVP,MVVM

The first thing you need to know is why you need to design a technical framework? It must be for low coupling and improve development efficiency, right, so don't design for design.

MVC

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

  • Model: Model layer, business logic + data storage, etc.
  • View: User interface, usually xml+Activity
  • Controller: Control layer, usually Activity

MVP

From my personal point of view, now (20:02:49, October 29, 2019), most of them use this method, which is neither complicated nor decoupled.

  • Model: Model layer, business logic + data storage + network request
  • View: View layer, View drawing and user interaction, etc., generally Activity
  • Presenter: the presentation layer, connects the V layer and the M layer, and completes the interaction between them

MVVM

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

  • Model: Model layer, business logic + data storage + network request
  • View: View layer, View drawing and user interaction, etc., generally Activity
  • ViewModel: In fact, it is a combination of Presenter and View data models. Two-way binding, changes in View will be reflected in ViewModel, and changes in data will also be reflected in View.

4. Benefits of componentization

  1. Any modification needs to compile the entire project, which is inefficient.
  2. Decoupling is conducive to multi-person team development
  3. Function reuse

5. App startup process

  1. Launcher startActivity
  2. AMS startActivity
  3. Zygote fork process
  4. Activity main()
  5. ActivityThread process loop loop
  6. Open Activity, start life cycle callback...

6.Activity startup process

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

7. App volume optimization

  • You can use the lint tool to detect useless files and enable resource compression to automatically delete useless resources.
  • Use drawable objects as much as possible, some images do not require static image resources, and the framework can draw images dynamically at runtime. Try to write Drawable by yourself, if you can cut pictures without UI, it takes up little space.
  • Reuse resources. For example, a triangle button, click the front triangle to face upwards to represent the meaning of folding, and click the rear triangle to face downwards to represent expansion. Normally, we will use two images to switch, but we can actually change it in the form of rotation.
    ..........

8. App startup optimization

  • Use the window displayed in advance to quickly display a program, giving users a quick feedback experience, blinding the eyes, treating the symptoms but not the root cause.
  • Avoid doing intensive and heavy initialization at startup (Heavy app initialization).
  • Avoid time-consuming operations such as I/O operations, deserialization, network operations, layout nesting, etc. during startup

9. App layout optimization

  • If the parent control has a color, which is also the color you need, then you don't need to add a background color to the child control
  • If the child control has a background color and can completely cover the parent control, then the parent control does not need to set the background color
  • Minimize unnecessary nesting
  • If you can use LinearLayout and FrameLayout, don't use RelativeLayout, because RelativeLayout is relatively complicated and surveying is relatively time-consuming.
  • Use include and merge together to increase reuse and reduce levels
  • ViewStub is loaded on demand, which is more portable
  • Choose ConstraintLayout for complex interface, which can effectively reduce hierarchy

10. App memory optimization

  • Frequent use of string splicing with StringBuilder or StringBuffer
  • ArrayMap、SparseArray替换HashMap
  • Avoid memory leaks
    • Collection class leak (collection always refers to the added element object)
    • Memory leaks caused by singleton/static variables (long-lived references hold short-lived references)
    • Anonymous inner class/non-static inner class
    • Memory leak caused by unclosed resources
  • Several tools to detect memory leaks: LeakCanary, TraceView, Systrace, Android Lint, Memory Monitor+mat

11. What are the memory leaks

  • Collection class leak (collection always refers to the added element object)
  • Memory leaks caused by singleton/static variables (long-lived references hold short-lived references)
  • Anonymous inner class/non-static inner class
  • Memory leak caused by unclosed resources
    • Forgot to close the network, file and other streams
    • When manually registering for broadcast, forget to unregisterReceiver() when exiting
    • Forgot to stopSelf() after Service execution is complete
    • Observer mode frameworks such as EventBus forget to manually unregister

12. App thread optimization

The thread pool avoids the existence of a large number of Threads and reuses the threads in the thread pool, thus avoiding the performance overhead caused 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 a large number of threads from occupying system resources. The blocked line phenomenon occurs. It is recommended to read Chapter 11 of "Android Development Art Exploration".

classification

  • FixedThreadPool A fixed number of thread pools
  • CachedThreadPool only has non-core threads, the number is variable, and idle threads have a timeout mechanism, which is more suitable for performing a large number of tasks that consume less time
  • ScheduledThreadPool has a fixed number of core threads, and there is no limit on non-core threads. It is mainly used to perform scheduled tasks and repetitive tasks with a fixed medium period.
  • SingleThreadPool only one core thread to ensure that all tasks in order to perform the same thread, a thread to unify the outside world tasks, which makes the problem of synchronization between threads need to deal with these tasks.  Advantages
  • Reduce the time spent on creating and destroying threads and the overhead of system resources
  • Do not use the thread pool may cause the system to create a large number of threads resulting in system memory and consumed "over-switching"  Precautions

13.How to realize Android skinning, principle

Reset Factory2 of LayoutInflater to intercept the process of creating View, and then make your own control, and change the skin as you want.

14. Fresco principle, glide principle, the difference between the two, which is more memory-saving

I don't understand this temporarily, join todo

15.DialogFragment black border

www.jianshu.com/p/c8044b2c2…

16.Handler principle, Android message mechanism

The key to the Handler mechanism lies in the understanding of the principle of ThreadLocal, thread private data, using the ThreadLocal mechanism to store Looper inside the thread, perfect!

17.Android system architecture

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

18. What are the common layouts

  • FrameLayout,LinearLayout,RelativeLayout,ConstraintLayout,CoordinatorLayout等

19. There are several ways to store Android data

  • SharedPreferences: Small things are ultimately stored in the form of key-value in the xml file.
  • file
  • database
  • ContentProvider
  • The internet

20.View,SurfaceView

  • View is the base class of all controls in Android
  • View is suitable for active updates, while SurfaceView is suitable for passive updates, such as frequently refreshing the interface.
  • View refreshes the page in the main thread, while SurfaceView opens a sub-thread to refresh the page.
  • View does not implement a double buffering mechanism when drawing, and SurfaceView implements a double buffering mechanism in the underlying mechanism.

21.jni call process

The series of articles by Litou next door is very good, the address is here

22. How to resolve mutual references between components

  • Call the externally provided methods of other components: I have seen an idea before, using the "interface + implementation" method to define a ComponentBase middle layer, and then there is an Interface for each component to provide method calls to the outside, and each component is initializing When these interfaces are implemented, other components are taken from ComponentBase when they are needed.
  • Interface jump: ARouter

23. Customize the View pie chart, click events, and draw text

You can follow the hencoder teacher's article system to learn.

24.Android digital signature

Verify user identity and verify data integrity

25. Where is the fragment used and the difference with Activity

  • When Activity needs to be modular
  • Adaptation on different devices, such as platforms and mobile phones
  • Activity is very cumbersome compared to Fragment. Generally, it is more appropriate to use Fragment for small interface modules. Or tabs on the home page.

26. Principle of RxJava

Observer mode, chained

27. EventBus principle

I don't know the principle very well and I rarely use it. It seems to be a framework based on the observer pattern.

28. View drawing principle

Mainly analyze the process of measure, layout, and draw.

29.Retrofit and OkHttp principle, interceptor

  • In the case of Retrofit, the source code is very good. It is mainly through the dynamic proxy + get the annotations on the method, and then assemble the parameters of the request network, and finally use OkHttp to request the network
  • OkHttp's interceptor chain is very cleverly designed and is a typical responsibility chain model. Finally, the last chain processes the network request and gets the result.

30. Click event delivery mechanism, which types of events are divided into

The general process of event delivery  Activity--> Window-->DecorView --> View树从上往下:, whoever wants to intercept during the delivery process will intercept their own processing. MotionEvent is a click event in Android.

Main event type

  • ACTION_DOWN The first touch of the phone to the screen event
  • ACTION_MOVE is triggered when the mobile phone slides on the screen and will call back multiple times
  • ACTION_UP Triggered when the finger leaves the screen

31. How to generate anr, how long does Service trigger anr (20 seconds), and how to solve anr? How to solve the inexplicable anr?

I think anr does time-consuming operations in the main thread, such as io, reading and writing files, database operations, and so on. After anr occurs, there will usually be logs, which are in /data/anr/traces.txt.

2.32 Dialog and Activity are the same Window?

Not the same.

  • The attach method of Activity, here is an instance of PhoneWindow instantiated for Activity
  • A PhoneWindow instance is also instantiated in the construction method of Dialog

33. The relationship between Window, Activity, Dectorview

A Window is instantiated in Activity, and there is a DecorView (root layout) in Window.

34. What is the difference between ConstraintLayout and RelativeLayout in terms of drawing?

everything

35. Where are the onClick event and onTouchListener callbacks?

If a View needs to handle events and it sets OnTouchListener, then the onTouch method of OnTouchListener will be called back. If onTouch returns false, onTouchEvent will be called, otherwise not. In the onTouchEvent method, the event is Action. When UP, the onClick method of OnClickListener will be called back. It can be seen that the priority of OnClickListener is very low.

36. How to keep the application alive?

This is really not well understood. The main reason is that keep-alive is not recommended to improve the user experience, especially the Android version. Google is very strict and does not recommend keep-alive.

37. How is LinearLayout measured? If there is weight, how is it measured?

Take a measurement first, and there will be space left after the completion, and then measure the weight of the View to divide the remaining space.

38. Screen adaptation

Previously, there was Hongshen’s AndroidAutoLayout, which scaled controls according to the width and height. It was very classic. Many projects may still be used, but the update has stopped. Then there is the famous Toutiao plan, which is still a little bit time to come out. The principle is actually to change the density.

The width of the screen = design draft width * density

Then there is the AndroidAutoSize library. The integration of Toutiao's solution has also improved many problems. It is easy to use and perfect.

3. Other

1. Java four references

  • Strong reference, the default is, I would rather OOM than recycle
  • Weak reference, will be recycled if there is not enough memory
  • Soft references, will be recycled during GC
  • Phantom reference, its function is to track the garbage collection process, and receive a system notification when the object is collected by the collector.

2. What is the most difficult thing encountered in the project? How to solve it?

Everyone encounters different situations. Think about the most challenging aspect of the projects you have done in advance.

3. Git basic operation

4. Kotlin advantage

  1. Fully compatible with java
  2. Empty safety
  3. Support lambda expression
  4. Support extended functions
  5. Less code, faster development speed

The disadvantage is that sometimes the code readability may be reduced.

5.What is Kotlin coroutine?

It is a threading framework that provides a set of APIs for operating threads.

6. Binary tree, breadth first traversal, depth first traversal

Recommend Xiao Hui's comic algorithm

7.tcp,http,https,socket

8. Agile development

9. Which design patterns do you often use, and the use of common design patterns

What do you think about salary after 10.3 years

11. Your advantage

12. Career planning (what to do in 3 years, what to do in 5 years)

13. The difference between application, process, thread

Tips for entering a big factory

After several years of "frustration", I found that entering the big factory does have some tricks. For students with the same background as me, as long as you grasp the trick, entering the big factory is not a dream.

1) Be sure to prepare in advance, at least one month, and look at the online interview questions. For those high-frequency questions, learn with understanding, and memorize the ones that are really incomprehensible. Not all of them are memorized during the college entrance examination. of.

2) Large factories usually have many departments, and the number of hc and recruitment standards for each department are different. Even in the same department, if the hr is different, the standards will definitely be different. Repeated submission of resumes can increase our chances of getting interviews. The probability. In the same way, repeated interviews with different departments can also increase the probability of us entering large factories.

3) Large factories often deploy new businesses. New businesses need to start and enter the market quickly. There are usually many HCs, so the recruitment standard will be slightly lower. This time is an excellent opportunity. I entered a new business department.

Interview system review route

Sometimes, choice is more important than effort, and opportunity is more important than struggle. However, opportunities are only reserved for those who are prepared. Only when we are always prepared can we seize the opportunity when it comes.

Here to share with you my interview review route , friends in need can refer to:

1. Watch the video for systematic learning

The experience of Crud in the past few years has made me realize that I am really a fighter in the rookie. It is also because of Crud that my technology is relatively fragmented and not deep enough to be systematic, so it is necessary to study again. What I lack is system knowledge, poor structural framework and ideas, so learning through videos is better and more comprehensive. Regarding video learning, individuals can recommend to study at station B. There are many learning videos on station B. The only drawback is that they are free and easily outdated.

2. To systematically sort out knowledge and improve reserves

There are so many knowledge points in client development, and there are still so little things in the interview. Therefore, there are no other tricks for the interview, just to see how well you prepare for these knowledge points. So, when you go out for an interview, it is good to see which stage you have reached in your review.

System learning direction:

  • Essential skills for architects: in-depth Java generics + annotations in simple language + concurrent programming + data transmission and serialization + Java virtual machine principle + reflection and class loading + dynamic proxy + efficient IO

  • Android advanced UI and FrameWork source code: advanced UI promotion + Framework kernel analysis + Android component kernel + data persistence

  • 360° overall performance tuning: design ideas and code quality optimization + program performance optimization + development efficiency optimization

  • Interpretation of open source framework design ideas: hot repair design + plug-in framework interpretation + component framework design + image loading framework + network access framework design + RXJava responsive programming framework design + IOC architecture design + Android architecture component Jetpack

  • NDK module development: NDK basic knowledge system + underlying image processing + audio and video development

  • WeChat Mini Program: Mini Program Introduction + UI Development + API Operation + WeChat Docking

  • Hybrid development and Flutter: Html5 project combat + Flutter advanced

After the knowledge is sorted out, it is necessary to check and fill in the vacancies. Therefore, for these knowledge points, I have prepared a lot of e-books and notes on hand. These notes provide a perfect summary of each knowledge point.

3. Read the source code, read the actual combat notes, and learn the ideas of God

"Programming language is the way the programmer expresses, and the architecture is the programmer's perception of the world." Therefore, if programmers want to quickly understand and learn the architecture, reading the source code is essential. Reading the source code is to solve problems + understand things, and more importantly: see the ideas behind the source code; programmers say: read thousands of lines of source code, and practice thousands of ways.

4. On the eve of the interview, sprint questions

Within a week before the interview, you can start sprinting. Please keep in mind that when brushing the questions, the technology is the first priority, and the algorithm is basic, such as sorting, etc., and the intellectual questions are generally not asked unless they are school recruits.

Regarding the interview questions, I personally prepared a set of systematic interview questions to help you learn from one another:

The above content is free to share with everyone, friends who need the full version, click here to see all the content .

Guess you like

Origin blog.csdn.net/weixin_44339238/article/details/111933080