I’ve used a number of Java open source libraries over the years in a variety of projects. Java developers are lucky to have a long list of community libraries to pull from. Here are a few standouts that have made their way into virtually all of my new development. These were chosen because they have clean interfaces, provide significant value, are well tested, and most of all … help me write less code.
This one is probably at the top of a lot of developer’s lists. Back in my C/C++ days, we had Boost. Early in my Java days, we used Apache Commons. Now, Google Guava is the primary core/utility library for Java. If you ever find yourself writing anything that could be common to the Java language, look here first.
Here are a few classes from Guava that I’m always using:
Use the Optional class instead of using null:
Use the Preconditions class to validate parameters and fail fast:
Pick up any kind of OO textbook and you will see something like “separate interface from implementation”. Got it … create an interface that the callers will use and implement the interface with a concrete class that is abstracted away from the caller. The next part of the problem, which is usually left out of the discussion, is who/what provides the implementation class to the caller. This is where Dependency Injection (DI) comes in.
Take a look at Guice Modules to bind interfaces to implementations:
And the @Singleton, @Inject and @Provides annotations to get started:
Lombok is fairly new to me, but it has quickly became a favorite. Lombok is a set of annotations that are processed at compile time to generate ‘boilerplate’ code. This will result in smaller classes (especially POJO value objects) that are easier to maintain.
Take a look at @Data and stop writing getters, setters, equals(), hashCode(), and toString()
Use @Builder to make your value objects immutable and provide a builder pattern:
Here are a few other projects that didn’t make my top 3 but are definitely worth looking at:
Principal Engineer / Stackify
- Top .NET Developer Skills According to Tech Leaders and Experts - October 20, 2021
- What to Do About Java Memory Leaks: Tools, Fixes, and More - September 3, 2021
- What is Load Testing? How It Works, Tools, Tutorials, and More - February 5, 2021
- Americaneagle.com and ROC Commerce stay ahead with Retrace - September 25, 2020
- Stackify’s New Pricing: Everything you need to know - September 9, 2020