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
- Immutability: Prefer
finalfor variables that don’t change - Exception Handling: Use specific exceptions, document with
@throws - Null Safety: Check for null, document when nulls are allowed
- Generics: Use type parameters for type safety
- Resource Management: Use try-with-resources for AutoCloseable
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
BinarySearch.java: Implementation of the binary search algorithm with O(log n) time complexity.InterpolationSearch.java: Implementation of the interpolation search algorithm, efficient for uniformly distributed data.
📊 Sorting Algorithms
BubbleSort.java: Implementation of the bubble sort algorithm with optimization for early termination.InsertionSort.java: Implementation of the insertion sort algorithm, efficient for small datasets.MergeSort.java: Implementation of the merge sort algorithm with O(n log n) guaranteed performance.QuickSort.java: Implementation of the quicksort algorithm using divide-and-conquer approach.SelectionSort.java: Implementation of the selection sort algorithm with O(n²) time complexity.SortColors.java: Implementation of the Dutch National Flag problem for sorting colors.WiggleSort.java: Implementation of wiggle sort algorithm for alternating array elements.
🧮 Mathematical Algorithms
FibonacciSeries.java: Implementation of Fibonacci number generation using iterative approach.factorial.java: Implementation of factorial calculation.ArmstrongNumber.java: Implementation to check if a number is an Armstrong number.PrimeFactors.java: Implementation to find prime factors of a number.Pow(x,n).java: Implementation of power function with optimization.
🎯 Array Manipulation
Anagrams.java: Implementation to check if two strings are anagrams.CheckPalindrome.java: Implementation to check if a string is a palindrome.Palindrome.java: Alternative implementation for palindrome checking.Pangram.java: Implementation to check if a string is a pangram.shufflearray.java: Implementation to shuffle array elements randomly.SumOfTwoNumbers.java: Implementation to find two numbers that sum to a target.
🔢 Matrix Operations
AlgebraMultiplyMatrices.java: Implementation of matrix multiplication.PrintDiagonalElements.java: Implementation to print diagonal elements of a matrix.ReverseMatrix.java: Implementation to reverse matrix elements.rotate180.java: Implementation to rotate matrix by 180 degrees.Rotate90.java: Implementation to rotate matrix by 90 degrees.SpiralOrderMatrix.java: Implementation to print matrix in spiral order.
🌊 Advanced Algorithms
KadanesAlgorithm.java: Implementation of Kadane’s algorithm for maximum subarray sum.Krushkal'sAlgorithm.java: Implementation of Kruskal’s algorithm for minimum spanning tree.primsAlgorithm.java: Implementation of Prim’s algorithm for minimum spanning tree.SudokuSolver.java: Implementation of Sudoku puzzle solver using backtracking.TrappedWater.java: Implementation to calculate trapped rainwater.Trapping_rainwater.java: Alternative implementation for trapped rainwater problem.
🎮 Interactive Programs
GuessNumber.java: Interactive number guessing game.HelloWorld.java: A simple program that prints “Hello World!”.Largest.java: Implementation to find the largest number in an array.Main.java: Main class for program execution.Star.java: Implementation to print star patterns.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:
- Open a terminal or command prompt.
- Navigate to the directory containing the Java file you want to run.
- Compile the Java file using the
javaccommand. For example, to compileHelloWorld.java, run:javac HelloWorld.java - Run the compiled Java program using the
javacommand. For example, to runHelloWorld, run:java HelloWorld
Contribution Guidelines
If you would like to contribute to this directory, please follow these guidelines:
- Ensure your code is well-documented and follows the coding standards.
- Add a brief description of your program in this
README.mdfile. - Ensure your program is placed in the correct directory.
- Test your program thoroughly before submitting a pull request.
Thank you for your contributions!