Java Code Style Guide for DSA Examples
Java Code Style Guide
This guide explains how to write clean and beginner-friendly Java code for DSA examples.
The main goal is to keep Java solutions simple, readable, and easy to understand for students and new contributors.
Why This Guide Is Needed
DSA examples are easier to learn when the code follows one clean style.
This guide helps contributors with:
- Clear class and method names
- Meaningful variable names
- Proper formatting
- Useful comments
- Time and space complexity
- Input and output examples
- Edge case handling
1. Class Naming
Use PascalCase for class names.
Class names should clearly describe the algorithm or data structure.
Good
public class BinarySearch {
}
public class MergeSort {
}
Avoid
public class binarysearch {
}
public class mergesortexample {
}
2. Method Naming
Use camelCase for method names.
Method names should describe what the method does.
Good
public static int binarySearch(int[] arr, int target) {
return -1;
}
public static void mergeSort(int[] arr, int left, int right) {
}