Java libraries you can’t miss in 2017


Thank you for reading this post, don't forget to subscribe!

This blog post is heavily inspired by this presentation by Andres Almiray.

This was so good, that I needed to groom it as the reference list. Sharing it with short feature lists and examples.



Guice (pronounced ‘juice’) is a lightweight dependency injection framework for Java 6 and above, brought to you by Google.

# Typical dependency injection  public class DatabaseTransactionLogProvider implements Provider<TransactionLog> {    @Inject Connection connection;      public TransactionLog get() {      return new DatabaseTransactionLog(connection);    }  }  
# FactoryModuleBuilder generates factory using your interface  public interface PaymentFactory {     Payment create(Date startDate, Money amount);   }  

GitHub, JavaDoc, User guide, FactoryModuleBuilder


HTTP is the way modern applications network. It’s how we exchange data & media. Doing HTTP efficiently makes your stuff load faster and saves bandwidth.

OkHttp is an HTTP client that’s efficient by default:

  • HTTP/2 support allows all requests to the same host to share a socket.
  • Connection pooling reduces request latency (if HTTP/2 isn’t available).
  • Transparent GZIP shrinks download sizes.
  • Response caching avoids the network completely for repeat requests.
OkHttpClient client = new OkHttpClient();    String run(String url) throws IOException {    Request request = new Request.Builder()        .url(url)        .build();      Response response = client.newCall(request).execute();    return response.body().string();  }  

GitHub, Website


Type-safe HTTP client for Android and Java by Square, Inc. Retrofit turns your HTTP API into a Java interface.

Retrofit turns your HTTP API into a Java interface.

public interface GitHubService {      @GET("users/{user}/repos")      Call<List<Repo>listRepos(@Path("user") String user);  }  

The Retrofit class generates an implementation of the GitHubService interface.

Retrofit retrofit = new Retrofit.Builder()      .baseUrl("")      .build();     GitHubService service = retrofit.create(GitHubService.class);  

Each Call from the created GitHubService can make a synchronous or asynchronous HTTP request to the remote webserver.

Call<List<Repo>> repos = service.listRepos("octocat");  

GitHub, Website


Java Deferred/Promise library similar to JQuery

  • Deferred object and Promise
  • Promise callbacks: .then(…), .done(…), .fail(…), .progress(…), .always(…)
  • Multiple promises – .when(p1, p2, p3, …).then(…)
  • Callable and Runnable – wrappers.when(new Runnable() {…})
  • Uses Executor Service
  • Java Generics support: Deferred<Integer, Exception, Doubledeferred;, deferred.resolve(10);, deferred.reject(new Exception());,deferred.notify(0.80);,
  • Android Support
  • Java 8 Lambda friendly

GitHub, Website


RxJava – Reactive Extensions for the JVM – a library for composing asynchronous and event-based programs using observable sequences for the Java VM.

It extends the observer pattern to support sequences of data/events and adds operators that allow you to compose sequences together declaratively while abstracting away concerns about things like low-level threading, synchronization, thread-safety and concurrent data structures.

One of the common use cases for RxJava is to run some computation, network request on a background thread and show the results (or error) on the UI thread:

 Flowable.fromCallable(() -{       Thread.sleep(1000); //  imitate expensive computation       return "Done";   })     .subscribeOn(     .observeOn(Schedulers.single())     .subscribe(System.out::println, Throwable::printStackTrace);      Thread.sleep(2000); // <--- wait for the flow to finish  

GitHub, Wiki

Read Full Article

Leave a Reply

Your email address will not be published. Required fields are marked *