Android interview questions (compilation version) 1000+ interview questions with detailed answers, gold nine silver ten, finished reading

foreword

Easily master programmer interview skills, effort is literally between!

In today's technology industry, programming is a highly regarded and sought-after profession. Whether you're looking for your first programming job or looking to advance your status in the industry, interviews are a hurdle you have to go through. In the face of fierce competition, how to stand out in the interview has become a topic that every programmer pays attention to.

A programmer interview is not just a simple answer to questions, it is more like a stage for technical competition and ability demonstration. In the interview, in addition to demonstrating your technical knowledge and coding ability, you also need to demonstrate your logical thinking, problem-solving skills, and teamwork qualities. Therefore, it is particularly important to prepare before going to the interview .

Preparation before the interview

The advice I want to give you here is: those who are preparing for the interview must make a review plan according to their own situation! Moreover, you'd better take a self-test from time to time and ask yourself some common interview questions. In this way, check for leaks and fill in vacancies, and find your own problems. Then start with the high-frequency interview questions, because the probability of high-frequency interview questions being answered is far greater than other interview questions, so you can click into the interview questions and learn all the interview questions (interview points) involved in this interview question. Understand in detail.

common interview questions

1. In the Java exception mechanism, the difference between exception Exception and error Error

What is this question trying to investigate?

When you need to customize exceptions during development, should you choose to define Excption or Error? What does the written code trigger Excption or Error represent?

Knowledge points of inspection

Java exception mechanism

How should candidates answer

ThrowableThere is a throwable class in Java Throwablewith two important subclasses, one is Error and the other is Exception.

insert image description here

ErrorIt is an error that the program cannot handle, indicating a serious problem in the program. For example, the Java virtual machine runs wrong (Virtual MachineError), when the JVM no longer has the memory resources needed to continue the operation, OutOfMemoryError will appear, and so on. When these errors occur, the JVM will generally choose to terminate the thread. These errors cannot be checked, they are outside the control and processing capabilities of the program, and most of them are not allowed to occur when the program is running.

ExceptionIt is an exception that the program can handle. And Exception is divided into runtime exception (RuntimeException) and non-runtime exception.

  • Abnormal operation

    Runtime exceptions, also known as unchecked exceptions . The so-called unchecked means that Java will not tell us that there is an exception when compiling and checking, and it needs to be exposed at runtime, such as subscript out of bounds, null pointer exception, etc.

  • non-runtime exception

    Exceptions other than RuntimeException are collectively referred to as non- runtime exceptions , such as IOException and SQLException, which are exceptions that must be handled ( check exceptions ). If they are not handled (throw to the upper layer or try-catch), the program cannot be compiled.

Second, talk about the difference between ArrayList and LinkedList?

  1. ArrayList is an array-based data structure, and LinkedList is a linked-list-based data structure.
  2. ArrayList is suitable for query operations, and LinkedList is suitable for insertion and deletion operations.

3. Please briefly describe the working principle and usage of LinkedHashMap?

Looking at the source code of LinkedHashMap, it is found that it inherits HashMap to implement the Map interface. That is, LinkedMap has HashMap methods.

The main difference between LinkHashMap and HashMap is: LinkedHashMap is ordered, and hashmap is unordered. LinkedHashMap achieves order by maintaining a doubly linked list, and it is precisely because of maintaining this linked list that there is a greater memory overhead.

Supplementary ordered and unordered: What we mean by unordered is that the insertion order and the output order are inconsistent.
Add a linked list structure and a sequential structure: the linear structure is divided into a sequential structure and a linked list structure.

  • Sequential structure: It is a complete and ordered memory in memory. Therefore, when we query, we directly index the index to find the data to be queried. The speed is very fast, but the disadvantage is that insertion and deletion are slow. It's a bit like when a class is queuing up (a column), everyone knows where they are. The teacher only needs to say the third position, and the student immediately knows that the teacher is looking for him. At this time, a classmate needs to be inserted into the second position, so the position of each classmate starting from the second position before and after must be +1. So relatively slow.
  • Linked list structure: record the previous node and the next next node of the node through the node head (that is, the traditional double linked list, the single linked list only records the next node, and the circular linked list is the next node of the last node point to the first node). It is precisely because of this relationship that the linked list structure does not require a complete memory, and insertion and deletion are relatively fast, but queries are relatively slow. But because of the need to maintain nodes, the memory overhead is relatively large. It is a bit similar to when a class is queuing up. Although everyone does not know their position, they know who is in front of them and who is behind them. When you want to insert a classmate b to the front of c, as long as classmate c remembers that he was a before, now change to bb and remember that he is a in front and c in the back. So I want to insert very quickly. Delete is similar. But when the teacher inquires by location, he must start counting from the first one until he finds the number the teacher is looking for. So the query is slow.

