A Java geek
  • Me
  • Books
  • Speaking
  • Mentions
  • Focus
  • Newsletters

serviceloader

A collection of 3 posts
Making ServiceLoader usable: a provider factory
Java

Making ServiceLoader usable: a provider factory

I keep coming back to java.util.ServiceLoader. I have used it to put a JSON layer behind a contract, so the core code carries no direct dependency on any particular JSON library, and I can swap the implementation without touching callers. The same shape works for JWT handling, where the concrete library might be jose4j or another JOSE implementation, and you can easily find other decoupling use-cases.

Jul 12, 2026
Migrating the ServiceLoader to the Java 9 module system
Java

Migrating the ServiceLoader to the Java 9 module system

A long long (long?) time ago, I wrote a post about the ServiceLoader. In short, the Service Loader allows to separate an API and its implementations in different JARs. The client code depends on the API only, while at runtime, the implementation(s) that is (are) on the classpath will be used. This is great way to decouple the client code from the implementing one.

Oct 13, 2019
Java

Simplest Java decoupling without 3rd party frameworks

[…​] coupling (or dependency) is the degree to which each program module relies on each one of the other modules. — Wikipedia http://en.wikipedia.org/wiki/Coupling_(computer_science) In object-oriented programming, removing dependencies is done by using interface. Thus, if class A is dependent on class B, we introduce interface C, which is implemented by B. Now A depends on C  (see below). This first step in decoupling is called programming by interface.

Mar 20, 2009
A Java geek © 2008-2026
v. de3e6256577cb3cdbb9539190b458d4bba3c5668/15862753853
Latest Posts