Tan115's picture
Add files using upload-large-folder tool
07c2d26 verified
Raw
History Blame
40.3 kB
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.