Java 9モジュール

Java 9モジュールは、Javaの構造における最大の変更の一つです。ここでは、「Java 9モジュールシステム」について簡潔な高レベルの紹介を行います。

Java 9のモジュールシステム

私たちはJava 9のモジュールシステムについて、次のトピックを調査します。

    1. はじめに

 

    1. Java SE 9: Jigsaw プロジェクト

 

    1. 現行の Java システムの問題点は?

 

    1. Java SE 9 モジュールシステムの利点

 

    1. JDK 8 と JDK 9 の比較

 

    1. Java 9 モジュールとは何か?

 

    1. Java 9 モジュールシステムの基盤

 

    Java 8 と Java 9 のアプリケーションの比較

はじめに

オラクル社は、Java 9のリリースを2017年3月から2017年9月に延期しました。私たちが知っているように、Java SE 8は3つの大きな新機能(さらにいくつかの改善と新機能も含む)と共にリリースされました。

    1. ラムダ式

 

    1. ストリームAPI

 

    日付API

同様に、Java SE 9も3つの大きな機能を備えています(さらにいくつかの改善や新機能も追加)。

    1. Javaモジュールシステム(Jigsawプロジェクト)

 

    1. Java REPL

 

    MillingプロジェクトCoin

この投稿では、Oracle Jigsaw プロジェクトの基礎について話し合います。

Java SE 9:ジグソープロジェクト

ジグソープロジェクトは、完全に新しいコンセプトであるJava SE 9のJavaモジュールシステムを導入する予定です。これはOracle Corpの非常に大きく名誉あるプロジェクトです。最初はJava SE 7リリースの一環として始められましたが、大きな変更があり、それがJava SE 8に延期され、さらに延期されました。今では、2017年9月にJava SE 9でリリースされる予定です。ジグソープロジェクトの主な目標は以下の通りです:

  • The Modular JDK
    As we know, Current JDK system is too big. So they have decided to divide JDK itself into small modules to get a number of benefits (We will discuss them soon in the coming sections).- Modular Source Code
    Current source code jar files are too big, especially rt.jar is too big right. So they are going to divide Java Source code into smaller modules.- Modular Run-Time Images
    The main goal of this Feature is “Restructure the JDK and JRE run-time images to accommodate modules”.- Encapsulate Most Internal APIs
    The main goal of this feature is “Make most of the JDK’s internal APIs inaccessible by default but leave a few critical, widely-used internal APIs accessible”.- Java Platform Module System
    The main goal of this Feature is “Allowing the user to create their modules to develop their applications”.- jlink: The Java Linker
    The main goal of this jlink Tool is “Allowing the user to create executable to their applications”.

これらのことがよく理解できなければ、心配しないでください。次のセクションや私の次の投稿でも、これらの概念を詳しく説明し、役立つ例も示します。

現行のJavaシステムの問題は何でしょうか? (Gyōkō no Java shisutemu no mondai wa nan deshō ka?)

このセクションでは、「なぜ私たちはJava SE 9モジュールシステムが必要なのか」ということについて、現行のJavaシステムの問題を取り上げます。Java SE 8以前のシステムでは、Javaベースのアプリケーションの開発や配信に以下の問題があります。

  • As JDK is too big, it is a bit tough to scale down to small devices. Java SE 8 has introduced 3 types of compact profiles to solve this problem: compact1, compact2, and compact3. But it does not solve this problem.
  • JAR files like rt.jar etc are too big to use in small devices and applications.
  • As JDK is too big, our applications or devices are not able to support better Performance.
  • There is no Strong Encapsulation in the current Java System because “public” access modifier is too open. Everyone can access it.
  • As JDK, JRE is too big, it is hard to Test and Maintain applications.
  • As the public is too open, They are not to avoid the accessing of some Internal Non-Critical APIs like sun.*, *.internal.* etc.
  • As User can access Internal APIs too, Security is also big issue.
  • Application is too big.
  • Its a bit tough to support Less Coupling between components.

これらの問題を解決するため、オラクル株式会社はJava SE 9リリースでJavaモジュールシステムをリリースする予定です。

Java SE 9モジュールシステムの利点

Java SE 9のモジュールシステムは以下の利点を提供します。

  • As Java SE 9 is going to divide JDK, JRE, JARs etc, into smaller modules, we can use whatever modules we want. So it is very easy to scale down the Java Application to Small devices.
  • Ease of Testing and Maintainability.
  • Supports better Performance.
  • As public is not just public, it supports very Strong Encapsulation. (Don’t worry its a big concept. we will explore it with some useful examples soon).
  • We cannot access Internal Non-Critical APIs anymore.
  • Modules can hide unwanted and internal details very safely, we can get better Security.
  • Application is too small because we can use only what ever modules we want.
  • Its easy to support Less Coupling between components.
  • Its easy to support Single Responsibility Principle (SRP).

私たちはこれらの概念を近いうちに一つずつ探求します。

JDK 8とJDK 9を比較してみる。

jmods folder, java modules

Java 9では、モジュールとは何ですか?

java 9 modules system

Java 9 のモジュールシステムの母

現在、Java 9モジュールシステムは、アーリーアクセスJDKに95個のモジュールを持っています。オラクル社は、JDKのjarファイルとJava SEの仕様を2つのモジュールセットに分割しました。

  • All JDK Modules starts with “jdk.*”
  • All Java SE Specifications Modules starts with “java.*”

Java9のモジュールシステムには、「java.base」というモジュールがあります。これはベースモジュールとして知られています。これは独立したモジュールであり、他のどのモジュールにも依存しません。デフォルトでは、他のすべてのモジュールがこのモジュールに依存しています。そのため、「java.base」モジュールはJava9モジュールの母としても知られています。これはすべてのJDKモジュールとユーザー定義モジュールのデフォルトモジュールです。

Java 8とJava 9のアプリケーションを比較してください。

java 9 application module system
  • One Module
  • Module Name
  • Module Descriptor
  • Set of Packages
  • Set of Types and Resources

リソースはmodule-info.java(モジュールデスクリプタ)またはその他のプロパティやXMLのいずれかです。この投稿では理論について多く議論しました。Java 9のモジュールシステムの基礎を理解するには十分だと思います。次の投稿で基本的なモジュールの開発を始めます。必要に応じて、さらに理論的な概念やJava 9のモジュールシステム用語について話し合います。以上が「Java 9のモジュールシステム入門」の内容です。次の投稿で、さらにJava SE 9モジュールシステムの概念について話し合います。もし私の投稿が気に入ったり、問題や提案、タイプエラーがある場合はコメントを残してください。チュートリアルをお読みいただきありがとうございました。Java SE 9の学習を楽しんでください!参考:Project Jigsaw

コメントを残す 0

Your email address will not be published. Required fields are marked *