Create New Module System in Java 9


Using Eclipse Oxygen and JDK 9

The steps below show how to create a new module

module com.operators {

	exports com.operators;

}

package com.operators;

public class Operators {

	public int add(int a, int b) {
		return a + b;
	}

	public int sub(int a, int b) {
		return a - b;
	}

	public int mul(int a, int b) {
		return a * b;
	}

}




package com.operators;

public class Main {

	public static void main(String[] args) {

	}

}

Right click on project and go to Run As > Java Application

The steps below show how to test calculator module

module com.demo {

	requires com.operators;

}




package com.demo;

import com.operators.Operators;

public class Main {

	public static void main(String[] args) {

		Operators operators = new Operators();
		System.out.println("Add: " + operators.add(10, 2));
		System.out.println("Sub: " + operators.sub(10, 2));
		System.out.println("Sub: " + operators.mul(10, 2));

	}

}
Add: 12
Sub: 8
Mul: 20