Ryan Harrison My blog, portfolio and technology related ramblings

30 Useful Java Libraries

A collection of some interesting Java libraries and frameworks (not including the big ones everyone uses such as Spring or JUnit). Hopefully it contains some lesser known libraries which you might not have heard of before and may find useful.

Name Description
ArchUnit Write unit tests to enforce the architecture of your Java code. E.g. all your service classes follow established conventions for naming and package layout through to finding cyclic dependencies.
AssertJ Forget Hamcrest or those provided by JUnit, AssertJ is the only library you will need for writing assertions. Provides countless rich integrations which are easily discoverable through auto-completion.
Awaitility Testing asynchronous systems can be challenging. Awaitility provides a simple DSL that allows you to define the expectations of async operations within tests - without having to deal with threads, timeouts and other concurrency issues.
Caffeine A high performance, near optimal caching library with a modern lambda-based API. Can be easily integrated into Spring applications through its standard caching abstractions.
Eclipse Collections Perhaps not needed in all cases, but can give much improved GC times and overall performance over the standard Java collections in some high throughput pipelines. Also includes immutable versions for better safety in parallel workloads.
Failsafe A lightweight, zero-dependency library for handling all kinds of application failures. Provides a concise API that allows you to wrap executable logic within a number of resilience policies such as Retry, Timeout, Fallback and CircuitBreaker.
FastExcel Apache POI has numerous features for interacting with Excel files, but the API is cumbersome and resource consumption can be a problem for larger files. FastExcel provides a much simpler API to generate and read big Excel files quickly.
Guava Numerous core Java libraries from Google including additional collection types and utilities for concurrency, I/O, hashing, caching and strings. Perhaps becoming less necessary now, but still a great extension over the Java standard library.
Handlebars Simple, logic-less templating engine when you want something a bit more lightweight than Freemarker or Thymeleaf.
HikariCP The best JDBC connection pool out there - fast, simple, reliable and with “zero-overhead”. The default in newer Spring Boot based applications.
Immutables For those that prefer not to use Lombok, but still like all the benefits of immutable classes. Immutables is an annotation processor that generates simple, fast and consistent value objects (data classes) without all the traditional boilerplate.
Faker Generate all kinds of fake data (names, addresses, emails and many more). Really useful when you need to create some throwaway data as part of tests or quick proof-of-concepts/demos.
Jimfs An in-memory file system for Java from Google. Great for unit testing when you don’t want to/can’t mock the underlying filesystem (usually due to static methods from java.nio.Files etc).
Jib Build optimised Docker images from your Java applications directly from Maven/Gradle, without the need for CLI dependencies or Dockerfiles. Jib separates your app into multiple layers (splitting dependencies from classes) for much quicker rebuilds.
jOOR The Java Reflection API is powerful, but often cumbersome to use. jOOR provides a simple, fluent wrapper that gives much more intuitive access to the standard meta information and class structures.
Lombok A set of annotations that helps remove all the typical boilerplate and verbosity in Java applications. Easily auto-generate data classes with constructors, getters/setters, toString, equals/hashcode, builders, loggers and more.
Micrometer A vendor-neutral application metrics facade (think SLF4J, but for metrics). Support for dimensional metrics and Spring Boot Actuator offers a number of useful out-of-the-box integrations.
Mug A small set of utilities over Java 8 Streams and Optionals. Also includes a functional style Maybe implementation.
Picocli A user-friendly framework for building command-line based apps with the JVM. Supports autocompletion, colours, subcommands and is GraalVM compatible.
Resilience4J A lightweight fault tolerance library for Java 8+ and a successor for Netflix Hystrix. Provides decorators for Circuit Breakers, Rate Limiters, Retries and Bulkheads. Can also be used as a circuit breaker implementation within Spring Cloud Circuit Breaker.
Rest Assured A powerful DSL for writing tests over your RESTful API’s.
Retrofit A lightweight and type-safe HTTP client for the JVM. A common go-to within Android applications to interact with external services.
ShedLock A distributed lock that makes sure your scheduled tasks are executed at most once at the same time. Uses an external store like a Redis, JDBC database or Zookeeper for coordination.
StreamEx Many enhancements over the standard Java Stream API that make common tasks shorter and more convenient. Fully compatible with the built-in Java 8 Stream classes, but provides many additional useful methods.
TestContainers Write proper integration tests that use Docker to spin-up throwaway instances of databases, queues, browsers and more. Integrates with JUnit and doesn’t require any extra complex configuration. No longer feel the need to mock out external services!
ThreeTen Extra Additional date-time classes that complement those already in Java 8 (MutableClock, LocalDateRange etc). Curated by the primary author of the new java.time API.
Vavr An essential for all the functional programmers out there. Provides all the essential data types and functional control structures alongside a number of extra modules for integrations with other libraries and frameworks.
Verbal Expressions A library that helps to construct difficult regular expressions with a fluent and human-readable API.
WireMock A library for stubbing and mocking HTTP services. Allows you to construct a standalone local web server that can be used within integration tests to verify expected behaviour against external API’s. Also integrates with Spring Cloud Contract.
Yavi A lambda-based, type-safe validation library with no reflection, annotations or dependencies. For those who are not fans of using the Bean Validation frameworks.

For even more Java libraries check out https://github.com/akullpp/awesome-java