Skip to content

Instantly share code, notes, and snippets.

@aman-junaid
Last active October 10, 2022 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aman-junaid/414b71feb82f476680e287b3c5a2908c to your computer and use it in GitHub Desktop.
Save aman-junaid/414b71feb82f476680e287b3c5a2908c to your computer and use it in GitHub Desktop.
Java Module outline
module <module name> {
requires <other modules required by this module>;
/*
Ex. requires java.logging
There are other variants of requires
1. requires transitive org.foo; - this means that the current module requires
this module and other modules using the current module will also need org.foo.
2. requires static com.foo; - this means, the dependency is at compile time only,
not needed at runtime. This can be used for incomplete features.
Note -
1. Directive requires java.base is implied to all the modules.
2. More than one module can be put as comma seperated list.
*/
exports <packages of this module to be exported for the other modules>;
/*
Ex- exports com.aj.demo;
There is one varient of exports
1. exports <packages> to <other module>; - This specifies that this exported package is
available for use in the <other module> only.
Note -
1. If a class is public but the package containing the class in not in exports,
the class will not be available for other modules to be used.
*/
opens <packages of this module open to other modules via reflection>;
/*
opens - it is similar to the exports + reflection API allowed
*/
uses <name of the sevices provide by other module that this module uses>;
/*
Ex -
requires service;
uses services.X;
Note -
A service comprises of an interface or an abstract class whose implementation is provided by
a provider class. uses implies the services class which has to be used. This is basically
an interface or an abstract class.
*/
provides <services to other modules> with <services implementations>;
/*
Ex -
requires services;
provides services.X
with provider.Y
Note -
1. provider.Y is the implementation of services.X
*/
version <version of this module>
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment