Interviewer: When I face Android programmers, I often encounter reciting questions. When I ask the principle, I will reveal my stuff

Don't talk nonsense, let's go directly to the topic and see what questions the interviewer has asked Android programmers recently.

One, Android10 new features and adaptation

New features

  1. Folding screen
  2. 5G network support
  3. Smart reply notification
  4. Dark mode
  5. Gesture navigation
  6. Floating settings panel
  7. Share improvements

privacy

  1. Front desk access
  2. Network scanning requires precise location permissions
  3. Prevent device tracking
  4. Protect user data in external storage
  5. Prevent unwanted interrupts

Safety

  1. Storage encryption
  2. Default TLS1.3
  3. Platform optimization
  4. Improved biometrics

Camera and media

  1. Photo dynamic depth
  2. Audio playback capture
  3. New audio and video codecs
  4. Primitive MIDI API
  5. Directional zoomable microphone
  6. Vulkan everywhere

Connection optimization

  1. Improved peer-to-peer and internet connection
  2. WiFi high performance mode

Android system basics

  1. ART optimization
  2. Neural Network API1.2
  3. Thermal API
  4. Public API compatibility

Faster update speed, fresher code~

2. What is the difference between get and post requests

  1. The data of the GET request will be appended to the URL (that is, the data is placed in the HTTP protocol header), the URL and the transmission data are separated by ?, and the parameters are connected by &, such as: login.action?name=zhagnsan&password=123456. POST places the submitted data in the body of an HTTP packet.

  2. The data submitted by GET method can only be 1024 bytes at most. In theory, there is no limit to POST and a larger amount of data can be transmitted. In fact, it is wrong and inaccurate to say this:

"The data submitted by GET can only be 1024  bytes at most  ", because GET submits data via URL, so the amount of data that GET can submit is directly related to the length of the URL. In fact, the URL does not have the problem of parameter upper limit, and the HTTP protocol specification does not limit the length of the URL. This limitation is a limitation of a specific browser and server. IE's limitation on URL length is 2083 bytes (2K+35). For other browsers, such as Netscape, FireFox, etc., there is no length limit in theory, and the limit depends on the support of the operating system.

  1. GET POST security than the  security  is high. Note: The security mentioned here is not the same concept as the "security" mentioned in GET above. The meaning of "security" above is just no data modification, and the meaning of security here is the real meaning of Security, such as: submit data through GET, the user name and password will appear in plain text on the URL, because (1) the login page may be Browser cache, (2) Other people can view the history of the browser, then others can get your account and password. In addition, using GET to submit data may also cause a Cross-site request forgery attack.

3. The difference between threads and processes? Why not just use processes?

process

A process is a running activity of a program with independent functions on a certain data set. It is an independent system for resource allocation and scheduling (if the thread mechanism is not supported, the system scheduling unit of the process. Otherwise, the thread is the system scheduling unit). unit.

Features

1. A process is an  execution process of a program  . If the program is executed two or more times, two or more processes are required.

2. A process is an abstraction of a running program. It represents the running CPU, also known as the process is an abstraction of the CPU.

3. System resources (such as memory and files) are allocated in units of processes.

4. The operating system allocates an independent address space for each process.

5. The operating system transfers control to the process through "scheduling".

Disadvantages of the process:

1. The cost and overhead of process switching are relatively high.
2. Multiple programs need to be executed in parallel in a process to achieve different functions.
3. Sometimes the performance of the process is relatively low. (The introduction of threads is to solve the drawbacks of the process).

Thread:

1. There is an identifier ID.
2. There are states and state transitions, so some state transition operations need to be provided.
3. The context environment needs to be saved when it is not running, so registers such as the program counter are needed.
4. Have its own stack and stack pointer.
5. Share the address space and other resources of the process.

to sum up

1. A process is a running activity of a program on a certain data set; a thread is an execution path in a process. (The process can create multiple threads).

2. In a system that supports the thread mechanism, the process is the unit of system resource allocation, and the thread is the unit of CPU scheduling.

3. Resources cannot be shared between processes, and threads share the address space and other resources of the process in which they are located. At the same time, the thread has its own stack, stack pointer, program counter and other registers.

4. The process has its own independent address space, but the thread does not. The thread must depend on the process to exist.

5. The cost of process switching is relatively large. The thread is relatively small. (As mentioned earlier, the introduction of threads is also due to overhead considerations).

Fourth, the life cycle of Java objects

1. Created

In the creation phase, the system completes the object creation process through the following steps;

① Allocate storage space for the object.

②Start constructing the object.

③Initialize static members from superclass to subclass.

④The member variables of the superclass are initialized in order, and the superclass construction method is called recursively.

⑤Subclass member variables are initialized in order, and the subclass construction method is called. Once the object is created and assigned to some variable assignment, the state of this object is switched to the application phase.

2. In Use

The object is held by at least one strong reference.

3. Invisible stage

When an object is in the invisible stage, it means that the program itself no longer holds any strong references to the object, although these references still exist. Simply put, the execution of the program has exceeded the scope of the object.

4. Unreachable

An object in the unreachable stage means that the object is no longer held by any strong references. Compared with the "invisible stage", the "invisible stage" means that the program no longer holds any strong references to the object. In this case, the object may still be loaded by some static variables under JVM and other systems. Or strong references such as threads or JNI hold, these special strong references are called "GC root". The existence of these GCroots will cause memory leaks of the object and cannot be recycled.

