Welcome to your Java learning journey! This Maven project is designed to help you learn Java data structures and process flow through Test-Driven Development (TDD).
- Understand Java syntax and object-oriented programming
- Learn fundamental data structures (ArrayList, Stack)
- Practice control flow (loops, conditionals, recursion)
- Master exception handling
- Get comfortable with unit testing in Java
src/
├── main/java/com/learnjava/
│ ├── Main.java # Your original code (moved here)
│ ├── MyArrayList.java # Custom ArrayList implementation
│ ├── MyStack.java # Custom Stack implementation
│ ├── Calculator.java # Calculator with math algorithms
│ ├── StringAlgorithms.java # Classic string algorithms
│ └── DataStructuresDemo.java # Maps, Sets, and advanced collections
└── test/java/com/learnjava/
├── MyArrayListTest.java # Tests for MyArrayList (12 tests)
├── MyStackTest.java # Tests for MyStack (10 tests)
├── CalculatorTest.java # Tests for Calculator (19 tests)
├── StringAlgorithmsTest.java # Tests for StringAlgorithms (13 tests)
└── DataStructuresDemoTest.java # Tests for DataStructuresDemo (12 tests)
- Java 11 or higher
- Maven 3.6 or higher
-
Run all tests:
mvn test -
Run a specific test class:
mvn test -Dtest=MyArrayListTest mvn test -Dtest=MyStackTest mvn test -Dtest=CalculatorTest
-
Run a specific test method:
mvn test -Dtest=CalculatorTest#shouldAddTwoNumbers
Start with MyArrayList.java - implement the methods to make all tests in MyArrayListTest.java pass.
Key Concepts:
- Generics (
<T>) - ArrayList operations
- Exception handling
- Method implementation
Move to MyStack.java - implement stack operations to make MyStackTest.java pass.
Key Concepts:
- Stack (LIFO - Last In, First Out)
- Exception handling for edge cases
- Search algorithms
Implement Calculator.java to make CalculatorTest.java pass.
Key Concepts:
- Basic arithmetic operations
- Recursion (factorial, GCD)
- Iteration (Fibonacci)
- List processing (max, average)
- Prime number checking
- Perfect numbers
- Number base conversion
- Array algorithms
Implement StringAlgorithms.java to make StringAlgorithmsTest.java pass.
Key Concepts:
- Palindrome checking
- Anagram detection
- String reversal
- Character frequency counting
- String compression
- Pattern matching
Finally, implement DataStructuresDemo.java to make DataStructuresDemoTest.java pass.
Key Concepts:
- HashMap operations (Java's dictionary)
- HashSet operations (unique collections)
- Character/word frequency counting
- Set operations (union, intersection)
- Map sorting and grouping
- Cache implementation
public class MyArrayList<T> {
// T can be any type: String, Integer, etc.
}if (condition) {
throw new IllegalArgumentException("Error message");
}for (Type item : collection) {
// Process each item
}public long factorial(int n) {
if (n <= 1) return 1;
return n * factorial(n - 1);
}This project follows TDD principles:
- Red: Tests fail initially (methods return default values)
- Green: Implement methods to make tests pass
- Refactor: Improve your code while keeping tests green
- Start Small: Implement one method at a time
- Read Test Names: They tell you exactly what to implement
- Use IDE: IntelliJ IDEA or VS Code with Java extensions
- Debug: Use breakpoints to understand how your code works
- Ask Questions: Don't hesitate to ask for help!
# Compile the project
mvn compile
# Run tests and see what fails
mvn test
# Run tests with more verbose output
mvn test -Dtest=MyArrayListTest -DforkCount=0
# Clean and compile
mvn clean compileYou'll know you're successful when:
- All tests pass (
mvn testshows green) - You understand each method you implemented
- You can explain the difference between ArrayList and Stack
- You can write your own simple tests
After completing this project:
- Try implementing other data structures (LinkedList, Queue, HashMap)
- Learn about Java Collections Framework
- Explore more advanced topics (Streams, Lambda expressions)
- Build a small application using what you've learned
Happy coding! 🚀