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
- Stackify Named to Constellation ShortList for Digital Performance Management - August 19, 2019
- Stackify founder: Landing on Inc. 5000 brings validation, prompts reflection - August 16, 2019
- Inc. 5000 ranks Matt Watson’s Stackify among top fastest-growing companies in KC - August 15, 2019
- Stackify Joins the Inc. 5000 List of Fastest-Growing Companies - August 14, 2019
- Looking for New Relic Alternatives & Competitors? Learn Why Developers Pick Retrace - May 1, 2019