Early Charlemagne wrote:Hi,
I have a query about Automatic modules.
On Chapter 6 in the Java OCP 11 Programmer II Study Guide by Scott Selikoff and Jeanne Boyarsky it's written "A key point to remember is that code on the classpath can access the module path. By contrast, code on the module path is unable to read from the classpath."
Also, looking at Table 6.3 (see attachment) I understand that Automatic modules cannot access unnamed modules on the classpath.
However, I read elsewhere the following:
Remember that modular code cannot access code present on the -classpath but "automatic modules" are an exception to this rule. When a non-modular jar is put on --module-path, it becomes an "automatic module" but it can still access all the modular as well as non-modular code. In other words, a class from an automatic module can access classes present on --module-path as well as on -classpath without having any "requires" clause
Did I misunderstand the information in Java OCP 11 Programmer II Study Guide?
Hi,
Unnamed modules are on the classpath. They can access JAR files on both the classpath and the module path.
Named modules are on the module path, they cant access any unnamed module.
Automatic module are on the module path, they can access all the modular as well as non-modular code.
For example, using Bottom-Up migration strategy, you have a mix of named and unnamed modules.The named modules are the low-level that have been migrated. They are on the module path and not allowed to access any unnamed modules, but the high-level that have not been migrated are unnamed and they access the low-level(named).
Another example, top-down migration, you move all projects to module path(now they are automatic modules), then you choose the first module that has more dependencies to add the module-info to convert the automatic module into a named module. If the modules that are low-level(have less dependence) were unnamed (that is, they were in the classpath) this strategy would not work, since named modules cannot access unnamed modules.Thats why you must move all projects to module path, using this strategy.