Self-study Android development for 5 years, the interview byte is beating cool? Come take a look at my interview experience

The basics of Java and Android

  1. Jvm virtual machine
  2. Will messageQueue block the ui thread
  3. Object lock and class lock
  4. Zigzag print tree
  5. There are other things that I ca n’t remember, mainly because I was too impressed with the two sides.

Flutter and Dart

  1. dart is passed by value or by reference
  2. The relationship between Widget and element and RenderObject
  3. the root node of the widget
  4. The relationship between mixin extends implement (other than extends, I haven't used it ...)
  5. jvm memory model (feeling that this is the interviewer who pity me, seeing that I do n’t ask anything =. =)
  6. Future and microtask execution order
  7. How to use in dart (basically never used ...)
  8. await for (never used ...)

To be honest, the first, third, and sixth things I prepared should be answered, but I haven't touched Flutter in more than a month, and I forgot it. . . Write down the two-sided answer later, hoping to help later generations. In addition, it is very important to maintain GitHub and blogs. The demo like me is written by hand, and the people who delete it are directly GG. .

1. Whether dart is passed by value or by reference first, dart is by reference. First look at the code

main(){
  Test a = new Test(5);
  print("a的初始值为:${a.value}");
  setValue(a);
  print("修改后a的值为: ${a.value}");
}

class Test{
  int value = 1;
  Test(int newValue){
    this.value = newValue;
  }
}

setValue(Test s){
  print("修改value为100");
  s.value = 100;
}

The output is:

a的初始值为:5
修改value为100
修改后a的值为:100

It can be seen from here that the reference is passed. If only an object is copied, the value of a in the main function will not change.

Some people may refute me with the following code:

main(){
  int s = 6;
  setValue(s);
  print(s); //输出6,而不是7
}

class Test{
  int value = 1;
  Test(int newValue){
    this.value = newValue;
  }
}

setValue(int s){
  s += 1;
}

You see, the output is not 6, everything in dart is an object. If it is passed by reference, why is it 6?

The answer is this, in the setValue () method, the parameter s is actually not an object with the s that we initialized int s = 6 but they are referring to the same memory area, and then call s + = in setValue () At 1, the object in this memory area performs a +1 operation, and then a new object is generated in the heap (analog java), and s points to this object. So the s parameter just copies the memory address of s in the main function, as in java:

public class Test {
    public static void main(String[] args) {
        Test a = new Test();
        Test b = a;    
        b = new Test();
    }
}

We only need to remember that the parameter is to pass the memory address. If the object at this memory address is modified, the value of the variable that references the memory address in other locations will also be modified. Don't forget that everything in dart is an object.

To secretly say, I think the interviewer is not good in this area. This kind of detail problem, if it is not a bug, and there is no time to pay attention to this when the business is busy, the interviewer can show these two situations, then Ask the interviewer why. . Then I can answer. . Cry haw. .

2. The relationship between Widget and element and RenderObject

First of all, I will elaborate on the situation at that time. The interviewer asked me if there is a one-to-many relationship between Widget and Element. If a widget is added, what is the relationship?

There is still no good answer for this part. Now it is just a guess. If a widget is added, the Element tree will traverse all the subsequent Elements to see if the type has changed, and then rebuild the RenderObject.

There should be a one-to-one relationship between Element and Widget, because the context of each Widget is unique. Write it up after you think about it.

3. The root node of the widget tree

Still not able to understand the meaning of the interviewer. . If you can understand, please comment and let me know. Now that I understand it, the interviewer should refer to the widget in the runApp () method. I wanted to say that at the time, but I forgot what the method name was. . .

4. The relationship between mixin extends implement

In this part, you can refer to the article of the Nuggets' little German, the high yield seems like that. . Flutter Dart mixins explore the Flutter Dart syntax (1): usage and difference of extends, implements, with

6. The execution order of Future and microtask also refer to Xiaode 's article in-depth understanding of Flutter's isolate (1) ---- event loop (event loop) and code running sequence in-depth understanding of Flutter's isolate (2)-create your own isolate in-depth understanding Flutter's isolate (3) — Flutter's thread model (thread model) in-depth understanding of Flutter's isolate (4) — using Compute to write isolates

7. What is the cascade symbol in dart ... allows you to operate the same object continuously, not only can you continuously call the function, but also can continuously access the method, so you can avoid creating temporary variables and write smoother code, Streaming programming is more in line with modern programming habits and programming styles:

main(){
  Tree tree = new Tree(1);
  tree..test1 = 1..test2 =5;
  print(tree.test1);
  print(tree.test2);
}

class Tree{
  int value;
  int test1 = 2;
  int test2 = 3;
  Tree(int a){
    this.value = a;
  }
}

8. await for use a first official document

await-forAs every Dart programmer knows, the for-in loop plays well with iterables. Similarly, the await-for loop is designed to play well with streams.Given a stream, one can loop over its values:Every time an element is added to the stream, the loop body is run. After each iteration, the function enclosing the loop suspends until the next element is available or the stream is done. Just like await expressions, await-for loops can only appear inside asynchronous functions.

It probably means that await for is to continuously obtain the data in the stream and then perform the operations in the loop body.

Stream<String> stream = new Stream<String>.fromIterable(['不开心', '面试', '没', '过']);
main() async{
  print('上午被开水烫了脚');
  await for(String s in stream){
    print(s);
  }
  print('晚上还没吃饭');
}

The output is

上午被开水烫了脚
不开心
面试
没
过
晚上还没吃饭

Await for and listen are very similar in function, both are to get the data in the stream and then output, but as await in await for shows, if the stream is not passed, it will always block at this position. The above is the last output without eating. Here is an example of listen, you can understand at a glance.

Stream<String> stream = new Stream<String>.fromIterable(['不开心', '面试', '没', '过']);
main(){
  print('上午被开水烫了脚');
  stream.listen((s) { print(s); });
  print('晚上还没吃饭');
}

The output is

上午被开水烫了脚
晚上还没吃饭
不开心
面试
没
过

Therefore, await for is generally used until when the stream is completed, and must be used after waiting for the transfer to complete, otherwise it will block all the time, causing a problem similar to Android ANR.

to sum up

In fact, the interviewer is still very nice, the first time I saw a live boss. . The big guy's research on flutter and dart is really in-depth. It's far from comparable to people like me who can only adjust APIs.

The main reason is that I have n’t used flutter for a month and a half, and then I asked other bigwigs if they want to prepare Flutter. The bigwigs said no. Many things I watched before were forgotten.

Hey, I still have n’t prepared myself enough, or when I started to ask me, I just forgot to answer, and I should be able to pass it.

The article is not easy, if you like this article, or it is helpful to you, I hope everyone will like it and forward it. The article will be updated continuously.

Published 34 original articles · Like1 · Visits 756

Guess you like

Origin blog.csdn.net/Android725/article/details/105300518
Recommended