Java Language Modules

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Syntax

  • requires java.xml;
  • requires public java.xml; # exposes module to dependents for use
  • exports com.example.foo; # dependents can use public types in this package
  • exports com.example.foo.impl to com.example.bar; # restrict usage to a module

Remarks

The use of modules is encouraged but not required, this allows existing code to continue working in Java 9. It also allows for a gradual transition to modular code.

Any non-modular code is put in an unnamed module when it is compiled. This is a special module that is able to use types from all other modules but only from packages which have an exports declaration.

All packages in the unnamed module are exported automatically.

Keywords, e.g. module etc..., are restricted in use within the module declaration but can be continue to be used as identifiers elsewhere.



Got any Java Language Question?