5. Collection phase (Collected)

When the garbage collector finds that the object is already in the "unreachable phase" and the garbage collector is ready to reallocate the object's memory space, the object enters the "collection phase". If the object has overridden the finalize() method, it will perform the terminal operation of the method.

Here is a special note: do not overload the finazlie() method!

There are two reasons:

① It will affect the JVM's object allocation and recovery speed. When the object is allocated, the JVM needs to register the object on the garbage collector so that the overloaded method can be executed during the collection; the execution of the method requires CPU time and After the method is executed, the collection operation will be executed again, that is, the garbage collector needs to perform GC on the object at least twice.

② May cause the object to "resurrect" again. In the finalize() method, if another strong reference holds the object again, it will cause the state of the object to change from the "collection phase" to the "application phase" again. This has destroyed the life cycle process of the Java object, and the "resurrected" object does not use subsequent code management.

6. Final stage

When the object is still in an unreachable state after executing the finalize() method, the object enters the final stage. At this stage, it is waiting for the garbage collector to reclaim the object space.

7. Object space reallocation phase

The garbage collector reclaims or redistributes the memory space occupied by the object, then the object completely disappears, which is called the "object space redistribution phase".

5. Why wait and notification are declared in Object class instead of Thread

A tricky Java question. If the Java programming language was not designed by you, how can you answer this question? Common sense and in-depth understanding of Java programming can help answer this tricky Java core interview question.

Why wait, notify and notifyAll are defined in the Object class instead of the Thread class

This is a well-known Java interview question. Anyone with 2 to 4 years of experience or senior Java developer interview may encounter it.

The good thing about this question is that it reflects the interviewer’s understanding of the waiting notification mechanism and whether he has a clear understanding of the subject. Just like the question of why multiple inheritance is not supported in Java or why String is final in Java, there may be multiple answers to this question.

Everyone can give some reasons why wait and notify methods are defined in the Object class. From my interview experience, wait and nofity are still the most confusing for most Java programmers, especially developers who are 2 to 3 years old. If they ask to use wait and notify, they will be very confused. Therefore, if you go to the Java interview, please make sure that you have a sufficient understanding of wait and notify mechanisms, and you can easily use wait to write code, and learn about notification mechanisms through producer-consumer issues or implementing blocking queues.

Why wait and notification need to be called from synchronized block or method, and the difference between wait, sleep and yield method in Java, if you haven't read it, you will find it interesting. Why wait, notify and notifyAll belong to the Object class? Why shouldn't they be in the Thread class? Here are some ideas that I think make sense:

  1. Wait and notify are not just ordinary methods or synchronization tools, but more importantly, they are the communication mechanism between two threads in Java   . For language designers, if this mechanism of communication cannot be achieved through Java keywords (such as synchronized), and at the same time to ensure that this mechanism is available for each object, then the Object class is the correct declaration position. Remember that synchronization and waiting for notification are two different areas. Don't treat them as the same or related. Synchronization is to provide mutual exclusion and ensure the thread safety of Java classes, while wait and notify are the communication mechanisms between two threads.

  2. Every object can be locked  , which is another reason to declare wait and notify in the Object class instead of the Thread class. (Everyone is equal)

  3. In order to enter the critical section of the code in Java, threads need to lock and wait for the lock. They do not know which threads hold the lock, but only know that the lock is held by a certain thread, and they should wait to acquire the lock, rather than know which thread In the synchronized block, and request them to release the lock.

  4. Java is based on Hoare's monitor idea. In Java, all objects have a monitor.

    The thread waits on the monitor. To execute the wait, we need 2 parameters:

  5. A thread

  6. A monitor (any object)

In Java design, the thread cannot be specified, it is always the thread that runs the current code. However, we can specify the monitor (this is what we call waiting). This is a good design, because if we can let any other thread wait on the monitor that we need, it will lead to "intrusion" and cause difficulties in designing concurrent programs. Remember, in Java, all operations that intrude in the execution of another thread are deprecated (for example, the stop method).

At last

Thank you for your patience to finish reading the long-winded article. In addition to the article, I have a lot of interview questions in private collection.

I also share here, my own collection of  Android learning PDF + architecture video + interview documents + source notes  , as well as advanced architecture technology advanced brain maps, Android development interview special materials, advanced advanced architecture materials to help everyone learn and advance , It also saves everyone’s time to search for information on the Internet to learn, and can also share with friends around to learn together

Needless to say, I believe everyone has a consensus: no matter what the industry, the most powerful person is definitely the person at the end of the pyramid. Therefore, if you want to be a great programmer, you must make yourself stand taller. Becoming a technical expert is not a matter of overnight. It requires time and technology accumulation.

Regarding this point, when I established the Android direction at that time, I had already begun to sort out my growth path, including how to systematically learn the technology, which was listed in great detail.

Finally, I will share a series of Android learning resources that took more than a year to organize: Android source code analysis, Android third-party library source code notes, Android advanced architects seven topic studies, BAT interview questions analysis package over the years, Android master study notes, etc. , These contents are free to share with everyone, friends who need the full version, click here to see all the contents .

Guess you like

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