A comprehensive collection of Java programming exercises focused on Object-Oriented Programming (OOP) principles and Design Patterns. This repository contains practical implementations of various design patterns and demonstrates core OOP concepts like interfaces, inheritance, polymorphism, and abstraction.
This repository serves as a learning resource for mastering Java programming with a focus on:
- Object-Oriented Programming principles
- Design Pattern implementations
- Interface-based design
- Inheritance and Polymorphism
- Code organization and best practices
- Java: Core programming language
- IDE: IntelliJ IDEA (project files included)
- Build System: Standard Java compilation
- Java Development Kit (JDK) 8 or higher
- IntelliJ IDEA (recommended) or any Java IDE
- Basic understanding of Java and OOP concepts
JavaExercises/
├── Assignment1/ # Interfaces, Inheritance, and Polymorphism
├── Assingment2/ # Factory/Strategy Pattern
├── Assignment3/ # Abstract Factory Pattern
├── Assignment4/ # (In Development)
├── Assignment5/ # State Pattern
├── .gitignore # Git ignore configuration
└── README.md # This file
Concepts: Interface implementation, Inheritance, Downcasting, Polymorphism
This assignment demonstrates the power of interfaces in Java through a flight-tracking system. Multiple entities (Birds, Drones, Satellites, UFOs, etc.) implement various interfaces based on their capabilities.
Key Interfaces:
IFlightEnabled- For entities that can flyITrackable- For entities that can be trackedINavigable- For navigation capabilitiesIAutopilot- For autonomous controlICameraEnabled- For image captureISensorEquipped- For sensor-equipped entitiesIOrbitEarth- For orbiting objects- And more...
Classes Implemented:
- Animal hierarchy (Bird, Bee, Dolphin)
- Aircraft (Jet, Drone, ReconDrone, Glider)
- Space objects (Satellite, SpaceProbe, AlienShip, UFO)
- Vehicles (Truck, SelfDrivingCar, AutonomousBoat)
- Special entities (Missile, WeatherBalloon, DragonFly)
Concepts: Factory Pattern, Strategy Pattern, Dependency Injection
A pizza ordering system demonstrating the Factory pattern where different types of pizzas (Italian, Spanish, Senegalese) are created and served by chefs.
Implementation:
Chef- Factory class that creates pizzasPizza- Abstract pizza classPizzaItalian,PizzaSpanish,PizzaSenegal- Concrete pizza implementationsIPizzaPizza- Pizza interface
Concepts: Abstract Factory Pattern, Product Families
A vehicle manufacturing system demonstrating the Abstract Factory pattern with two brands (Mercedes and Volvo) and two vehicle types (Car and Truck).
Implementation:
AbstractFactory- Main factory interfaceCarFactory,TruckFactory- Concrete factory implementationsMercedes,Volvo- Abstract product classesMercedesCar,MercedesTruck,VolvoCar,VolvoTruck- Concrete products
Currently under development. Check back for updates.
Concepts: State Pattern, Behavioral Design Patterns
Demonstrates the State pattern through a Lion's mood system. The assignment includes both "before" and "after" implementations to show the improvement gained by using the State pattern.
Implementation:
- Before: Direct state management within the Lion class
- After: Clean separation using state objects
Lion- Context classIState- State interfaceHungry,NotHungry,Angry- Concrete state implementations
The lion changes states interactively based on user input, demonstrating how the State pattern encapsulates state-specific behavior.
-
Clone the repository:
git clone https://github.com/JavaProjects25/JavaExercises.git cd JavaExercises -
Open the project in IntelliJ IDEA:
- File → Open → Select the JavaExercises directory
-
Navigate to any assignment folder (e.g., Assignment1)
-
Locate the
Main.javafile in thesrcdirectory -
Right-click on
Main.javaand select "Run Main.main()"
-
Navigate to the assignment directory:
cd Assignment1/JavaClass\ -\ Assignment01/src
-
Compile the Java files:
javac *.java -
Run the Main class:
java Main
- Assignment 1: Run
Main.javainAssignment1/JavaClass - Assignment01/src/ - Assignment 2: Run
Main.javainAssingment2/src/ - Assignment 3: Run
Main.javainAssignment3/src/ - Assignment 5:
- Before State: Run
Main.javainAssignment5/src/BeforeState/ - After State: Run
Main.javainAssignment5/src/AfterState/(interactive)
- Before State: Run
By working through these assignments, you will learn:
-
Interface-Based Design
- Creating and implementing multiple interfaces
- Understanding interface segregation
- Working with polymorphism through interfaces
-
Design Patterns
- Factory Pattern: Creating objects without specifying exact classes
- Abstract Factory Pattern: Creating families of related objects
- State Pattern: Changing object behavior based on internal state
-
OOP Principles
- Encapsulation: Hiding internal details
- Inheritance: Building class hierarchies
- Polymorphism: One interface, multiple implementations
- Abstraction: Working with abstract concepts
-
Best Practices
- Code organization and structure
- Separation of concerns
- Clean code principles
- Design pattern application
- Each assignment is self-contained and can be run independently
- Diagram files (
.drawio) are included for visual representation of patterns - The project uses IntelliJ IDEA project structure (
.imlfiles)
This is a learning repository. Feel free to:
- Report issues or bugs
- Suggest improvements
- Add more design pattern examples
- Enhance documentation
This project is for educational purposes.
Happy Learning! 🚀