File size: 40,277 Bytes
07c2d26 | 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 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 | 1
00:00:06,000 --> 00:00:11,000
Hello, the students in this lesson, we're going to learn more about features it was added in Java
2
00:00:11,000 --> 00:00:12,000
version nine.
3
00:00:12,000 --> 00:00:14,000
I'm talking about modules in Java.
4
00:00:14,000 --> 00:00:21,000
There we have really a lot of new things to learn modules, really powerful features that exist in Java
5
00:00:21,000 --> 00:00:22,000
platform.
6
00:00:22,000 --> 00:00:28,000
And if you want to become Java software engineer or get one of Oracle certifications, you have to be
7
00:00:28,000 --> 00:00:29,000
familiar with it.
8
00:00:29,000 --> 00:00:38,000
We'll start lesson from simple and general topics such as what models are and just talking about why
9
00:00:38,000 --> 00:00:42,000
we might need them to help you understand modules better.
10
00:00:42,000 --> 00:00:49,000
I will explain what goals we are trying to achieve by using them and what benefits we expect to get.
11
00:00:50,000 --> 00:00:52,000
We'll review different module types.
12
00:00:53,000 --> 00:01:00,000
After that, we'll learn module directives that we use in the module descriptor and common line options
13
00:01:00,000 --> 00:01:05,000
that might come in handy when you will work with multiple modules from Consult.
14
00:01:05,000 --> 00:01:12,000
And at the end of the lesson, we're going to create modular Hello World application, and I will show
15
00:01:12,000 --> 00:01:18,000
you how to configure it leaves and either you can work with this modular application from Eclipse.
16
00:01:19,000 --> 00:01:22,000
As you can see, we have really a lot of things to do.
17
00:01:22,000 --> 00:01:24,000
Let's start our lesson.
18
00:01:25,000 --> 00:01:28,000
Let's understand first what modules are.
19
00:01:28,000 --> 00:01:37,000
Module is a Nicklin named reusable group of related packages, as well as resources such as images and
20
00:01:37,000 --> 00:01:39,000
Xolo files and module.
21
00:01:39,000 --> 00:01:44,000
The specifying the modules name Xen Modules dependencies.
22
00:01:44,000 --> 00:01:46,000
These are the other modules.
23
00:01:46,000 --> 00:01:49,000
This module depends on zip packages.
24
00:01:49,000 --> 00:01:52,000
It explicitly makes available to other modules.
25
00:01:53,000 --> 00:02:00,000
All other packages in the module I implicitly unavailable to other modules, just services it offers,
26
00:02:01,000 --> 00:02:06,000
the services it consumes, but what other modules it allows?
27
00:02:06,000 --> 00:02:12,000
Reflection and General Module is a packaging mechanism that enables you to package a Java application
28
00:02:13,000 --> 00:02:21,000
or Java API as a separate Java module and general module is packaged as Modular Jar File and Java module
29
00:02:21,000 --> 00:02:24,000
can specify which of Java packages it contains.
30
00:02:24,000 --> 00:02:28,000
That should be visible to OSR Java modules, which he uses.
31
00:02:28,000 --> 00:02:36,000
This module and you have a module must also specify which OSI Jumo modules are required to do its job.
32
00:02:37,000 --> 00:02:45,000
In most single words, Java module is a package for packages that is super simplified, but hope this
33
00:02:45,000 --> 00:02:48,000
will help you to understand this concept.
34
00:02:48,000 --> 00:02:55,000
You can group packages into modules and to ensure encapsulation, you may control access to different
35
00:02:55,000 --> 00:02:57,000
packages within the module.
36
00:02:57,000 --> 00:03:02,000
Modularity as higher level of a nation above packages is a clear.
37
00:03:03,000 --> 00:03:06,000
Java Modules is a new feature in Java nine.
38
00:03:07,000 --> 00:03:15,000
We as a Java Platform Module System Z Java Platform Module System is also sometimes referred to as Java,
39
00:03:15,000 --> 00:03:20,000
Jigsaw or Project Jigsaw, depending on where you read.
40
00:03:20,000 --> 00:03:25,000
Jigsaw was internally used project name during development.
41
00:03:25,000 --> 00:03:29,000
Later, Jigsaw changed the name to Java Platform Module system.
42
00:03:30,000 --> 00:03:37,000
There is a juicer 376 Juicer stands for Java specification request.
43
00:03:37,000 --> 00:03:45,000
This is an actual description of proposed and final specification for the Java platform at any one time.
44
00:03:45,000 --> 00:03:49,000
There are numerous juicers movies with a review and approval process.
45
00:03:50,000 --> 00:03:55,000
In the Juicer 376, we can find list of goals of modular.
46
00:03:55,000 --> 00:04:02,000
Ryzen is a Java Sea platform, and one them such goals as a reliable configuration.
47
00:04:03,000 --> 00:04:10,000
Modularity provides mechanisms for explicitly declaring dependencies between modules in a manner that's
48
00:04:10,000 --> 00:04:14,000
recognized both at compile time and execution time.
49
00:04:15,000 --> 00:04:16,000
The system can work.
50
00:04:16,000 --> 00:04:24,000
Suzy's Dependencies commands a subset of all modules required to support your app from Gemini nine and
51
00:04:24,000 --> 00:04:33,000
forward Java applications must be packaged as Java Modules two zero four and application modules specifies
52
00:04:33,000 --> 00:04:38,000
what OSM modules Java API modules supporting modules.
53
00:04:38,000 --> 00:04:47,000
It uses zero for the Java virtual machine can check the whole module dependency graph from application
54
00:04:47,000 --> 00:04:52,000
module and four one one zero virtual machine starts up.
55
00:04:52,000 --> 00:05:00,000
If any required models are not found at startup, the Java Virtual Machine reports is a missing module
56
00:05:00,000 --> 00:05:03,000
and shuts down before Java nine Mason class.
57
00:05:04,000 --> 00:05:11,000
Just from a Mason Jar file, for example, would not be detected until the application actually tried
58
00:05:11,000 --> 00:05:12,000
to use Zoom Mason class.
59
00:05:13,000 --> 00:05:20,000
This would happen sometime at runtime dependent on one's application tried to use the missing class.
60
00:05:20,000 --> 00:05:28,000
Having missing modules reported at application startup time is a big advantage compared to its runtime
61
00:05:28,000 --> 00:05:37,000
when trying to use Zoom's Mojo Jar plus strong encapsulation zip packages in the module are accessible
62
00:05:37,000 --> 00:05:41,000
to OSM modules only use the module explicitly exports them.
63
00:05:42,000 --> 00:05:51,000
Even then, another module can't use those packages unless it explicitly states that it requires as
64
00:05:51,000 --> 00:05:53,000
other modules capabilities.
65
00:05:53,000 --> 00:05:59,000
This improves platform security because fewer classes accessible to potential attackers.
66
00:06:00,000 --> 00:06:06,000
You may find that considering modularity helps you come up with cleaner, more logical designs.
67
00:06:07,000 --> 00:06:15,000
Scalable Java Platform Robust is a Java platform was a monolith consisting of a massive number of packages,
68
00:06:16,000 --> 00:06:20,000
making it challenging to develop, maintain and evolve.
69
00:06:20,000 --> 00:06:22,000
It couldn't be easily subset.
70
00:06:23,000 --> 00:06:27,000
The platform is now one of the rise into ninety five modules.
71
00:06:28,000 --> 00:06:30,000
This number might change as Java evolves.
72
00:06:31,000 --> 00:06:38,000
You can create custom rom coms consisting of only modules you need for your apps was devices you are
73
00:06:38,000 --> 00:06:39,000
targeting.
74
00:06:39,000 --> 00:06:46,000
For example, if a device doesn't support graphical user interfaces, you could create a runtime that
75
00:06:46,000 --> 00:06:47,000
doesn't include xG.
76
00:06:47,000 --> 00:06:56,000
UI modules significantly reduces your runtime size before Java nine and the Java Platform Module system.
77
00:06:56,000 --> 00:07:03,000
You would have had to package all of the Java platform APIs with your job application because there
78
00:07:03,000 --> 00:07:06,000
was no official way of reliable checking.
79
00:07:06,000 --> 00:07:09,000
What crosses your Java application use?
80
00:07:10,000 --> 00:07:16,000
Since the job platform API eyes have grown quite large over the years, your application will get the
81
00:07:16,000 --> 00:07:23,000
large amount of Java classes included in its distribution, many of which your application would probably
82
00:07:23,000 --> 00:07:24,000
not be using.
83
00:07:25,000 --> 00:07:32,000
Greater platform integrity Before Java Non, it was possible to use many classes in the platform as
84
00:07:32,000 --> 00:07:35,000
it were not meant for use by and apps.
85
00:07:35,000 --> 00:07:43,000
Classes with strong encapsulation zones and channel API are truly encapsulated and hidden from apps
86
00:07:43,000 --> 00:07:45,000
using the platform.
87
00:07:45,000 --> 00:07:51,000
This can make migrating legacy code the Modularized Java non problematic.
88
00:07:51,000 --> 00:07:59,000
If your code depends on internal APIs, then use glossies make up the key from distributable big, then
89
00:07:59,000 --> 00:08:00,000
it needs to be.
90
00:08:01,000 --> 00:08:08,000
This can be a problem on small devices like mobile phones, Raspberry Pi, etc. was a Java platform
91
00:08:08,000 --> 00:08:09,000
modular system.
92
00:08:10,000 --> 00:08:16,000
You can now package your application was always a module of the Java Platform API that your application
93
00:08:16,000 --> 00:08:18,000
is actually using.
94
00:08:18,000 --> 00:08:21,000
This will result in small application distribution.
95
00:08:21,000 --> 00:08:24,000
Both improve performance.
96
00:08:25,000 --> 00:08:29,000
Gem uses various optimization techniques to improve application performance.
97
00:08:30,000 --> 00:08:38,000
GSR 376 indicates that these techniques are more effective when it's known in advance.
98
00:08:39,000 --> 00:08:46,000
Word types are located only in specific modules, and this was a great improvement for Java as a platform.
99
00:08:47,000 --> 00:08:53,000
Nowadays, questions about modules among many questions during different Oracle certifications.
100
00:08:54,000 --> 00:08:57,000
Let's talk now about different modules types.
101
00:08:57,000 --> 00:09:03,000
There are four types of modules in the new model system system modules.
102
00:09:03,000 --> 00:09:07,000
These other modules listed when we run Java.
103
00:09:07,000 --> 00:09:14,000
These modules Command Z, includes a Java Sea and JDK modules application modules.
104
00:09:15,000 --> 00:09:22,000
These models are what we usually want to build when we decide to use modules z unnamed and defined as
105
00:09:22,000 --> 00:09:28,000
a compile module info class file included in the assembled jar.
106
00:09:28,000 --> 00:09:37,000
Today, we are going to create our own module info file and see all examples automatic modules.
107
00:09:37,000 --> 00:09:43,000
We can include unofficial modules by an existing jar files to the module pass.
108
00:09:43,000 --> 00:09:47,000
The name of the module will be derived from the name of the jar.
109
00:09:48,000 --> 00:09:58,000
Automatic modules will have full access to every OSM module loaded by pass name tomorrow when a class
110
00:09:58,000 --> 00:10:01,000
or jar is loaded into the class bus.
111
00:10:01,000 --> 00:10:03,000
But no, the module bus.
112
00:10:03,000 --> 00:10:06,000
It's automatically added to the unnamed model.
113
00:10:07,000 --> 00:10:14,000
It's a catch all model to maintain backwards compatibility with previously written Java code.
114
00:10:14,000 --> 00:10:19,000
The unnamed, more new concept is similar to the default package.
115
00:10:19,000 --> 00:10:26,000
Therefore, it is not considered a real model but can be viewed as a default module.
116
00:10:26,000 --> 00:10:33,000
We can create multi-modal projects comprised of a main application and several library modules.
117
00:10:33,000 --> 00:10:39,000
We have to be careful, though, because we can only have one module per jar file.
118
00:10:40,000 --> 00:10:46,000
Let's see now what module descriptor is and what are the different directives that might be used in
119
00:10:46,000 --> 00:10:53,000
the module if a Java file, as we have discussed already, a module must provide a module descriptor
120
00:10:53,000 --> 00:11:00,000
metadata that specifies the modules, dependencies, zip packages the model makes available to other
121
00:11:00,000 --> 00:11:07,000
modules and more, and module descriptor is a compiled version of the module declaration that's defined
122
00:11:07,000 --> 00:11:09,000
in the file name module.
123
00:11:09,000 --> 00:11:16,000
Info jowar and the first scene that we need to do is to create a file was named Module Info and with
124
00:11:16,000 --> 00:11:17,000
Java extension.
125
00:11:18,000 --> 00:11:22,000
This file should be located in the source code directory.
126
00:11:23,000 --> 00:11:31,000
Each module declaration begins with the keyword module, followed by a unique module name and the module
127
00:11:31,000 --> 00:11:35,000
body enclosed in races like you see in that example.
128
00:11:35,000 --> 00:11:40,000
In general, module name follows the same naming rules as Java packages.
129
00:11:41,000 --> 00:11:48,000
However, you should not use underscores any module names or package names, class and these massive
130
00:11:48,000 --> 00:11:56,000
names, variable names, etc. from Gemini and Forward because Java wants to use underscore as reserved
131
00:11:56,000 --> 00:11:58,000
and easy to in the future.
132
00:11:58,000 --> 00:12:05,000
It is recommended to name a Java module is the same as the name of the root Java package contained in
133
00:12:05,000 --> 00:12:06,000
the module.
134
00:12:06,000 --> 00:12:14,000
If that is possible, because some of this might contain multiple packages is a module declarations,
135
00:12:14,000 --> 00:12:22,000
but it can be empty or may contain various module directives, including the requis experts provide
136
00:12:22,000 --> 00:12:27,000
space, etc. We are going to discuss each of these in a few minutes.
137
00:12:27,000 --> 00:12:35,000
As you'll see later, components and module declaration create is a model descriptor, which is stored
138
00:12:35,000 --> 00:12:40,000
in the file named Module Info, plus the Modules folder.
139
00:12:40,000 --> 00:12:48,000
On this slide, I will briefly introduce each module directive Zacchaeus only in module declarations
140
00:12:48,000 --> 00:12:53,000
and may be used as identifiers anywhere else in your code.
141
00:12:53,000 --> 00:12:56,000
Let's learn now directives.
142
00:12:56,000 --> 00:13:00,000
The first directives that we are given to them is requires.
143
00:13:00,000 --> 00:13:06,000
This module directive allows us to declare module dependencies, for example.
144
00:13:06,000 --> 00:13:13,000
In this case, my module has both a runtime and the compile time dependency on some module that you
145
00:13:13,000 --> 00:13:15,000
should refer by module name.
146
00:13:16,000 --> 00:13:20,000
Each module must explicitly state its dependencies.
147
00:13:20,000 --> 00:13:30,000
When Module eight requires Model B, Module A is set to read Module B and Module B is spread by Module
148
00:13:30,000 --> 00:13:37,000
A, the specified dependency on another module user requires and all public Typekit.
149
00:13:37,000 --> 00:13:43,000
Experts from a dependency are accessible by our module when we use this directive.
150
00:13:43,000 --> 00:13:50,000
Another important mention here is that it is not allowed to have separate dependencies between modules.
151
00:13:50,000 --> 00:14:00,000
In other words, if Module eight requires Module B, Module B can also require module a z module dependency
152
00:14:00,000 --> 00:14:06,000
graph must be an acyclic graph and thus a directive is a quasi static.
153
00:14:06,000 --> 00:14:09,000
We might write a lot of functions that pretty.
154
00:14:10,000 --> 00:14:18,000
Our internal state one another to log in module is present, but not every consumer of our level will
155
00:14:18,000 --> 00:14:24,000
want this functionality, and they don't want to include an extra log in library.
156
00:14:24,000 --> 00:14:28,000
In this case, we want to use an optional dependency.
157
00:14:29,000 --> 00:14:35,000
By using the request setting directive, we create a compile time only dependency.
158
00:14:35,000 --> 00:14:38,000
Now let's learn transitive directive.
159
00:14:39,000 --> 00:14:45,000
Imagine that we want to use third party library, and that library in turn has other dependencies.
160
00:14:46,000 --> 00:14:54,000
How we can make sure that any module that we are dependent on will bring its own dependencies to work
161
00:14:54,000 --> 00:14:54,000
properly.
162
00:14:55,000 --> 00:15:03,000
We can force any downstream consumers also to read our required dependencies, which requires transitive.
163
00:15:03,000 --> 00:15:11,000
Attractive, let's review exports DirecTV Now, as you already could understand, is a strong encapsulation
164
00:15:11,000 --> 00:15:18,000
was one of the main goal when Java Platform Module System has been introduced by default, and Model
165
00:15:18,000 --> 00:15:22,000
doesn't expose any of its API to other modules.
166
00:15:23,000 --> 00:15:31,000
Our code is significantly more secure if we don't expose our API to external users.
167
00:15:31,000 --> 00:15:38,000
But what if we created API that it should be used by different modules and we need to explicitly make
168
00:15:38,000 --> 00:15:40,000
it available for everyone?
169
00:15:40,000 --> 00:15:46,000
We use the experts directive to expose all public members of the named package.
170
00:15:47,000 --> 00:15:55,000
Please note that only the least the package itself is experts now support packages of the experts package
171
00:15:56,000 --> 00:15:56,000
experts.
172
00:15:57,000 --> 00:16:06,000
That means that even this package, in my example, contains a package named You Zens Akombe.
173
00:16:06,000 --> 00:16:11,000
My package name util package is not exported.
174
00:16:11,000 --> 00:16:16,000
Just because of parent package is to export the SAP package.
175
00:16:16,000 --> 00:16:24,000
Also, we must declare it explicitly in the module descriptor, and the one module is a singular package
176
00:16:24,000 --> 00:16:29,000
can only be exported by a single Java module at one time.
177
00:16:29,000 --> 00:16:37,000
In other words, you can't have two or more and more and use that export the same package in use at
178
00:16:37,000 --> 00:16:38,000
the same time.
179
00:16:39,000 --> 00:16:46,000
The Java Virtual Machine will come clean startup if you do having two modules export.
180
00:16:46,000 --> 00:16:55,000
The same package is also sometimes referred to as a split package by split package is meant that the
181
00:16:55,000 --> 00:17:01,000
total content classes of the package is split between the multiple modules.
182
00:17:02,000 --> 00:17:03,000
This is not allowed.
183
00:17:04,000 --> 00:17:13,000
In case we want to limit access to our API and expose it only to some packages XL, we have to use experts
184
00:17:13,000 --> 00:17:17,000
to direct it similar to the experts directive.
185
00:17:17,000 --> 00:17:25,000
We declare a package as experts, but we also list which models we are allowing to import this package
186
00:17:25,000 --> 00:17:26,000
as it requires.
187
00:17:27,000 --> 00:17:36,000
And here's how it looks like the next directive is users now use this Model Directive Force, a service
188
00:17:36,000 --> 00:17:44,000
used by this module, making the model a service consumer, a service services, an object of loss that
189
00:17:44,000 --> 00:17:45,000
implements the interface.
190
00:17:45,000 --> 00:17:49,000
So extensive apps are specified in the users directive.
191
00:17:50,000 --> 00:17:55,000
With this in mind, the services our model consumes with a users directive.
192
00:17:56,000 --> 00:17:58,000
No, just the last name we use.
193
00:17:58,000 --> 00:18:06,000
This is the interface for apps, loss of the service, the on the implementation class, because service
194
00:18:06,000 --> 00:18:12,000
in this context means and implementation of a specific interface or apps a gloss that can be consumed
195
00:18:12,000 --> 00:18:14,000
by OSI classes.
196
00:18:14,000 --> 00:18:21,000
But what is the difference between uses and requires the wrappers we might require and more uses?
197
00:18:21,000 --> 00:18:29,000
It provides a service we want to consume, but that service implements an interface from one of its
198
00:18:29,000 --> 00:18:36,000
transitive dependencies instead of forcing our module to require all transitive dependencies.
199
00:18:36,000 --> 00:18:43,000
Just in case we use the uses, Directive two adds the required interface to the module.
200
00:18:43,000 --> 00:18:44,000
POS is a career.
201
00:18:45,000 --> 00:18:52,000
We have discussed directives that consumes the services, but this also means that we have modules that
202
00:18:52,000 --> 00:19:00,000
provides services so a module can also be a service providers that other modules can consume, and we
203
00:19:00,000 --> 00:19:04,000
can ensure this voice provides with direction.
204
00:19:05,000 --> 00:19:12,000
We should write provides key words first and specifies the interface or abstract class name of our service
205
00:19:13,000 --> 00:19:14,000
is Let's see.
206
00:19:14,000 --> 00:19:21,000
What we have to do is to specify what specific implementation of our service we are going to provide
207
00:19:22,000 --> 00:19:24,000
was a help with directing.
208
00:19:25,000 --> 00:19:29,000
You provide the implementation class name that isn't implements.
209
00:19:29,000 --> 00:19:33,000
The interface or extents is an abstract class.
210
00:19:34,000 --> 00:19:40,000
The next important declarations that I'd like to show you opens and opens to.
211
00:19:41,000 --> 00:19:44,000
Let's learn this before December nine.
212
00:19:44,000 --> 00:19:53,000
Reflection could be used to learn about all types in the package and all members of it time even its
213
00:19:53,000 --> 00:19:58,000
private members, was the one that allows this capability on not.
214
00:19:59,000 --> 00:20:04,000
Thus, nothing was truly encapsulated like we have discussed already.
215
00:20:05,000 --> 00:20:12,000
The key motivation of the module system is strong, and cancellation by default and died in the module
216
00:20:12,000 --> 00:20:19,000
is not accessible to OSM modules unless it's a public type and you export its package.
217
00:20:20,000 --> 00:20:26,000
You expose all the packages you want to expose with Gemini.
218
00:20:26,000 --> 00:20:28,000
This also applies to reflection.
219
00:20:29,000 --> 00:20:36,000
For example, we can allow runtime only access to a package, so directive opened.
220
00:20:36,000 --> 00:20:44,000
Some package indicates that a specific package is public types and then nested public and protected
221
00:20:44,000 --> 00:20:49,000
types accessible to code in other modules at runtime only.
222
00:20:49,000 --> 00:20:59,000
Also, all the types in the specified package and all of the types members are accessible via reflection.
223
00:20:59,000 --> 00:21:08,000
Another example We can allow runtime only access the package by specific modules and opens to Model
224
00:21:08,000 --> 00:21:08,000
Directive.
225
00:21:09,000 --> 00:21:18,000
Like, for example, open package name to some list of modules indicates that specific packages, public
226
00:21:18,000 --> 00:21:26,000
types and then nascent public and protected types are accessible to code in the list of modules at runtime
227
00:21:26,000 --> 00:21:27,000
only.
228
00:21:27,000 --> 00:21:35,000
All of the types in the specified package and all of the types members are accessible via reflection
229
00:21:35,000 --> 00:21:37,000
to court in the specified modules.
230
00:21:38,000 --> 00:21:45,000
We have discussed already that one of the main goals of modules is strong encapsulation, and I believe
231
00:21:45,000 --> 00:21:50,000
that you watched the previous lesson and you're pretty familiar with reflection by this moment already.
232
00:21:51,000 --> 00:21:58,000
So you can understand that before June nine, it was possible to use a reflection to examine every type
233
00:21:59,000 --> 00:22:02,000
and the member in the package, even the private ones.
234
00:22:03,000 --> 00:22:04,000
Was through.
235
00:22:04,000 --> 00:22:11,000
Really encapsulated, which can open up all kinds of problems for developers of the libraries because
236
00:22:11,000 --> 00:22:13,000
Java nine enforce a strong encapsulation.
237
00:22:14,000 --> 00:22:21,000
We have to explicitly grant permission for OSM modules to reflect on our classes if we want to continue
238
00:22:21,000 --> 00:22:28,000
to allow full reflection as older versions of Java did, we can simply opens entire modules by using
239
00:22:28,000 --> 00:22:32,000
open direct before module name like you see on the slide.
240
00:22:33,000 --> 00:22:35,000
Does it make sense so far?
241
00:22:35,000 --> 00:22:42,000
And please always remember these in case you have any questions, please post them below this video
242
00:22:42,000 --> 00:22:45,000
and I will be happy to answer those.
243
00:22:45,000 --> 00:22:51,000
We have just learned directives that we can use in our modules in profile.
244
00:22:51,000 --> 00:22:55,000
The next step would be to learn how to build our modules.
245
00:22:56,000 --> 00:22:59,000
And before I show you examples of how to do that.
246
00:23:00,000 --> 00:23:01,000
Let me explain.
247
00:23:01,000 --> 00:23:08,000
Different command line options that we can use when we build Java modules, even despite the fact that
248
00:23:08,000 --> 00:23:15,000
later in our course, we are going to learn such views as Randall and May one and zero when you have
249
00:23:15,000 --> 00:23:18,000
support for building modules in Java.
250
00:23:18,000 --> 00:23:22,000
It's still valuable to know how to use modules.
251
00:23:22,000 --> 00:23:28,000
System forms a common plan will be used as a common line for our full example.
252
00:23:28,000 --> 00:23:36,000
I'm going to show you in a few minutes to help solidify how the entire system works in our minds.
253
00:23:37,000 --> 00:23:38,000
Module Pass.
254
00:23:38,000 --> 00:23:42,000
We use a module pass option to specify the module for us.
255
00:23:42,000 --> 00:23:49,000
This is a list of one on one directories that contain our modules athletes.
256
00:23:49,000 --> 00:23:57,000
Instead of relying on the module declaration file, we can use the command line equivalent of the requires
257
00:23:57,000 --> 00:23:59,000
directors and experts.
258
00:24:00,000 --> 00:24:09,000
Common Line replacement for the X Plus DirecTV and Opens replaces the open clause in the module declaration
259
00:24:09,000 --> 00:24:16,000
file adds modules adds is a list of modules into the default set of modules.
260
00:24:16,000 --> 00:24:24,000
These modules creates a list of all modules and their version strings by each module.
261
00:24:24,000 --> 00:24:27,000
Add or overwrite classes in modules.
262
00:24:28,000 --> 00:24:38,000
Illegal acts was values is permit over or do not use a relaxed encapsulation by showing a single global
263
00:24:38,000 --> 00:24:43,000
warning shows rewarding or fails with errors.
264
00:24:43,000 --> 00:24:45,000
The default is permit.
265
00:24:46,000 --> 00:24:49,000
Finally, we are done with the mini series piece.
266
00:24:49,000 --> 00:24:53,000
Let's continue learning modules with examples now.
267
00:24:53,000 --> 00:24:57,000
This would be our Hello World modular application.
268
00:24:57,000 --> 00:25:04,000
Thus, it would all be super complicated because the main goal right now is to make you understand key
269
00:25:04,000 --> 00:25:07,000
principles of modular application.
270
00:25:08,000 --> 00:25:15,000
The rest of the synths will be super easy to understand if you learned how everything works on the hood.
271
00:25:15,000 --> 00:25:23,000
So first of all, I want to say that for the sake of the demo, I created separate multi module project.
272
00:25:23,000 --> 00:25:27,000
I will share with you a link to it in attachments to this lesson.
273
00:25:28,000 --> 00:25:32,000
I have Food Project folder and I created the Modules folder.
274
00:25:33,000 --> 00:25:38,000
Apparently, this folder will contain different modules of my app.
275
00:25:38,000 --> 00:25:43,000
It is full of some main modules as a root source package.
276
00:25:43,000 --> 00:25:49,000
For example, it was a top level package of the module is compatibles greetings.
277
00:25:49,000 --> 00:25:52,000
Then I named the module in the same way.
278
00:25:53,000 --> 00:25:55,000
Note this is a full stops.
279
00:25:55,000 --> 00:25:57,000
These are modular root directory name.
280
00:25:58,000 --> 00:26:07,000
Z's full stops need to be easier because part of the module name Zen not to be interpreted as subdirectory
281
00:26:07,000 --> 00:26:08,000
POS dividers.
282
00:26:09,000 --> 00:26:09,000
Is it the.
283
00:26:10,000 --> 00:26:13,000
As you can see, I have two models here.
284
00:26:13,000 --> 00:26:16,000
Let me start from greeting Swan.
285
00:26:16,000 --> 00:26:24,000
It contains loss was named greetings and static mass insight that brings hello world to console.
286
00:26:25,000 --> 00:26:28,000
Each model should have Model E for file.
287
00:26:29,000 --> 00:26:32,000
Let's look at the model descriptor of this model.
288
00:26:32,000 --> 00:26:34,000
On the top, you can see model name.
289
00:26:35,000 --> 00:26:42,000
Basically, model name and name of the model for this should match and be expert package from this model.
290
00:26:42,000 --> 00:26:46,000
Experts directive is used was package name.
291
00:26:47,000 --> 00:26:53,000
Now creates a second model is the name of my second module is Compatibles App.
292
00:26:53,000 --> 00:26:56,000
This is the main module that uses greetings module.
293
00:26:57,000 --> 00:27:04,000
It has only one class was the main message where we use greetings class to invoke say hello mass pay
294
00:27:04,000 --> 00:27:05,000
attention.
295
00:27:05,000 --> 00:27:11,000
We also have the import statement here to import greetings class from another package.
296
00:27:11,000 --> 00:27:14,000
This module also has module descriptor.
297
00:27:15,000 --> 00:27:16,000
Let's look at it.
298
00:27:16,000 --> 00:27:24,000
Here we can see that this module requires my greetings module, and this is all of this agree because
299
00:27:24,000 --> 00:27:27,000
we are using class from greetings module in this one.
300
00:27:28,000 --> 00:27:36,000
Then the stand dependencies between these two modules, if he isn't great, if no, please press pause
301
00:27:36,000 --> 00:27:40,000
for a minute and think about it one more time.
302
00:27:40,000 --> 00:27:48,000
The next step that we need to do this to compile our models specially for that, I create a script that
303
00:27:48,000 --> 00:27:50,000
will compile all sources.
304
00:27:50,000 --> 00:28:00,000
It is located in the root directory and it is called Build this sage I use Linux shall come here, so
305
00:28:00,000 --> 00:28:07,000
pay attention to your transit script, either on Linux platforms or from Bosch on your Windows machine
306
00:28:07,000 --> 00:28:12,000
and do not use Windows Common Line to run this script.
307
00:28:12,000 --> 00:28:14,000
You know what Java commands?
308
00:28:15,000 --> 00:28:16,000
This is our Java compiler.
309
00:28:17,000 --> 00:28:24,000
After that, I pass the name of the output directly to specify where I want to put the compiled classes.
310
00:28:25,000 --> 00:28:29,000
The next thing I do, I need to pass module source plus option.
311
00:28:30,000 --> 00:28:33,000
This is different from the one I shared before.
312
00:28:33,000 --> 00:28:40,000
If you remember the interview module courses on a separate slot, there is a difference between module
313
00:28:40,000 --> 00:28:43,000
costs and module source boss.
314
00:28:43,000 --> 00:28:51,000
The component needs a distinction between the code it used to compile in module source, boss and location
315
00:28:51,000 --> 00:28:55,000
of compiled dependencies and libraries.
316
00:28:55,000 --> 00:28:58,000
Module boss does it make more sense now?
317
00:28:59,000 --> 00:29:02,000
I was here name of my folder with modules.
318
00:29:03,000 --> 00:29:09,000
After that, I used Show Command to find old files with Java Extension in Modules folder.
319
00:29:10,000 --> 00:29:13,000
Once my modular app is compiled, I can run it.
320
00:29:14,000 --> 00:29:16,000
I have another script for this.
321
00:29:16,000 --> 00:29:18,000
Is it a school run app or sage?
322
00:29:19,000 --> 00:29:21,000
Let's look at it in this script.
323
00:29:21,000 --> 00:29:25,000
You also see program that is familiar to you, Java.
324
00:29:26,000 --> 00:29:28,000
I am going to start Java Virtual Machine.
325
00:29:29,000 --> 00:29:37,000
I use option module POS to puzzle the reference to the compiled modules and after completion, all of
326
00:29:37,000 --> 00:29:41,000
them are stored in target output directory.
327
00:29:41,000 --> 00:29:49,000
You can see that all files here have class extension and even module info file is compiled into class
328
00:29:49,000 --> 00:29:49,000
file.
329
00:29:50,000 --> 00:29:58,000
Zen I specifies that most of the class it contains main message zip past consists of module name and
330
00:29:58,000 --> 00:29:59,000
full class name.
331
00:30:00,000 --> 00:30:08,000
So in this particular example, Compatibles Rules app is the model name and call it Bus App.
332
00:30:08,000 --> 00:30:11,000
App is a full class name.
333
00:30:11,000 --> 00:30:12,000
Is this clear?
334
00:30:13,000 --> 00:30:17,000
For the sake of the demo, I opened it March inside eclipse.
335
00:30:17,000 --> 00:30:27,000
I run build S.H. script first, and after that I run run apps, script and hindcast so we can see Hello
336
00:30:27,000 --> 00:30:29,000
World from the application.
337
00:30:29,000 --> 00:30:30,000
Can you see this?
338
00:30:30,000 --> 00:30:34,000
Congratulations to you with your first modular application.
339
00:30:35,000 --> 00:30:40,000
One more small comment here was the moment of recording this video.
340
00:30:40,000 --> 00:30:45,000
There is no single and proper way of using Eclipse to run multi-modal application.
341
00:30:46,000 --> 00:30:51,000
There might be some additional steps to configure multimodal application in eclipse.
342
00:30:52,000 --> 00:30:59,000
That's why, even on your work, most likely you would use common client to build and to run your complex
343
00:30:59,000 --> 00:31:02,000
enterprise application for the sake of convenience.
344
00:31:03,000 --> 00:31:10,000
You still can work in eclipse, but do you need to be prepared that sometimes you will see more errors?
345
00:31:10,000 --> 00:31:17,000
Is unusual because sometimes it is hard to conceive of all dependencies, not in the app, but in the
346
00:31:17,000 --> 00:31:25,000
creep's itself in order Eclipse would understand the clearly dependencies between all modules.
347
00:31:25,000 --> 00:31:33,000
Here's an example you can import two modules as separate projects and work in Java editor was Java files.
348
00:31:34,000 --> 00:31:42,000
But in app module, you may see error because Eclipse can't see dependency on another module.
349
00:31:42,000 --> 00:31:49,000
Since technically fruit loops, this is a separate project, and the groups allows only one module info
350
00:31:49,000 --> 00:31:51,000
file per project.
351
00:31:51,000 --> 00:31:53,000
In order to remove the error.
352
00:31:53,000 --> 00:31:57,000
Sometimes you may need to configure dependencies manually.
353
00:31:57,000 --> 00:32:04,000
If Eclipse didn't manage to configure everything automatically, for example, in my app module, I
354
00:32:04,000 --> 00:32:11,000
open built up submenu, configure builds bus and here on library staff.
355
00:32:12,000 --> 00:32:16,000
On the Module POS, I select Add Class Folder.
356
00:32:16,000 --> 00:32:24,000
Here I put checkbox next to the modules that they need in this one, namely Reding's module and press,
357
00:32:24,000 --> 00:32:24,000
OK.
358
00:32:25,000 --> 00:32:32,000
Now you wouldn't see any errors in the clips, but in case you have multiple modules and not all of
359
00:32:32,000 --> 00:32:34,000
them, I configure it automatically.
360
00:32:34,000 --> 00:32:41,000
This might take time during the configuration of your project very first time after these configuration
361
00:32:41,000 --> 00:32:42,000
steps.
362
00:32:42,000 --> 00:32:44,000
You may run even from Eclipse.
363
00:32:45,000 --> 00:32:51,000
Can you see this great since you have near Z simple syncs already?
364
00:32:51,000 --> 00:32:56,000
Let me show you how to add the service to our modular application.
365
00:32:56,000 --> 00:33:04,000
In my Goulding's module, I declare an interface was name service status log that contains only one
366
00:33:04,000 --> 00:33:07,000
massive print service that is slow.
367
00:33:07,000 --> 00:33:10,000
I have implementation of this interface.
368
00:33:10,000 --> 00:33:17,000
Is it the school default service status slogan for the sake of our demo and just brings text to console?
369
00:33:18,000 --> 00:33:26,000
Now, in my model info file, I need to declare that this module provides such service was a complete
370
00:33:26,000 --> 00:33:27,000
implementation.
371
00:33:27,000 --> 00:33:30,000
I use provides service directive for.
372
00:33:30,000 --> 00:33:37,000
This is the next logical step would be to consumes this service in my app module.
373
00:33:37,000 --> 00:33:44,000
I use uses directly for that and specify full class name of the interface.
374
00:33:45,000 --> 00:33:52,000
After that, in App G+ with the help of Service Loader from January to package I can load my service.
375
00:33:52,000 --> 00:33:57,000
I use load mass and quasi loss of the services that I need.
376
00:33:57,000 --> 00:34:00,000
Service loader is a terrible time.
377
00:34:01,000 --> 00:34:07,000
That's why it has iterate mass app that allows me to get a reference to the first service load.
378
00:34:07,000 --> 00:34:12,000
The object in the sequence handles a reference to the object.
379
00:34:12,000 --> 00:34:15,000
I can call print service that is massive.
380
00:34:16,000 --> 00:34:24,000
Let's now use our new brush to compile new sources one more time and run our app in so you can see that
381
00:34:24,000 --> 00:34:27,000
we successfully managed to invoke service message.
382
00:34:28,000 --> 00:34:31,000
That's all what I wanted to share with you in this lesson.
383
00:34:32,000 --> 00:34:35,000
Let's recap what we have learned in this lesson.
384
00:34:36,000 --> 00:34:40,000
In the lesson we have learned what general models are all seeing.
385
00:34:40,000 --> 00:34:45,000
Those are goals that we want to achieve and that that captures images.
386
00:34:45,000 --> 00:34:47,000
376.
387
00:34:47,000 --> 00:34:53,000
We have learned different more of those types of after that revealed details.
388
00:34:53,000 --> 00:35:01,000
Different command line options to work was more use and on real example, you saw how to create, build
389
00:35:01,000 --> 00:35:03,000
and run modular application.
390
00:35:04,000 --> 00:35:06,000
Together, we can simulate eclipse.
391
00:35:06,000 --> 00:35:13,000
The work was modular application form I.D. and the zenith of the lesson I explained to you how to provide
392
00:35:13,000 --> 00:35:16,000
and consume service in different modules.
393
00:35:17,000 --> 00:35:19,000
Thanks a lot for your attention.
394
00:35:19,000 --> 00:35:22,000
Have a great day and see you in the next lesson.
|