Skip to content

Iamdachi/java-homework1

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 

Repository files navigation

welcometojava

Project demonstrating compilation, running, and creating an executable JAR of a simple Java program.

Learning about classes

This project also demonstrates different types of classes:

  1. Inner Class

    • Example: NotificationSystem.EmailNotification
    • Tied to an instance of the outer class, can access its fields.
  2. Static Nested Class

    • Example: NotificationSystem.SMSNotification
    • Works independently of the outer class instance.
  3. Anonymous Class

    • Example: custom comparator in handleSorting method
    • Allows inline, one-off behavior without creating a separate class.
  4. Local Class

    • Example: PaymentProcessor.processPayment() -> Receipt
    • Defined inside a method, used only within that method.

Dependencies

Project Structure

src/
└── welcometojava/
    ├── MatrixUtils.java
    ├── WelcomeMain.java
    ├── NotificationSystem.java
    └── PaymentProcessor.java
lib/
└── commons-math3-3.6.1.jar

Java version

openjdk 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)

Install Dependencies

Make a directory /lib in the project root:

cd /path/to/project/root
mkdir lib
cd lib

Install 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

Compilation and execution of bytecode

  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

  1. Execute the bytecode
java -cp "out:lib/commons-math3-3.6.1.jar" welcometojava.WelcomeMain

out - contains compiled .class files

lib/commons-math3-3.6.1.jar - the external library

welcometojava.WelcomeMain - fully qualified class name of the main class

Building an Executable JAR

  1. Move to the project root:
cd /path/to/project/root
  1. Create manifest.txt in the project root with the content:
Main-Class: welcometojava.WelcomeMain
  1. 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/

  1. 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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages