JAVA9 Modular Jigsaw Introductory Guide __java

Source: Internet
Author: User

JAVA9 official version is about to be released, here I first introduced under the Java9 of the specific what is going on.


Compared to Java, in fact, JS Domain is very early in the modular. Gossip is less of a drag. Today we'll see how the JAVA9 is modular.

Students familiar with Java know that before Java (1--->8), the use of a large jar file Rt.jar this jar package in Java8 has more than 60 m. and we need to tools.jar this jar when our Java code is running, This jar is also not small.

There are also more than 10 m. These two files are the minimum required environment to run a Java program. This means that running a HelloWorld Java program also requires the introduction of a dozens of M jar.

If it's in the Java EE environment. Then things will become more complicated.




Modularity can make javase programs lighter and easier to deploy.


The module is the code and the data package, the code refers to a packages, is before we write a package. And a module is a collection of one or more packages.

Here we can look at the Java modular configuration file.


Module Module1 {
    //indirectly refers to the java.sql modules
    requires transitive java.sql;
    Exports org.huluo.module1;
}

The above configuration file only exports one package Org.huluo.module1

This means that the class under the Org.huluo.module1 package of the module can be referenced. Classes in other packages under the module cannot be referenced even if they are public-decorated classes or other modules. This topic will be described later.

The above configuration file does three things, defines the module Module1, indirectly references the java.sql module and exports the Org.huluo.module1 package.


Also, in JAVA9, the public access modifier no longer means that it can be accessed.

The relationship between modules is called readability (readability), which represents whether a module can find the module file and reads it into the system (note: It is not representative of the type that can be accessed). In the actual code, one type for the invocation of another type, which we call Accessibility (Accessible), means that this type can be used; The premise of accessibility is readability, in other words, the existing module is readable, and then further detection of accessibility (security).





Introducing what is a transitive reference to a module (indirect reference)

When our Module 2 References Module 1, module 1 references the java.sql module. In fact, Module 2 does not refer to the java.sql module.

But if we declare Module 1 's reference to be an indirect reference to the Java.sql module, Module 2 can refer to the java.sql module.

This is a bit similar to Maven's dependency transfer.


Here is the demo project: http://download.csdn.net/download/u013803262/9972059

Reference from: http://www.jianshu.com/p/053a5ca89bbb

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.