Modular Programming in Java 9
上QQ阅读APP看书,第一时间看更新

Traditional Java code structure

Traditionally, writing a Java application starts with creating one or more source directories. These are special directories that serve two purposes--firstly, they act as root locations of your Java source code and secondly, the contents of these directories are added to the class path. So, the steps to organize source code have typically been:

  1. Create one or more source folders.
  2. In a source folder, create package folders to mirror the package name.
  3. Place the .java files in the right package folders:

Many Java developers use the directory structure src/main/java for the source directory. So, for example, a class Main.java in the package com.acme.app would have the overall path src/main/java/com/acme/app/Main.java:

 

This is how source code in Java has typically been organized by developers for many years now. With Java 9 modules, there's a change in the way we approach structuring and writing code. Let's switch gears and examine what a module in Java 9 looks like.