4. How to achieve synchronization in multithreading?

Synchronous and asynchronous multithreading are not the same thing. Several situations,

  1. It is what everyone calls synchronized, which can guarantee atomicity, and ensure that only one thread can hold the lock when multiple threads operate the same method, and operate the method,
  2. It is to manually call the read-write lock,
  3. Manually operate the wait and notify of the thread
  4. I remember that volatile is not atomic. It can guarantee memory visibility and ensure that the data of each thread is up-to-date in the case of multi-threading.

Five, talk about your understanding of Activity.runOnUiThread?

Generally, it is used to bind a runnable to the main thread. In the source code of runOnUiThread, it will judge whether the current runnable is the main thread. If it is run directly, if not, post the runnable into the looper through a default empty constructor handler, and create The constructor handler will bind a looper object of the main thread by default

6. Can the child thread update the UI? Why?

The child thread cannot directly update the UI.
Note this sentence, it cannot be updated directly, it is not impossible to update (updatable in extreme cases), the drawing process must be kept in sync (otherwise the page is not smooth), and our main thread is responsible for drawing the UI, extreme The situation is that the sub-threads can update the ui in the life cycle before (including) the onResume of the Activity, that is, onCreate, onStart and onResume, and the drawing of the main thread has not started yet.

Seven, talk about the Handler mechanism and principle?

First, we create a Handler instance object in the UI thread. Whether it is an anonymous inner class or a Handler instance object generated by a custom class, we need to rewrite the handleMessage method. In the handleMessage method, we can write the acceptance message through the parameter msg After the logical processing of the UIi thread, we create a sub-thread. When the UI needs to be updated in the sub-thread, a new Message object is created and the data of the message is recorded inside the message object Message, such as arg1, arg2, obj, etc. Then call the sendMessge method through the previous Handler instance object to send the Message instance object, and then the message will be stored in the MessageQueue to be processed. The dispatchMessage method is called back to pass the message to the handleMessage method of the Handler. Finally, the aforementioned message will be taken out from the MessageQueue by the Looper and passed to the handleMessage method.

8. Briefly describe the overall principle of the Handler mechanism

  1. Looper prepares and starts the round robin : Looper#prepare() initializes the thread-specific Looper and MessageQueue Looper#loop() starts an infinite loop to read the next Message in the MessageQueue that meets the execution time. If there is no Message yet, call pollOnce( on the Native
    side ) enters infinite waiting and if there is a Message, but the execution time when has not been satisfied, the
    remaining time parameter is passed in when pollOnce() is called to enter limited waiting
  2. Message sending, enqueue and dequeue : If the Native side is waiting infinitely: After any thread sends a Message or Runnable to the Handler, the Message will be inserted into the appropriate MessageQueue corresponding to the Looper instance held by the Handler according to the order of when conditions Location. MessageQueue will call wake() on the Native side to wake up the infinitely waiting thread after finding a suitable Message to insert. This will prompt the reading of MessageQueue to continue into the next cycle. At this moment, the Message that already meets the conditions in the Queue will be dequeued and returned to the Looper Native side. If it is in a limited wait: epoll_wait will return after waiting for a specified period of time. The thread continues to read the MessageQueue. At this moment, because the duration condition will be met, it will be dequeued. Looper processes the implementation of the Message:
  3. After the Looper gets the Message, it calls back the callback property of the Message, which is Runnable , or executes the callback of the Handler according to the target property, namely the Handler. If the mCallback property exists, call back Handler$Callback; otherwise, call back handleMessage()

The above interview questions are based on my sharing of spring and autumn recruiting experience of major factories, summarizing thousands of real interview questions , including 32 modules , which are: "Java basics, collections, multithreading, virtual machines, reflection, Generics, concurrent programming, four major components of Android, asynchronous tasks and message mechanisms, UI drawing, performance tuning, SDN, third-party frameworks, design patterns, Kotlin, computer networks, system startup processes, Binder, Handler, AMS, Dart, Flutter, algorithm and data structure, NDK, H.264, H.265. Audio codec, FFmpeg, OpenMax, OpenCV, OpenGL ES", as shown in the figure below:
insert image description here

However, due to the limited space of the article, the complete interview questions and answer analysis cannot be displayed. Friends who need complete interview questions can scan the QR code below to get it! ! !

Guess you like

Origin blog.csdn.net/datian1234/article/details/132214396