The Top 5 Java Libraries for Maximum Productivity

Alex Power
Javarevisited
Published in
3 min readSep 7, 2020
Photo by Alireza Attari on Unsplash

Do you ever find yourself writing a piece of Java and thinking, “there must be a better way?” Java is such a popular language, there probably is! Here is a consolidated list of a few of the most useful Java libraries I’ve encountered. Using these libraries will increase your productivity and leverage the work someone else has already done!

1) Lombok

Project Lombok is a Java library that uses annotations to reduce boilerplate code. You can use annotations such as @Getter to automatically generate “getField()” methods. Here are a few of the supported annotations:

  1. @Getter and @Setter, which generate Getters and Setters.
  2. @EqualsAndHashCode automatically generates Equals and HashCode methods which adhere to the Equals and HashCode contracts.
  3. @ToString will generate a toString() method which follows the format ClassName(fieldName=value, fieldName2=value…).
  4. @Builder automatically implements the builder pattern for ease of constructing your POJO.
  5. @Data is short-hand for @Getter, @Setter, @EqualsAndHashCode, @ToString, and @RequiredArgsConstructor!

There are many more supported annotations, all of which are highly customizable. Never write boilerplate again!

2) Guava

Guava is a Java library created and maintained by Google that contains many broadly applicable utilities that solve common problems in Java. Some of the features include:

  1. Extensions to Collections, such as Multimap<K, V> which is a Map that supports multiple values for a given key, equivalent to Map<K, Collection<V>> with a cleaner API.
  2. The Graphs package which includes a number of utilities for modelling graph-type data
  3. Concurrency utilities such as MoreExecutors, Atomics, and ListenableFuture

There is so much to dig into in the Guava library. Since it’s maintained by Google and widely used, you can be confident that their APIs have been thoroughly tested and carefully maintained. If you have a common Java problem to solve, Guava probably has a solution!

3) Hibernate

Hibernate is an Object-Relational Mapping library that allows you to interact with you database without having to think about how to translate between SQL Tables and POJOs. From Hibernate’s website:

Hibernate enables you to develop persistent classes following natural Object-oriented idioms including inheritance, polymorphism, association, composition, and the Java collections framework. Hibernate requires no interfaces or base classes for persistent classes and enables any class or data structure to be persistent.

Use Hibernate to supercharge your persistence layer and eliminate thousands of lines of database code.

4) Feign

OpenFeign is a library created by Netflix that enables you to easily create RESTful HTTP Clients in Java. To create a Feign client, you simply declare an interface outlining the request and response details. This is best illustrated via an example:

When used, this interface GitHubClient will execute the GET and POST requests declared on the methods. This client will default to using JSON format for all requests. There are a myriad of customizations for the Feign client:

  1. Encoders and Decoders to choose how the POJOs are serialized and deserialized on the wire
  2. Retryers to specify retry policy and logic
  3. RequestInterceptors for other pre-request tasks such as cookie retrieval or authorization

Use Feign and never write HTTP clients by hand again! Note: if you use Spring, you should use Spring Cloud OpenFeign which has better Spring integrations than OpenFeign on its own.

5) Spring Boot

Last but certainly not least is Spring Boot. Spring Boot streamlines the process of creating production-ready Java applications by:

Create stand-alone Spring applications

Embed Tomcat, Jetty or Undertow directly (no need to deploy WAR files)

Provide opinionated ‘starter’ dependencies to simplify your build configuration

Automatically configure Spring and 3rd party libraries whenever possible

Provide production-ready features such as metrics, health checks, and externalized configuration

There can be a difficult learning curve when using Spring Boot, but I can assure you that the time invested has a huge payoff. Spring Boot has reduced development times across the board on my projects and continues to pay dividends through its stability, extensibility, and readability.

Conclusion

Java may be an older language that lacks some of the features of newer languages, but it has unparalleled library support from the community. There is no shortage of production-ready libraries for you to leverage on your projects. Armed with the knowledge about these libraries, you can become a more productive developer. Don’t re-invent the wheel — focus on your core competence, solving problems.

If you liked this article, please consider clapping and dropping your email below to subscribe to my email list.

--

--

Alex Power
Javarevisited

Consultant with Galatea Assoc. Blogger in Tech, Java, and Spring. Catholic. Dad. https://www.alexpower.me