Java Directory

This directory contains Java programs demonstrating various algorithms and data structures. Each file is a self-contained example of a specific algorithm or data structure.

☕ Java Coding Standards

Documentation Requirements

All Java code in this directory must follow these JavaDoc standards:

1. Class-Level JavaDoc

Every class should have comprehensive JavaDoc:

/**
 * ClassName - Brief one-line description
 * 
 * <p>Detailed description of the class purpose, functionality,
 * and any important implementation details.</p>
 * 
 * <h2>Key Features:</h2>
 * <ul>
 *   <li>Feature 1</li>
 *   <li>Feature 2</li>
 * </ul>
 * 
 * @author Your Name
 * @version 1.0
 * @since 2025-10-15
 * 
 * @see RelatedClass
 */
public class ClassName {
    // class implementation
}

2. Method JavaDoc

All public methods must include complete JavaDoc:

/**
 * Brief description of what the method does.
 * 
 * <p>More detailed explanation if needed, including
 * algorithm description and complexity analysis.</p>
 * 
 * @param param1 Description of first parameter
 * @param param2 Description of second parameter
 * @return Description of return value
 * 
 * @throws IllegalArgumentException When param is invalid
 * @throws NullPointerException When param is null
 * 
 * @example
 * <pre>{@code
 * MyClass obj = new MyClass();
 * int result = obj.methodName("test", 5);
 * System.out.println(result); // Output: 10
 * }</pre>
 * 
 * @see #relatedMethod()
 */
public int methodName(String param1, int param2) {
    // implementation
}

3. Field Documentation

Document all class fields:

/** The maximum buffer size in bytes */
private static final int MAX_BUFFER_SIZE = 1024;

/** Current state of the processor */
private ProcessorState state;

4. Code Style (Google Java Style Guide)

// Naming Conventions
public class MyClassName { }          // PascalCase for classes
public void myMethodName() { }        // camelCase for methods
private int myVariableName;           // camelCase for variables
public static final int MAX_SIZE = 100; // UPPER_SNAKE_CASE for constants

// Formatting
public class Example {
    // 4 spaces for indentation (no tabs)
    private int field;
    
    public void method() {
        if (condition) {
            // Opening brace on same line
            doSomething();
        } else {
            doSomethingElse();
        }
    }
}

5. Best Practices

6. Example Pattern

/**
 * DataProcessor - Processes data with various transformations
 * 
 * <p>This class provides methods to process, transform, and validate
 * data according to specified rules.</p>
 * 
 * @author Code-Contribution Community
 * @version 1.0
 */
public class DataProcessor {
    
    /** Maximum number of items to process */
    private static final int MAX_ITEMS = 1000;
    
    /**
     * Processes a list of items.
     * 
     * @param items List of items to process (must not be null)
     * @return Number of successfully processed items
     * @throws IllegalArgumentException if items list is empty
     * @throws NullPointerException if items is null
     */
    public int processItems(List<String> items) {
        if (items == null) {
            throw new NullPointerException("Items cannot be null");
        }
        // implementation
        return 0;
    }
}

List of Programs

🔍 Search Algorithms

  1. BinarySearch.java: Implementation of the binary search algorithm with O(log n) time complexity.
  2. InterpolationSearch.java: Implementation of the interpolation search algorithm, efficient for uniformly distributed data.

📊 Sorting Algorithms

  1. BubbleSort.java: Implementation of the bubble sort algorithm with optimization for early termination.
  2. InsertionSort.java: Implementation of the insertion sort algorithm, efficient for small datasets.
  3. MergeSort.java: Implementation of the merge sort algorithm with O(n log n) guaranteed performance.
  4. QuickSort.java: Implementation of the quicksort algorithm using divide-and-conquer approach.
  5. SelectionSort.java: Implementation of the selection sort algorithm with O(n²) time complexity.
  6. SortColors.java: Implementation of the Dutch National Flag problem for sorting colors.
  7. WiggleSort.java: Implementation of wiggle sort algorithm for alternating array elements.

🧮 Mathematical Algorithms

  1. FibonacciSeries.java: Implementation of Fibonacci number generation using iterative approach.
  2. factorial.java: Implementation of factorial calculation.
  3. ArmstrongNumber.java: Implementation to check if a number is an Armstrong number.
  4. PrimeFactors.java: Implementation to find prime factors of a number.
  5. Pow(x,n).java: Implementation of power function with optimization.

🎯 Array Manipulation

  1. Anagrams.java: Implementation to check if two strings are anagrams.
  2. CheckPalindrome.java: Implementation to check if a string is a palindrome.
  3. Palindrome.java: Alternative implementation for palindrome checking.
  4. Pangram.java: Implementation to check if a string is a pangram.
  5. shufflearray.java: Implementation to shuffle array elements randomly.
  6. SumOfTwoNumbers.java: Implementation to find two numbers that sum to a target.

🔢 Matrix Operations

  1. AlgebraMultiplyMatrices.java: Implementation of matrix multiplication.
  2. PrintDiagonalElements.java: Implementation to print diagonal elements of a matrix.
  3. ReverseMatrix.java: Implementation to reverse matrix elements.
  4. rotate180.java: Implementation to rotate matrix by 180 degrees.
  5. Rotate90.java: Implementation to rotate matrix by 90 degrees.
  6. SpiralOrderMatrix.java: Implementation to print matrix in spiral order.

🌊 Advanced Algorithms

  1. KadanesAlgorithm.java: Implementation of Kadane’s algorithm for maximum subarray sum.
  2. Krushkal'sAlgorithm.java: Implementation of Kruskal’s algorithm for minimum spanning tree.
  3. primsAlgorithm.java: Implementation of Prim’s algorithm for minimum spanning tree.
  4. SudokuSolver.java: Implementation of Sudoku puzzle solver using backtracking.
  5. TrappedWater.java: Implementation to calculate trapped rainwater.
  6. Trapping_rainwater.java: Alternative implementation for trapped rainwater problem.

🎮 Interactive Programs

  1. GuessNumber.java: Interactive number guessing game.
  2. HelloWorld.java: A simple program that prints “Hello World!”.
  3. Largest.java: Implementation to find the largest number in an array.
  4. Main.java: Main class for program execution.
  5. Star.java: Implementation to print star patterns.
  6. String_atoi.java: Implementation of string to integer conversion (atoi function).

How to Run

To run any of the Java programs in this directory, follow these steps:

  1. Open a terminal or command prompt.
  2. Navigate to the directory containing the Java file you want to run.
  3. Compile the Java file using the javac command. For example, to compile HelloWorld.java, run:
    javac HelloWorld.java
    
  4. Run the compiled Java program using the java command. For example, to run HelloWorld, run:
    java HelloWorld
    

Contribution Guidelines

If you would like to contribute to this directory, please follow these guidelines:

  1. Ensure your code is well-documented and follows the coding standards.
  2. Add a brief description of your program in this README.md file.
  3. Ensure your program is placed in the correct directory.
  4. Test your program thoroughly before submitting a pull request.

Thank you for your contributions!