DEV Community

Cover image for Top 5 Java libraries in 2020
Pavel Polívka
Pavel Polívka

Posted on

Top 5 Java libraries in 2020

There are tons of awesome Java libraries. Usually there is more than one library for a concrete thing. More than two or five. Most of the time you cannot go bad by choosing one over the other, sure there might be a string opinion online on why TestNG is miles better than Junit and vice versa but in general both are fine. I worked on a various of projects than used all kinds of different libraries and you get used to everything and everything has its pros and cons.
In this article I want to go over the most standout libraries. Those you will have hard time replacing with something else. Sure you can replace them, but the experience will not be the same.

Project Lombok

Project Lombok is the most awesome tool out of this list. It makes writing Java code fun again. It’s essentially set of annotations that will auto generate a lot of boiler plate Java code for you. Thanks to magic of annotation processing its incredibly light weight and provides no additional runtime dependencies.
Best features are @Getter, @Setter, @Data and @Builder.
The first two are used to auto generate getters and setters. @Data will take barebones class with some variables and generates all the necessary Java boiler plate for all the variables. Getters, Setters, equals, toString you name it. @Builder is basically creating entire Builder pattern class for your entire class.
The whole library is easy to setup and most modern IDEs have great support for it so it will auto generate the stuff for on the fly.

jOOQ

There are tons of libraries designed to retrieve data from SQL databases. Either ORM/JPA or QyeryDSL. The most standout one is jOOQ. It will generate code based on your database and allows you to write type safe SQL queries.
It’s standardize the way you write your SQL queries (same as JPA) but the generated queries are much better. This is thanks it’s more SQL like syntax you will end up retrieving just the data you need. JPA usually downloads tons of other data thanks to various joins in entities.
In the end you just create your database and jOOQ will create all the boilerplate for you, lets you write type safe, effective queries without any unnecessary stuff around it.
JOOQ is a paid library if you are using SQL Server or Oracle.

Apache Lucene

Apache Lucene is ultra-fast search library. It’s the library that is used by Elastic search and or Solr (Solr and Lucene are now one project). It provides best full text searching, faceting, joining, highlighting. It’s lightweight and can be used for almost any search use cases.

Mockito

Mockito is a mocking library. The best mocking library. There is a lot of alternatives but I never liked working with them like I liked working with Mockito. Its api is the most elegant one and definitely most readable one.
Newer versions of Mockito even allow you to mock some static method so that you can finnaly get rid of Power Mockito and Junit 4.

AssertJ

For a long time, I took Hamcrest as the defacto standard for asserting library. Then I discovered AssertJ. It’s basically doing the same thing as Hamcrest but it’s API seems more like API from this century and have the feeling of rest of the code I write. Instead of remembering what is the name of the Matcher is can be autocompleted by the IDE.


You can dm me on Twitter to let me know your favorite libraries.

Top comments (1)

Collapse
 
siy profile image
Sergiy Yevtushenko

If you like lombok, then you might find interesting this one github.com/manifold-systems/manifold