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
- Better code, Better results: No BS [Webinar] - December 20, 2018
- New Feature in Retrace: Application Scoring - May 24, 2018
- What’s New in Retrace: Java on Windows Support Now Available - March 20, 2018
- SST Software Fixes Problems behind the Scenes with Retrace - February 1, 2018
- Retrace Platform Major Update: Alerts and Notifications - January 24, 2018