30 Seconds of Java is a snippet collection, and its value depends on how the snippets are tested
Collection of reusable tested Java 21 compatible code snippets that you can understand in 30 seconds or less.
At a glance
- What is it?
- A library of short, Java 21 compatible code samples organised by topic, from binary search to Luhn mod N, published alongside the same author's design patterns book site. It is a reading and copy-paste resource, and the interesting question is what the test setup actually guarantees.
- Who is it for?
- Adopt 30 Seconds of Java as a reference to read and to lift from when you want the plainest possible version of an algorithm, and as a source of examples that compile under Java 21. Do not adopt it as a library dependency, because it is a set of standalone snippets rather than a published artifact with an API you can call.
- Can I use it commercially?
- Yes. MIT is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
- Is it still maintained?
- Yes. The repository last received commits 40 days ago.
- What is it written in?
- Mainly Java, according to GitHub's language statistics.
Answers come from the project's GitHub data, last synced on October 22, 2026, and from our analysis. They are not legal advice.
Editorial analysis
The organising idea is one class per snippet, named after itself
The project is described as a collection of reusable, tested and copy-pasteable Java 21 compatible code snippets that you can understand in 30 seconds or less, and it is inspired by the 30 seconds of code project. The description also frames it as a library for implementing design patterns effectively, with ready-to-use examples aimed at improving coding and design skills.
The structure is visible in every example. Each snippet is a single public class whose name is the concept plus the word Snippet, such as `BinarySearchSnippet`, `BubbleSortSnippet`, `CountingSortSnippet`, `CycleSortSnippet`, `InsertionSortSnippet`, `LinearSearchSnippet` and `LuhnModnSnippet`. The methods are static, so nothing has to be instantiated to try them.
The naming convention is the documentation. `BinarySearchIn2dArraySnippet` tells you at a glance that it is the two dimensional variant, and `LuhnModnSnippet` tells you it is the Luhn mod N variant rather than the plain mod 10 checksum. Someone skimming a file listing knows what they are looking at without opening anything.
The topics list groups the repository as an awesome list, a snippets collection and a snippets library, and the code-level metadata for the project is a Gradle build with `build.gradle`, `settings.gradle`, `gradle.properties`, the wrapper scripts and a `src/` directory. There is also a `localization/` directory and a `bin/` directory, plus `AGENTS.md` and a `CONTRIBUTE.md` at the root.
The homepage is the snippets page of the same author's design patterns site, which tells you the intended relationship. The snippets are a companion to a book of design pattern explanations, and the value proposition is reading code that demonstrates an idea rather than a dependency you install.
The style is deliberately plain, and that is the point
Look at what a snippet does not contain. `BubbleSortSnippet` has no null check on the array, no bounds validation, no generic type parameter, and returns void while mutating the input in place.
public static void bubbleSort(int[] arr) {
var lastIndex = arr.length - 1;
for (var j = 0; j < lastIndex; j++) {
for (var i = 0; i < lastIndex - j; i++) {
if (arr[i] > arr[i + 1]) {
var tmp = arr[i];
arr[i] = arr[i + 1];
arr[i + 1] = tmp;
}
}
}
}The Javadoc says only that it sorts an array with the bubbleSort algorithm. There is no note about stability, complexity, or what happens with an empty array.
That is a defensible choice for a snippet library whose stated goal is comprehension in thirty seconds, and it is also the thing to be careful about when you copy. An insertion sort snippet that shifts elements to make room is the correct algorithm and is not a hardened library method, and the difference shows up in production rather than in a tutorial.
The `var` usage is a modern touch that fits the Java 21 target, and the algorithms themselves are written recursively in a couple of cases, such as `binarySearch` recursing into half the range, which is the classic textbook form rather than the iterative one. That is fine for reading and for understanding the divide, and it is not what you would ship on a hot path.
The comment style is consistent across the collection, with a Javadoc block that names the algorithm, describes the parameters and states the return contract, including the failure value. The `binarySearch` snippet documents that it returns the index position of the array item if found and otherwise returns -1, and the two dimensional variants document that they return {-1,-1} when the location is not found. The contract is stated even when the implementation is short, and that is what makes the collection usable as a reference.
Counting sort and cycle sort show the range assumptions
Two of the snippets illustrate the range of algorithms in the collection, and each carries an assumption that the Javadoc states or implies.
`CountingSortSnippet` sorts an array of zero or positive numbers. It finds the maximum with a stream, allocates a count array of size max plus one, accumulates the counts, converts them to prefix sums, then places each element back counting down from the end, and finally copies the sorted values back into the original array. The assumption is in the first line of the Javadoc, that the numbers are zero or positive, because a negative value would index the count array out of bounds. It also mutates the input rather than returning a new array, which is a difference from `BinarySearchSnippet`.
`CycleSortSnippet` returns the same array it mutates in place, and its Javadoc says it sorts an array with the cycleSort algorithm. The implementation computes the correct position for each element as the value minus one, so it assumes a permutation of the integers from 1 to n. It also has no explicit guard for a value of zero, which would produce an index of minus one.
These are not bugs so much as the ordinary consequence of writing an algorithm in its textbook form. The point for a reader is that the Javadoc tells you the precondition and the return contract, and that is where you should read before lifting the code into something that has to survive a null, a negative or an empty input.
`BinarySearchIn2dArraySnippet` is the most intricate of the group, and its structure is a different kind of lesson. It assumes the matrix is sorted, as the Javadoc says, and it splits the search by first narrowing the row range around the middle column, then recursing into the relevant quadrant of that row, calling a helper `binarySearch` that does the ordinary in-row binary search between a start and end column. The helper returns {-1,-1} on failure and the outer method returns the row and column when found. It is a genuinely instructive piece of code, and it is also the snippet most likely to need a second look before you trust it with a non square matrix.
Luhn mod N generalises the checksum people already know
The `LuhnModnSnippet` class is the one that goes beyond a sorting algorithm, and it is a good illustration of how a snippet can encode a specification rather than just an algorithm.
It holds a constant of code points, the digits followed by the uppercase letters, and the Javadoc says it generates a check character using the Luhn mod N algorithm, taking an input string of valid alphanumeric characters and returning the generated check character, throwing an IllegalArgumentException if the input contains something invalid.
The value of a mod N checksum over the familiar mod 10 version is that it works over an alphabet larger than ten. A serial number checked with Luhn mod 36 can use letters, and the check character is one of the code points in the constant rather than a single digit, so the check does not reduce the space of valid values.
That makes this snippet a different kind of artefact from the sorting ones. The sorting snippets implement well known procedures that many people can already write. This one implements a specific rule, with an explicit alphabet and an explicit error case, and the snippet is the clearest statement of that rule available without reading the specification.
For a reader who is building a validator, the snippet is a starting point that has to be read closely, because the interesting decisions, which characters are valid, whether the check character is appended or substituted, and how the case of letters is handled, are exactly the parts a short snippet leaves as an exercise.
A Gradle project, a contribution guide and an active but quiet history
The repository is a Gradle project with the wrapper checked in, `build.gradle`, `settings.gradle`, `gradle.properties` and a `gradle/` directory, which means the collection is compiled as part of the build rather than being a folder of loose files. That is the mechanism behind the word tested in the description.
The project also has `CONTRIBUTE.md` as the documented path for adding to the library, and the README links to it for anyone interested in contributing. An `AGENTS.md` at the root indicates the project has written down conventions for AI coding assistants.
The metadata points elsewhere for context. The `localization/` directory suggests the snippets are documented in more than one language, and the `bin/` directory holds scripts. The homepage being a page on the author's design patterns site is a strong hint about the audience: people reading about patterns who want a working implementation next to the explanation.
On maintenance, the last push was on 2026-09-13, the repository is not archived, and there are no GitHub releases, which is consistent with a collection that grows by pull request rather than by versioned releases. The topic list includes hacktoberfest, which explains the shape of the contribution history, and it also means a large share of the snippets are likely first contributions from people who needed one particular algorithm rather than a curated syllabus.
The licence is MIT. For a collection of algorithm implementations, that is a reasonable and simple choice, and it means a snippet can be lifted into a commercial codebase without attribution obligations beyond the notice, though the licence file is the authoritative text.
Editorial conclusion
Adopt 30 Seconds of Java as a reference to read and to lift from when you want the plainest possible version of an algorithm, and as a source of examples that compile under Java 21. Do not adopt it as a library dependency, because it is a set of standalone snippets rather than a published artifact with an API you can call. Verify first that the snippet you copy handles the edge cases your input has, since the examples favour brevity over defensive checks, and that the class name and file name match the convention the project expects if you contribute one back.
Frequently asked questions
What is the 30 Seconds of Java repository?
It is a collection of reusable, tested, copy-pasteable Java 21 compatible code snippets that you can understand in 30 seconds or less, inspired by the 30 seconds of code project. The homepage is the snippets page of the same author's design patterns site.
How are the snippets organised and named?
Each snippet is a single public class whose name is the concept followed by Snippet, such as BinarySearchSnippet, CountingSortSnippet and LuhnModnSnippet, with static methods and a Javadoc block stating the parameters and the return contract. A two dimensional variant is named with an In2dArray suffix.
Which algorithms are covered in the collection?
The README opens with an Algorithm section including binary search in a one and two dimensional array, linear search in a one and two dimensional array, and the bubble, counting, cycle and insertion sorts, alongside a Luhn mod N check character generator.
Do the snippets handle edge cases like null or empty input?
They are written in the plain textbook form, so the preconditions live in the Javadoc rather than in defensive checks. Counting sort states it expects zero or positive numbers, and the search snippets return -1 or {-1,-1} when the item is not found, but the code does not validate null or empty inputs.
How do I contribute a snippet to 30 Seconds of Java?
The README points to CONTRIBUTE.md for the contribution guidelines. The repository also carries an AGENTS.md describing conventions, and the topic list includes hacktoberfest, so contributions arrive as pull requests against a Gradle project with a compiled test suite.
Official sources
Add this badge to your README
If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.
[](https://hysenlabs.com/projects/iluwatar-30-seconds-of-java)Was this useful?