Java.lang.module Page

java.lang.module



Return to Java Modules, java.lang, java.base, JDK 17 API Specification, Java Docs, Java, Java DevOps - Java SRE - Java CI/CD, Cloud Native Java - Java Microservices - Serverless Java, Java Security - Java DevSecOps, Functional Java, Java Concurrency, Java Data Science - Java and Databases, Java Machine Learning, Java Bibliography, Java Courses, Java Glossary, Awesome Java, Java GitHub, Java Topics

https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/module/package-summary.html



Overview



The `java.lang.module` package is a core part of the Java Platform Module System (JPMS), introduced in Java 9. It provides classes and interfaces to interact with and manage modules at runtime. This package allows developers to programmatically access information about modules, their dependencies, exported packages, and more.

Key Classes and Interfaces



* **Module**: Represents a named module in the Java runtime. Provides methods to access module metadata, dependencies, and exported packages.
* **ModuleDescriptor**: Describes a module's name, dependencies, exported and opened packages, and other module-level attributes.
* **ModuleLayer**: Represents a layer in the module system's hierarchical structure, containing a set of modules and their dependencies.
* **ModuleFinder**: An interface for locating modules, typically used to discover modules available on the module path or in the classpath.
* **Configuration**: Represents a resolved set of modules and their dependencies, ensuring that all required modules are present and compatible.

Common Use Cases



* **Accessing Module Information:** Developers can use the `Module` class to retrieve information about a module at runtime, such as its name, version, dependencies, and exported packages.
* **Dynamic Module Loading:** The `ModuleLayer` and `ModuleFinder` interfaces can be used to dynamically load modules at runtime, enabling more flexible application architectures.
* **Module Reflection:** The `java.lang.reflect.Module` class provides reflective access to module information, allowing tools and frameworks to introspect modules at runtime.

Example



```java
Module currentModule = getClass().getModule();
System.out.println("Module Name: " + currentModule.getName());

currentModule.getPackages().forEach(System.out::println);

for (ModuleDescriptor.Requires dependency : currentModule.getDescriptor().requires()) {
System.out.println("Requires: " + dependency.name());
}
```

This code snippet demonstrates how to obtain the current module, print its name, list its exported packages, and iterate over its dependencies.

Additional Resources



* Oracle Documentation on `java.lang.module`: [invalid URL removed]
* Baeldung: Java 9 Module API: [https://www.baeldung.com/java-9-module-api](https://www.baeldung.com/java-9-module-api)


Classes to support Java module descriptors and creating configurations of modules by means of resolution and Java service binding.

Java.lang.module Package


The `java.lang.module` package in Java provides classes and interfaces for working with modules, introduced in Java 9 as part of the Java Platform Module System (JPMS). Modules in Java are a way to encapsulate code and resources, define dependencies between components, and enforce access controls at compile time and runtime. Key components of the `java.lang.module` package include **ModuleDescriptor**, which represents a module's descriptor containing metadata such as its name, version, and dependencies; **ModuleFinder**, which provides a way to find modules based on specified criteria; **ModuleReader**, which allows reading resources from a module; and **ModuleLayer**, which represents a layer of modules with a defined configuration and class loading behavior. The `java.lang.module` package is essential for developing modular Java applications, enabling better organization, encapsulation, and dependency management of code and resources. It provides tools and APIs for creating, discovering, and interacting with modules at both compile time and runtime, enhancing the modularity, maintainability, and scalability of Java applications.


" (OCP17SelBoy 2022)

Research More


Java Research:

=Java Best Websites

=
Java Best Websites:
* oreilly>java.lang.module on O'Reilly
* ddg>java.lang.module on DuckDuckGo
* java>java.lang.module on docs.oracle.com
* heinz>java.lang.module on JavaSpecialists.eu
* baeldung>java.lang.module on baeldung.com

=Other JVM Languages and Frameworks

=
JVM Languages:
* kotlin>java.lang.module on kotlinLang.org
* scala>java.lang.module on scala-lang.org
* clojure>java.lang.module on clojureDocs.org
* groovy>java.lang.module on docs.groovy-lang.org

JVM Frameworks:
* android>java.lang.module on developer.android.com
* xda>java.lang.module on xda-developers.com
* spring>java.lang.module on spring.io
* vertx>java.lang.module on vertx.io
* quarkus>java.lang.module on quarkus.io
* graalvm>java.lang.module on graalvm.org

=Maven and Gradle

=
Maven, Maven Central and Gradle
* maven>java.lang.module on search.maven.org
* mavenrepo>java.lang.module on MvnRepository.com
* gradle>java.lang.module on plugins.gradle.org

=Tutorials

=
Java Tutorials:
* javatpoint>java.lang.module on javatpoint.com
* w3schools>java.lang.module on w3schools.com
* tutorialspoint>java.lang.module on tutorialspoint.com
* freecode>java.lang.module on FreeCodeCamp.org

=Java Security - Java Pentesting

=
Java Security - Java Pentesting
* exploit>java.lang.module on exploit-db.com
* cve>java.lang.module on cve.org Database of Common Vulnerabilities and Exposures (CVE)
* threatpost>java.lang.module on threatpost.com
* talos>java.lang.module on TalosIntelligence.com

=General Support

=
* redhat>java.lang.module on developers.redhat.com
* ibm>java.lang.module on IBM.com
* ms>java.lang.module on docs.microsoft.com
* techtarget>java.lang.module on whatis.techtarget.com
* youtube>java.lang.module on YouTube
* github>java.lang.module on GitHub
* reddit>java.lang.module on Reddit
* scholar>java.lang.module on scholar.google.com
* quora>java.lang.module on Quora
* dzone>java.lang.module on DZone
* hackernoon>java.lang.module on Hacker Noon
* infoq>java.lang.module on InfoQ.com
* twitter>java.lang.module on Twitter
* stackoverflow>java.lang.module on StackOverflow



Fair Use Sources


Fair Use Sources:
* ddg>java.lang.module on DuckDuckGo

# B09WJP11JL (OCP17SelBoy 2022)
# B0756P3CZD (JPG4e 2017)
# B09JL8BMK7 (JavaCmpRef 2021)
# B09NS868Y2 (JavBegGd2022)
# B07L3BFG49 (JavNutSh 2018)
# B09782LG72 (ModJvAct 2018)
# B078H61SCH (EffJav 2017)
# B09MW3MW2Z (MoreJ17 2021)
# B09MP5N4MQ (J17Fund 2021)
# B09GXR6SPF (CorJav1 2019)
# B07NCXJR1M (CorJav2 2019)
# 1617298875 (WlGrnJvDv 2022)
# B0B2HPDDGF (Hd1stJav17 2022)
# B071S84XCK (Jav9frPg 2017)
# B09NLQY1NS (Jav17AbsBeg 2021)
# B08651PDL6 (JavCookBk 2020)
# B086L2NYWR (LrnJav] 2020)
# B004V9OA84 (JavCncrPrct 2006)

See Also


* java.lang
** java.lang.annotation
** java.lang.constant
** java.lang.invoke
** java.lang.ref
** java lang reflection | java.lang.reflect


{{navbar_java}}


{{navbar_footer}}