Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
What is the use of the "export" clause in a module-info file in Java 9?
A Module is a combination of both code and data that has a name, declares dependencies on other modules, exports packages that contain the public types that can be accessible outside this module and specifies the services it uses or the service implementations it provides. All of these have specified in a module-info.java file, which is included in the root directory of a module.
There are two types of "export" clause can be used in "module-info.java" file.
1) export
We need to allow other modules to use the classes and interfaces of the package tp.com.tutorialspoint.model, we can write as below:
<strong>module com.tutorialspoint.model {
exports tp.com.tutorialspoint.model;
}</strong>
It's very important to understand that a package can only be present in only one module. Otherwise, we will get an error as below:
<strong>Error:(1, 1) java: package exists in another module:</strong>
2) export
<strong>module com.tutorialspoint.model {
exports tp.com.tutorialspoint.model
to com.tutorialspoint.gui;
}</strong> 