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
- KC-Based Stackify Is Growing Fast, Hiring Too - December 10, 2019
- Fast-growing Leawood tech company rounds up local investors for $6M raise - December 5, 2019
- More than a podcast host: Matt Watson’s Stackify raises $6M in rapid scaling maneuver - November 25, 2019
- What are Microservices? Code Examples, Best Practices, Tutorials and More - September 13, 2019
- 9 Best Practices to Handle Exceptions in Java - August 22, 2019