Creating a simple modular application
You should be wondering what this modularity is all about, and how to create a modular application in Java. In this recipe, we will try to clear up the confusion around creating modular applications in Java by walking you through a simple example. Our goal is to show you how to create a modular application; hence, we picked a simple example so as to focus on our goal.Â
Our example is a simple advanced calculator, which checks whether a number is prime, calculates the sum of prime numbers, checks whether a number is even, and calculates the sum of even and odd numbers.
Getting ready
We will divide our application into two modules:
- The
math.utilmodule, which contains the APIs for performing the mathematical calculations - The
calculatormodule, which launches an advanced calculator
How to do it...
- Let's implement the APIs in theÂ
com.packt.math.MathUtilclass, starting with theisPrime(Integer number)API:
public static Boolean isPrime(Integer number){
if (...