Project demonstrating compilation, running, and creating an executable JAR of a simple Java program.
This project also demonstrates different types of classes:
-
Inner Class
- Example:
NotificationSystem.EmailNotification - Tied to an instance of the outer class, can access its fields.
- Example:
-
Static Nested Class
- Example:
NotificationSystem.SMSNotification - Works independently of the outer class instance.
- Example:
-
Anonymous Class
- Example: custom comparator in
handleSortingmethod - Allows inline, one-off behavior without creating a separate class.
- Example: custom comparator in
-
Local Class
- Example:
PaymentProcessor.processPayment()->Receipt - Defined inside a method, used only within that method.
- Example:
- Java 25
- commons-math3-3.6.1.jar (Download link)
src/
└── welcometojava/
├── MatrixUtils.java
├── WelcomeMain.java
├── NotificationSystem.java
└── PaymentProcessor.java
lib/
└── commons-math3-3.6.1.jaropenjdk 25 2025-09-16
OpenJDK Runtime Environment (build 25+36-Ubuntu-124.04.2)
OpenJDK 64-Bit Server VM (build 25+36-Ubuntu-124.04.2, mixed mode, sharing)Make a directory /lib in the project root:
cd /path/to/project/root
mkdir lib
cd libInstall the dependency in the /lib directory:
curl -O https://dlcdn.apache.org/commons/math/binaries/commons-math3-3.6.1-bin.zip
unzip commons-math3-3.6.1-bin.zip
rm commons-math3-3.6.1-bin.zip
mv commons-math3-3.6.1/commons-math3-3.6.1.jar .
rm -r commons-math3-3.6.1- Move to the project root and create the bytecode from the source code.
cd /path/to/project/root
javac -cp lib/commons-math3-3.6.1.jar -d out src/welcometojava/*.java-cp lib/commons-math3-3.6.1.jar - include external Commons Math library
-d out - put compiled .class files in out/
src/welcometojava/*.java - compile all source files in that package
- Execute the bytecode
java -cp "out:lib/commons-math3-3.6.1.jar" welcometojava.WelcomeMainout - contains compiled .class files
lib/commons-math3-3.6.1.jar - the external library
welcometojava.WelcomeMain - fully qualified class name of the main class
- Move to the project root:
cd /path/to/project/root- Create manifest.txt in the project root with the content:
Main-Class: welcometojava.WelcomeMain- Build JAR:
jar cfm WelcomeApp.jar manifest.txt -C out .c - create a new JAR
f - specify file name (WelcomeApp.jar)
m - include manifest (manifest.txt)
-C out . - include all compiled .class files from out/
- Run the JAR:
java -cp "WelcomeApp.jar:lib/commons-math3-3.6.1.jar" welcometojava.WelcomeMain-cp - sets the classpath for JVM
WelcomeApp.jar - your compiled program
lib/commons-math3-3.6.1.jar - external Commons Math library
welcometojava.WelcomeMain - fully qualified main class