One side asks Java and Android basics
- The Jvm virtual machine
- MessageQueue will block the UI thread
- Object and class locks
- Zigzag print tree
- I can’t remember anything else, but I was so impressed by the second interview.
Second questions Flutter and Dart
- Dart is passed by value or by reference
- The relationship between widgets and Elements and RenderObjects
- The root node of the widget
- The relationship between mixin extends Implement (extends is not used much)
- JVM memory model (feel this is the interviewer pity me, see I don’t know what to ask =. =)
- Future and MicroTask execution order
- The dart in.. I have hardly ever used…
- I am await for it.
To be honest, I should be able to answer the first, third and sixth ones I prepared, but I haven’t touched the Flutter for more than a month and forgot all about them… I’ll write out the answer to the second interview in the hope that it can help the next person. In addition, GitHub and blog maintenance is very important, like me this demo write conveniently, conveniently delete people directly GG.
Dart is passed by reference. Dart is passed by reference. Let’s look at some code
main(){
Test a = new Test(5);
print("The initial value of a is:${a.value}");
setValue(a);
print("The value of a after modification is:${a.value}"); } class Test{ int value = 1; Test(int newValue){ this.value = newValue; }}setValue(Test s){
print("Change value to 100");
s.value = 100;
}
Copy the code
The output is:
The initial value of a is: 5 Changed value to 100 Changed value of A to 100Copy the code
If you copy an object, the value of ain main does not change.
Some might counter with the following code:
main(){
int s = 6;
setValue(s);
print(s); } class Test{int value = 1; Test(int newValue){ this.value = newValue; }}setValue(int s){
s += 1;
}
Copy the code
Everything is an object in Dart. If it’s passed by reference, why is it 6?
The answer is that in setValue(), the argument s is not actually the same object as the one we initialized with int s = 6, except that they now refer to the same memory area, and then when we call s += 1 in setValue(), the object in that memory area performs the +1 operation, A new object is then created in the heap (Java analogy), and S points to this object. So the s argument simply copies the memory address of s from main, as in Java:
public class Test { public static void main(String[] args) { Test a = new Test(); Test b = a; b = new Test(); }}Copy the code
Just remember that the argument is passing the memory address, and if you change the object at that memory address, the value of any variable that references that memory address will change as well. It’s important to remember that everything is an object in DART.
Secretly,, I think the interviewer is not good at the interview, such details, if it is not a bug, the business is busy when there is no time to pay attention to this, the interviewer can show these two situations, and then ask the interviewer what is the reason. Then I’ll be able to answer it. Cry and cry.
2. The relationship between widgets and Elements and RenderObjects
The interviewer asked me if there was a one-to-many relationship between the Widget and Element, and if there was a one-to-many relationship after adding a Widget.
This part is still not a good answer, but it’s just a guess. If you add a widget, the Element tree walks through all the following elements to see if the type changes, and then rebuilds the RenderObject if it does.
The relationship between Element and Widget should still be one-to-one because each Widget’s context is unique. Let’s write it up when we’re ready.
3. Root node of the Widget tree
Still didn’t understand the interviewer. If you can understand, please comment and let me know. Now you understand that the interviewer means the Widget in the runApp() method. I was going to say that, but I forgot the name of the method…
4. The relationship between mixin extends Implement
This part can refer to the nuggets’ Dwight Dekker article, productive like that. The grammar of Flutter Dart (1) extends, implements, and with
Also refer to Xiaodui’s article to learn more about the ISOLATE of Flutter (1) —- event loop and code running sequence learn more about the ISOLATE of Flutter (2) — Get to know more about Flutter threads. Get to know more about Flutter threads. Use Compute to write about Prolonged use
7. The dart.. What is the cascading symbol.. It allows you to operate on the same object continuously, not only calling functions continuously, but also accessing methods continuously. This avoids creating temporary variables, resulting in smoother code. Streaming programming is more consistent with modern programming habits and 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; }}Copy the code
例 句 : Here is the official document to await for use
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.
To await for is to continuously get data from the stream and then perform operations in the body of the loop.
Stream<String> stream = new Stream<String>.fromIterable(['Unhappy'.'interview'.'no'.'过']);
main() async{
print('Scalded my feet in the morning');
await for(String s in stream){
print(s);
}
print('I haven't had dinner yet');
}
Copy the code
The output is
In the morning, my feet were scalded by boiling waterCopy the code
‘await for’ and ‘listen’ are very similar in that they both get data from the stream and output it. But as’ await ‘in’ await for ‘shows, if the stream is not finished, it will remain blocked in this position.
Stream<String> stream = new Stream<String>.fromIterable(['Unhappy'.'interview'.'no'.'过']);
main() {print('Scalded my feet in the morning');
stream.listen((s) { print(s); });
print('I haven't had dinner yet');
}
Copy the code
The output is
I burned my feet with boiling water in the morning and didn't have dinner in the evening. I was unhappy and failed the interviewCopy the code
So await for is normally used until the stream is complete and must wait until the delivery is complete, otherwise it will block and cause problems similar to Android ANR.
conclusion
In fact, the interviewer is very nice, the first time to meet a live big man. The big guy’s research into Flutter and Dart is really deep, far beyond the capabilities of someone like me who can only tune API.
The main reason is that I haven’t used the flutter for a month and a half, and then I asked other leaders if they wanted to prepare the flutter, they said no, they had forgotten most of the things they had seen before.
Ah, or their own preparation is not sufficient, or the beginning of the big guy asked me when the direct answer forgot almost, should be able to pass it.
The article is not easy, if you like this article, or help you hope that you like to forward attention oh. The article will be updated continuously.