Page 1 of 1

About Question enthuware.ocpjp.i.v11.2.3026 :

Posted: Mon Aug 26, 2019 11:48 am
by sir_Anduin@yahoo.de
Why cant the a.b module reside in the .\ directory?
If a.b module needs to access something from the dir2, it will not work. content from dir2 must be placed under dir1.
But iif the a.b module does not need to access anything from dir2 directly it can be stored under the current directory.

Re: About Question enthuware.ocpjp.i.v11.2.3026 :

Posted: Mon Aug 26, 2019 10:57 pm
by admin
>Why cant the a.b module reside in the .\ directory?
Because .\ is not specified in the module-path (i.e. -p).
In the given command, -p points to .\dir1. Therefore, the module must reside in this directory.

>If a.b module needs to access something from the dir2, it will not work. content from dir2 must be placed under dir1.
That's fine. The problem statement does not say anything about classes from the classpath.

>But if the a.b module does not need to access anything from dir2 directly it can be stored under the current directory.
The directory where the module is stored must be on the module-path. current directory is not on the module path in the given command.

Re: About Question enthuware.ocpjp.i.v11.2.3026 :

Posted: Sun Dec 15, 2019 2:49 pm
by philippe
In the correct answer:

Code: Select all

Main.class should be present in dir1\a.b\a\b\c directory or, if it is inside a jar, then its path should be \a\b\c.
If it is inside a jar, then indeed the path should be \a\b\c, but that jar file should also be specified on the module path I believe?

Re: About Question enthuware.ocpjp.i.v11.2.3026 :

Posted: Sun Dec 15, 2019 8:47 pm
by admin
philippe wrote:
Sun Dec 15, 2019 2:49 pm
In the correct answer:

Code: Select all

Main.class should be present in dir1\a.b\a\b\c directory or, if it is inside a jar, then its path should be \a\b\c.
If it is inside a jar, then indeed the path should be \a\b\c, but that jar file should also be specified on the module path I believe?
No, the jar need not be specified explicitly in the module-path. This is where module-path and classpath differ. In module-path, you just need to specify the directory that contains the jar (although you can specify the jar file also). In classpath, you need to specify the jar file.

Re: About Question enthuware.ocpjp.i.v11.2.3026 :

Posted: Tue Jan 16, 2024 9:17 am
by Badem48
Hi,

I am little bit confused about this concept.

For the second option; I know that the -cp or --class-path option (.\dir2 in this case) is used for specifying the location of non-modular jars (or classes). If Main requires classes from a non-modular jar, those jars should be in dir2.

And for the third option; I know that the module path (.\dir1) should contain all the modules that the a.b module depends on. These can be in the form of modular JAR files, each containing a module-info.class.

It feels to me that both 2nd and 3rd options are correct and not 4th. What am I missing?

Plus, for the fourth option; what I know, the package structure inside the module (or jar) does not necessarily reflect the module's name. The Main class should be in the package a.b.c, but the directory structure would typically be dir1\a\b\c\Main.class (if unpackaged) or inside the jar under \a\b\c\Main.class. The module name (a.b) does not dictate the directory or package structure for the classes.

Why this is wrong?

Re: About Question enthuware.ocpjp.i.v11.2.3026 :

Posted: Wed Jan 17, 2024 6:37 am
by admin
Main is part of a named module (name of that module is a.b) and, in the given command. Classes that belong to a named module cannot access nonmodular classes present in the classpath. So option 2 is wrong.

Option 3 is wrong and the reason is given in the explanation: It is not necessary to have a jar file of the module. In this case, dir1 may contain the module in the exploded format also.

Option 4 is correct. In exploded format, the class files must exist in a directory with the same name as the module name. Inside that directory, the package driven directory structure must also exist.

You might want to go through a good book to learn this topic.