File size: 27,266 Bytes
2e5dac7 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 | 1
00:00:06,000 --> 00:00:06,000
Hello.
2
00:00:06,000 --> 00:00:11,000
Yes, students, today we are going to talk about implementations of the list interface, we are going
3
00:00:11,000 --> 00:00:17,000
to discuss such implementations as our list vector question right away, list and stack.
4
00:00:17,000 --> 00:00:23,000
You have a lot of things to learn in this lesson besides the learning of the specific classes.
5
00:00:23,000 --> 00:00:28,000
We are going to answer the question when you have to use each particular implementation of list interface.
6
00:00:28,000 --> 00:00:34,000
I'm going to share with you real life examples where we will use list implementations today during the
7
00:00:34,000 --> 00:00:39,000
lesson I'm going to show you is a tool that will allow you to investigate the interaction of classes
8
00:00:39,000 --> 00:00:40,000
in the clips.
9
00:00:40,000 --> 00:00:45,000
During the lesson, we are going to compare different implementations of the list interface so that
10
00:00:45,000 --> 00:00:50,000
you could understand what pros and cons of each implementations are in this lesson.
11
00:00:50,000 --> 00:00:56,000
We are going to compare on the array vector Copan right away and Stack also.
12
00:00:56,000 --> 00:01:01,000
We're going to learn what mocker interfaces are and what is random access interface.
13
00:01:01,000 --> 00:01:04,000
So as you can see, we have a huge agenda for today.
14
00:01:05,000 --> 00:01:07,000
Let's don't waste our time and start our lesson.
15
00:01:08,000 --> 00:01:09,000
Brunious lessons.
16
00:01:09,000 --> 00:01:14,000
You already learned what list is, but let's try to answer the question when we have to use list.
17
00:01:15,000 --> 00:01:20,000
In my opinion, list implementations can cover the requirements of the widest range of business cases.
18
00:01:21,000 --> 00:01:21,000
Why?
19
00:01:22,000 --> 00:01:23,000
Because of the next reasons.
20
00:01:24,000 --> 00:01:26,000
Support of data manipulation by Elements Index.
21
00:01:27,000 --> 00:01:33,000
You may want to retrieve product from specific index in your list of products, or you may want to put
22
00:01:33,000 --> 00:01:36,000
user in the list of users in the middle of the list by its index.
23
00:01:37,000 --> 00:01:42,000
Or probably you always want to add the new user since the beginning of the list, but not at the end.
24
00:01:42,000 --> 00:01:48,000
The possibility to use index to manage element positions gives you a lot of options for data manipulations
25
00:01:48,000 --> 00:01:50,000
that will help you in different business cases.
26
00:01:51,000 --> 00:01:55,000
And another reason list implementations may contain duplicates.
27
00:01:55,000 --> 00:02:01,000
Sometimes you just need to have container that will store all your products, for example, and you
28
00:02:01,000 --> 00:02:03,000
don't care about duplicate there.
29
00:02:03,000 --> 00:02:07,000
You just need to have a list of all products here.
30
00:02:08,000 --> 00:02:14,000
That's why, which is at least overset sometimes one more reason usability to create subleased.
31
00:02:14,000 --> 00:02:16,000
This feature is really attractive.
32
00:02:16,000 --> 00:02:18,000
One for some specific business cases.
33
00:02:18,000 --> 00:02:21,000
Let me share with you one example from the real life.
34
00:02:21,000 --> 00:02:25,000
We implemented mobile app for the betting tips in this app.
35
00:02:25,000 --> 00:02:27,000
We received data from the server.
36
00:02:27,000 --> 00:02:29,000
We store the data in the list.
37
00:02:30,000 --> 00:02:33,000
There was such the main type asport prediction data.
38
00:02:33,000 --> 00:02:39,000
eSport prediction was done for the specific sports event that may happen either today or yesterday or
39
00:02:39,000 --> 00:02:40,000
tomorrow.
40
00:02:40,000 --> 00:02:46,000
So developers created sub lists of the sport prediction for yesterday, today and tomorrow.
41
00:02:46,000 --> 00:02:50,000
We created three lists instead of one by splitting the original one.
42
00:02:51,000 --> 00:02:57,000
Why we could pass the one list to each widget to draw the list on the UI interface only for specific
43
00:02:57,000 --> 00:02:58,000
date.
44
00:02:58,000 --> 00:03:00,000
That's it, by the way.
45
00:03:00,000 --> 00:03:03,000
Here is the UI of the sports app, Anderson.
46
00:03:04,000 --> 00:03:07,000
You will be able to create similar apps, so don't worry.
47
00:03:07,000 --> 00:03:12,000
To implement such application, you have to know implementations of the list interface.
48
00:03:12,000 --> 00:03:15,000
Let's move further certain.
49
00:03:15,000 --> 00:03:19,000
And again, one more features a collection interface doesn't have.
50
00:03:19,000 --> 00:03:25,000
We may sort our button Tepes based on the level of probability that really improves interaction with
51
00:03:25,000 --> 00:03:26,000
the app.
52
00:03:26,000 --> 00:03:29,000
Moreover, I can offer user to source support.
53
00:03:29,000 --> 00:03:37,000
Prediction is a high probability score or by keep also rating or by anything else, wide range of use.
54
00:03:37,000 --> 00:03:43,000
And one more important reason to opt for these implementations, and this reason probably is the most
55
00:03:43,000 --> 00:03:46,000
important one that is not written in any book that you read.
56
00:03:46,000 --> 00:03:52,000
Engineers use list implementations and most of the times because they just don't use a set.
57
00:03:52,000 --> 00:03:59,000
Documentation's developers just need some container to store multiple elements in there and treat them
58
00:03:59,000 --> 00:04:02,000
as a single unit without any extra features.
59
00:04:02,000 --> 00:04:07,000
OK, now we want to know when and why we opt for liste implementations.
60
00:04:07,000 --> 00:04:13,000
Let's investigate list Iraqi on this slide you may use at least the interface is implemented by absoluteness
61
00:04:13,000 --> 00:04:14,000
class.
62
00:04:14,000 --> 00:04:15,000
Absolutely.
63
00:04:15,000 --> 00:04:20,000
Tintern extends APSA collection and is extended by Absol sequential sequentially.
64
00:04:21,000 --> 00:04:27,000
From this diagram you may see that our own list is extended directly from the absolute list, the same
65
00:04:27,000 --> 00:04:33,000
as vector and copy and write and released and linked list is extended from absolute sequential list
66
00:04:33,000 --> 00:04:37,000
stack class extends vector engineers.
67
00:04:37,000 --> 00:04:41,000
Doesn't like Stack for that because that is not the least by its essence.
68
00:04:42,000 --> 00:04:43,000
It is closer to the reverse.
69
00:04:43,000 --> 00:04:45,000
CU does a deck interface.
70
00:04:46,000 --> 00:04:52,000
We're going to run it later, but because of the backward compatibility creator subject didn't change
71
00:04:52,000 --> 00:04:53,000
anything here.
72
00:04:54,000 --> 00:04:54,000
Is it clear?
73
00:04:55,000 --> 00:05:02,000
Because Stack in its essence implement last in, first out principle, but it extends least interface,
74
00:05:02,000 --> 00:05:02,000
but not that.
75
00:05:03,000 --> 00:05:09,000
Even despite this, glass will not be used very often by a during the development, you might be asked
76
00:05:09,000 --> 00:05:11,000
about it during the interview.
77
00:05:11,000 --> 00:05:13,000
That's why I decided to mention it here.
78
00:05:14,000 --> 00:05:19,000
What is also worth to mention is the implementation of random access interface.
79
00:05:19,000 --> 00:05:25,000
Today during the demo, I'm going to show you what random access interface is and what mocker interfaces
80
00:05:25,000 --> 00:05:31,000
are to protect our lesson today as I just jump into the eclipse to investigate the source code that
81
00:05:31,000 --> 00:05:35,000
will help us to learn the topic better understand them.
82
00:05:35,000 --> 00:05:39,000
I'd like to share with you the trick that will also help you in the future during the development.
83
00:05:39,000 --> 00:05:45,000
Namely, I'd like to show you how you can easily find implementations of each interface and reviews
84
00:05:45,000 --> 00:05:48,000
a whole Iraqian, for example.
85
00:05:48,000 --> 00:05:50,000
Here is a list interface.
86
00:05:50,000 --> 00:05:54,000
I should put the cursor into the editor error and press efore button.
87
00:05:55,000 --> 00:05:57,000
Or you can also make mouse right.
88
00:05:57,000 --> 00:06:02,000
Click and select open type Iraqi here and we can see that the separate widget is open.
89
00:06:02,000 --> 00:06:07,000
Here, here I see items that extends or implements the interface.
90
00:06:07,000 --> 00:06:09,000
For example, here's our list.
91
00:06:10,000 --> 00:06:16,000
We can make a left mouse click to open it and here we may find our array list.
92
00:06:16,000 --> 00:06:20,000
As you can see, there are really a lot of classes over here will not run.
93
00:06:20,000 --> 00:06:25,000
Each of them instead will focus only on those that you will use during your work.
94
00:06:26,000 --> 00:06:32,000
Let's start from the most popular implementation of this interface that you will use in 98 percent of
95
00:06:32,000 --> 00:06:32,000
cases.
96
00:06:33,000 --> 00:06:34,000
That is just my assumption.
97
00:06:34,000 --> 00:06:42,000
But you will tell me that if I was right, here's a release class when people are released because it's
98
00:06:42,000 --> 00:06:47,000
really fast and most simple words released is array with dynamic size.
99
00:06:48,000 --> 00:06:50,000
But this is in very, very simple words.
100
00:06:51,000 --> 00:06:55,000
I only use regular arrays inside to store elements here.
101
00:06:55,000 --> 00:07:00,000
This is a variable is called element data in my store array of objects.
102
00:07:00,000 --> 00:07:07,000
That means that technically we can put everything in this array, but we can't because this field has
103
00:07:07,000 --> 00:07:09,000
packaged private modifier.
104
00:07:09,000 --> 00:07:15,000
OK, then you might be wondering if I only use this regular array to store elements, then it should
105
00:07:15,000 --> 00:07:18,000
have fixed size, is that correct?
106
00:07:18,000 --> 00:07:19,000
That is correct.
107
00:07:20,000 --> 00:07:23,000
Arrays in Java have fixed size, but not the array.
108
00:07:23,000 --> 00:07:27,000
Least let me show is a code that adds element to the collection.
109
00:07:28,000 --> 00:07:33,000
Here is an element method in today's modification count variable first.
110
00:07:33,000 --> 00:07:35,000
Don't pay attention to that right now.
111
00:07:35,000 --> 00:07:38,000
After that it calls another add method.
112
00:07:38,000 --> 00:07:41,000
I hold control key and press mouse left click.
113
00:07:41,000 --> 00:07:50,000
OK, here is a private matter and you see the first line we have if statement here we check if s equals
114
00:07:50,000 --> 00:07:55,000
to the length of the array, then we initialize our element data array with the new array.
115
00:07:56,000 --> 00:08:00,000
Before we go further, let's look what this s variable is.
116
00:08:00,000 --> 00:08:06,000
I hold all key and press our left key to move back to the previous position where I was.
117
00:08:06,000 --> 00:08:13,000
And we see that the argument in this method is a size variable size is also one of the fields in a release
118
00:08:13,000 --> 00:08:14,000
class.
119
00:08:14,000 --> 00:08:15,000
Now let's get back.
120
00:08:16,000 --> 00:08:22,000
I keep all key press and also press arrow right key to get back to the place in the source code where
121
00:08:22,000 --> 00:08:23,000
I was before.
122
00:08:23,000 --> 00:08:26,000
Now, you know, that s is a size.
123
00:08:27,000 --> 00:08:28,000
What does Groom method do?
124
00:08:29,000 --> 00:08:30,000
Let me answer that question.
125
00:08:31,000 --> 00:08:32,000
OK.
126
00:08:32,000 --> 00:08:37,000
This method calls another group method within argument and person size plus one there.
127
00:08:38,000 --> 00:08:39,000
And what do we have here?
128
00:08:40,000 --> 00:08:46,000
We see that in arguments that we passed to this method is used to define desired minimum capacity.
129
00:08:47,000 --> 00:08:54,000
You may see has that old capacity is equal to arrest lengths and in case old capacity is more than zero.
130
00:08:54,000 --> 00:08:57,000
We calculate new capacity, how it is calculated.
131
00:08:57,000 --> 00:09:02,000
I suggest you to investigate by itself by going deeper and method and location change.
132
00:09:03,000 --> 00:09:05,000
By the way, you might see here bitwise shift.
133
00:09:06,000 --> 00:09:09,000
And it is great that by this lesson you already know how it works.
134
00:09:10,000 --> 00:09:15,000
If you don't know, please review my lesson from the Java course about operators.
135
00:09:15,000 --> 00:09:23,000
And after that we use a race class to copy our current theory to the one with the new capacity and we
136
00:09:23,000 --> 00:09:24,000
return the reference to this array.
137
00:09:25,000 --> 00:09:31,000
So now you can understand that when there is no space for new element Ansary, the values from the old
138
00:09:31,000 --> 00:09:34,000
are a cockpit to the new array was the new size.
139
00:09:35,000 --> 00:09:40,000
OK, but what happens if we have just created the of our type and it's empty?
140
00:09:41,000 --> 00:09:43,000
Let's check the default constructor.
141
00:09:44,000 --> 00:09:47,000
We can see that element data is initialized with the empty array.
142
00:09:48,000 --> 00:09:50,000
This is constant empty array.
143
00:09:50,000 --> 00:09:53,000
But why do we need this default capacity constant?
144
00:09:54,000 --> 00:09:57,000
To answer this, let's get back to zero method.
145
00:09:57,000 --> 00:09:59,000
Pay attention to the if clause here.
146
00:10:00,000 --> 00:10:02,000
If old capacity more than zero.
147
00:10:02,000 --> 00:10:06,000
And we know that when our only has been just created, its size is zero.
148
00:10:07,000 --> 00:10:12,000
And the second clause is if Elliman data is not equal to the full capacity MHRA.
149
00:10:12,000 --> 00:10:17,000
We know that this statement is also false because we initialized our rate with this constant.
150
00:10:18,000 --> 00:10:25,000
So that's why our full program execution goes to the else block where we initialize our element data
151
00:10:25,000 --> 00:10:32,000
array with the rate of the Langston Wighton because it will take Maximilien between ten and one during
152
00:10:32,000 --> 00:10:33,000
the creation of three.
153
00:10:34,000 --> 00:10:37,000
Does it make sense now as a part of your homework?
154
00:10:37,000 --> 00:10:43,000
I would encourage you to go over each method in a release like we did with Add Method to understand
155
00:10:43,000 --> 00:10:46,000
how Array Works program.
156
00:10:46,000 --> 00:10:50,000
You might be wondered whether you can create an array list with a specific capacity.
157
00:10:51,000 --> 00:10:52,000
Yes, you can arrange.
158
00:10:52,000 --> 00:10:59,000
This has special constructor for that here it why you may need to create array list of different capacity.
159
00:11:00,000 --> 00:11:01,000
Let me explain.
160
00:11:01,000 --> 00:11:05,000
You imagine that you created array list with capacity of 10 elements.
161
00:11:05,000 --> 00:11:12,000
That means when you will add 11 element and after that sextants element and so forth, each time I should
162
00:11:12,000 --> 00:11:18,000
copies of values from the previous array and add them to the new array that will cause some spikes in
163
00:11:18,000 --> 00:11:19,000
our performance.
164
00:11:20,000 --> 00:11:26,000
Then if you know that you're going to add to your rate around one million elements right after creation
165
00:11:26,000 --> 00:11:31,000
of the array, at least it is better to set capacity at the beginning to avoid some spikes in the performance.
166
00:11:32,000 --> 00:11:38,000
If we specify capacity for one million elements, we will avoid case when we constantly copying arrays
167
00:11:38,000 --> 00:11:45,000
and creating new objects of arrays, keeping the old arrays in our memory until garbage collector will
168
00:11:45,000 --> 00:11:45,000
remove them.
169
00:11:46,000 --> 00:11:50,000
Is it clear now why you might want to create an array with the initial capacity?
170
00:11:51,000 --> 00:11:51,000
Great.
171
00:11:51,000 --> 00:11:52,000
Let's move on.
172
00:11:53,000 --> 00:11:55,000
There is also one more interesting use case.
173
00:11:55,000 --> 00:12:02,000
Imagine that you added new elements to your array list and after that you removed nine thousand one
174
00:12:02,000 --> 00:12:03,000
hundred elements.
175
00:12:03,000 --> 00:12:07,000
OK, there is a one thousand hundred elements in your list.
176
00:12:08,000 --> 00:12:16,000
But what its capacity, its capacity is still one million to remove new elements from our array.
177
00:12:16,000 --> 00:12:19,000
Inside our list we may call stream to size method.
178
00:12:20,000 --> 00:12:24,000
This method streams the capacity of the relist instance to the list.
179
00:12:24,000 --> 00:12:24,000
Current size.
180
00:12:25,000 --> 00:12:32,000
OK, now you know how the dynamic extension happens in Frailest, I also promised you to explain what
181
00:12:32,000 --> 00:12:34,000
random access is.
182
00:12:34,000 --> 00:12:37,000
Can you see that array list implements random access?
183
00:12:38,000 --> 00:12:40,000
Let's take a look at this interface.
184
00:12:40,000 --> 00:12:43,000
Can you see that this is the empty interface?
185
00:12:43,000 --> 00:12:46,000
It doesn't declare any contract for any behavior.
186
00:12:47,000 --> 00:12:48,000
Then why do we need it at all?
187
00:12:49,000 --> 00:12:52,000
Random access interface is a marker interface.
188
00:12:52,000 --> 00:12:57,000
Sometimes in you would see so-called marker interfaces.
189
00:12:57,000 --> 00:13:00,000
Why is called so xcode so?
190
00:13:00,000 --> 00:13:06,000
Because the only reason why they exist is to mark interface with a specific type to use this information
191
00:13:06,000 --> 00:13:07,000
in the future.
192
00:13:08,000 --> 00:13:10,000
Probably it is still not clear for you.
193
00:13:11,000 --> 00:13:13,000
But let me show you on the example.
194
00:13:13,000 --> 00:13:20,000
Here is a random access interface which is used to mark any class that supports retrieval of elements
195
00:13:20,000 --> 00:13:21,000
for the constant amount of time.
196
00:13:22,000 --> 00:13:29,000
That's actually one of the key features of our list is a constant amount of time for reading an element
197
00:13:29,000 --> 00:13:33,000
is because of the nature of a release and how it works under the hood.
198
00:13:33,000 --> 00:13:38,000
To read an element, you just need to get it from array by specific index.
199
00:13:38,000 --> 00:13:40,000
And this time is usually constant.
200
00:13:41,000 --> 00:13:45,000
That's why our list is marked as implementation of random access.
201
00:13:46,000 --> 00:13:48,000
Now let's see where this information is used.
202
00:13:49,000 --> 00:13:55,000
If we would open collection class, this is class with utility methods nonwar, it will run it in the
203
00:13:55,000 --> 00:13:56,000
separate question.
204
00:13:57,000 --> 00:14:02,000
Right now, I just want to show you how information about market interfaces used I press control and
205
00:14:03,000 --> 00:14:09,000
you simultaneously to search through this file and I want to search for random access words and I have
206
00:14:09,000 --> 00:14:11,000
around fifty eight mentions.
207
00:14:11,000 --> 00:14:18,000
You can see that random access is used with instance of operator and if closes to select specific algorithms
208
00:14:18,000 --> 00:14:22,000
that will work the best here in binary search method.
209
00:14:22,000 --> 00:14:28,000
You may see that in case that were passed as parameter to the mass that is compatible with random access
210
00:14:28,000 --> 00:14:31,000
type then indexed binary search algorithm will be applied.
211
00:14:32,000 --> 00:14:35,000
If no, then iterate a binary search method will be called.
212
00:14:36,000 --> 00:14:41,000
And similarly, in the other method, check for compatibility with random access interface is used to
213
00:14:41,000 --> 00:14:43,000
select the best algorithm.
214
00:14:44,000 --> 00:14:49,000
Right now, I believe you understood the use case and how much the interface may be used.
215
00:14:49,000 --> 00:14:50,000
That's great.
216
00:14:51,000 --> 00:14:52,000
According to the agenda.
217
00:14:52,000 --> 00:14:55,000
Also, we're going to cover today a few more classes.
218
00:14:55,000 --> 00:14:59,000
Zaya Vector, Cooperton writer released and Stack.
219
00:14:59,000 --> 00:15:06,000
While covering those, I will be super fast because they are mostly the same as I released, so I would
220
00:15:06,000 --> 00:15:11,000
draw your attention only to the things that are different from the released here of Extra Vector.
221
00:15:12,000 --> 00:15:18,000
It is almost the same as it released the same mechanism of storing data.
222
00:15:18,000 --> 00:15:21,000
Here is the element data array to store elements.
223
00:15:22,000 --> 00:15:28,000
There's only one big difference between a release and vector on assets and vector a synchronized.
224
00:15:28,000 --> 00:15:29,000
What does that mean?
225
00:15:30,000 --> 00:15:32,000
Let's take a look at the ad method.
226
00:15:32,000 --> 00:15:33,000
For example.
227
00:15:33,000 --> 00:15:36,000
Can you see the key words synchronized in the method definition?
228
00:15:37,000 --> 00:15:43,000
We didn't learn yet this keyword in detail, but we will we will run it in the details durians and we'll
229
00:15:43,000 --> 00:15:44,000
just write in top it.
230
00:15:45,000 --> 00:15:50,000
But right now you can understand this keyword as a restriction for multiple threats of execution and
231
00:15:50,000 --> 00:15:52,000
the method, but body simultaneously.
232
00:15:53,000 --> 00:15:59,000
That means if two threats of execution want to add element, remove element or replace element of a
233
00:15:59,000 --> 00:16:03,000
specific index, they won't be able to do this simultaneously.
234
00:16:04,000 --> 00:16:07,000
All these operations will be performed one after another.
235
00:16:07,000 --> 00:16:11,000
That would save you from the data inconsistency inside the vector.
236
00:16:11,000 --> 00:16:14,000
That's why Vector is called safe container.
237
00:16:15,000 --> 00:16:16,000
Does it make sense?
238
00:16:16,000 --> 00:16:18,000
OK, let's go further.
239
00:16:18,000 --> 00:16:20,000
Let me open a copy right away.
240
00:16:20,000 --> 00:16:22,000
List the same stories here.
241
00:16:23,000 --> 00:16:23,000
Right.
242
00:16:23,000 --> 00:16:26,000
Or at least is a safe version of the array list.
243
00:16:27,000 --> 00:16:30,000
Then what is the difference between vector and copywriter?
244
00:16:30,000 --> 00:16:31,000
At least Corporan.
245
00:16:31,000 --> 00:16:32,000
Right.
246
00:16:32,000 --> 00:16:34,000
The list was introduced in Java version five.
247
00:16:35,000 --> 00:16:39,000
Well, Vector was introduced in the version first in version five.
248
00:16:39,000 --> 00:16:44,000
Engineers come up with improvements in performance for this, let's say, version of a release.
249
00:16:45,000 --> 00:16:49,000
And we can say that right writer released is more efficient from the performance standpoint.
250
00:16:49,000 --> 00:16:54,000
In comparison with Vector, for example, let me open add method.
251
00:16:54,000 --> 00:16:55,000
Can you see this?
252
00:16:56,000 --> 00:16:59,000
There is no synchronized word here, but synchronized block instead.
253
00:17:00,000 --> 00:17:06,000
The White House improvisation is implemented in this class is different from the way it is implemented
254
00:17:06,000 --> 00:17:06,000
in Vector.
255
00:17:07,000 --> 00:17:10,000
That is the difference between vector unreleased and Copan.
256
00:17:10,000 --> 00:17:11,000
Right?
257
00:17:11,000 --> 00:17:11,000
Frailest.
258
00:17:12,000 --> 00:17:18,000
And now let's open this attack was, as you remember from the beginning of the lesson, Stack extends
259
00:17:18,000 --> 00:17:19,000
factor.
260
00:17:19,000 --> 00:17:22,000
But take a look at the map that introduced instead.
261
00:17:23,000 --> 00:17:29,000
What does this remind you of your right that is almost interface of the cube.
262
00:17:29,000 --> 00:17:32,000
The names of the masses are almost the same.
263
00:17:32,000 --> 00:17:36,000
Engineers don't like Stack because this is concrete glass.
264
00:17:36,000 --> 00:17:41,000
That means there is no flexibility in using different implementation of the same API.
265
00:17:42,000 --> 00:17:44,000
It implements LIFO principle.
266
00:17:45,000 --> 00:17:46,000
Last in, first out.
267
00:17:47,000 --> 00:17:52,000
We are going to review this principle in the details when we get closer to the interface.
268
00:17:52,000 --> 00:17:54,000
So don't worry.
269
00:17:54,000 --> 00:18:01,000
Years for now, the LIFO principle is implemented in DEC interface and in different implementation of
270
00:18:01,000 --> 00:18:02,000
that interface.
271
00:18:02,000 --> 00:18:08,000
But Stack was introduced in Java version one and keep the promise of backwards compatibility and to
272
00:18:08,000 --> 00:18:13,000
make sure that programs that are written on Java version first will be successfully executed on the
273
00:18:13,000 --> 00:18:14,000
Java version fifteens.
274
00:18:14,000 --> 00:18:17,000
And later this class is still here.
275
00:18:18,000 --> 00:18:18,000
That's it.
276
00:18:19,000 --> 00:18:23,000
Now, you know, also the difference between a release vector, right.
277
00:18:23,000 --> 00:18:24,000
And released instead.
278
00:18:25,000 --> 00:18:27,000
Now let's recap what we have learned today.
279
00:18:28,000 --> 00:18:31,000
Today, we investigated the Iraqi of least interface.
280
00:18:31,000 --> 00:18:36,000
You saw how you may investigate source code and you Iraqi of any interface in eclipse.
281
00:18:37,000 --> 00:18:42,000
Also in this lesson, we learned when we have to use implementation of the interface, such as every
282
00:18:43,000 --> 00:18:50,000
vector writer relist, and so that we learned in detail how size of the array maybe dynamically increased
283
00:18:50,000 --> 00:18:50,000
in there.
284
00:18:50,000 --> 00:18:56,000
At least now you know the difference between a real E vector right at released and stack.
285
00:18:57,000 --> 00:19:00,000
During the lesson we learned what Mark interfaces are.
286
00:19:00,000 --> 00:19:05,000
On the example of random access interface, we learned how market interface might be used.
287
00:19:06,000 --> 00:19:08,000
That's what we have for today.
288
00:19:08,000 --> 00:19:11,000
Thanks a lot for your attention and see you in the next lesson.
|