Three Favorite Open Source Java Libraries

java-libraries

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.

 

google-guava  Google Guava

https://github.com/google/guava

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:

https://github.com/google/guava/wiki/UsingAndAvoidingNullExplained

Use the Preconditions class to validate parameters and fail fast:

https://github.com/google/guava/wiki/PreconditionsExplained

 

google-guice  Google Guice

https://github.com/google/guice

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:

https://github.com/google/guice/wiki/LinkedBindings

And the @Singleton, @Inject and @Provides annotations to get started:

https://github.com/google/guice/wiki/Scopes

https://github.com/google/guice/wiki/Injections

https://github.com/google/guice/wiki/ProvidesMethods

 

lombok  Lombok

https://projectlombok.org/

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()

https://projectlombok.org/features/Data.html

Use @Builder to make your value objects immutable and provide a builder pattern:

https://projectlombok.org/features/Builder.html

 

Honorable Mentions

Here are a few other projects that didn’t make my top 3 but are definitely worth looking at:

SLF4J

http://www.slf4j.org/

Joda-Time

http://www.joda.org/joda-time/

Jackson JSON Processor

http://wiki.fasterxml.com/JacksonHome

 

Eric-2

Eric Martin

Principal Engineer / Stackify