Home » Archives for Michael Scharhag

Author Archives: Michael Scharhag

Michael Scharhag is a Java Developer, Blogger and technology enthusiast. Particularly interested in Java related technologies including Java EE, Spring, Groovy and Grails.

HTTP – Content negotiation

java-interview-questions-answers

With HTTP, resources are identified using URIs. And a uniquely identified resource might support multiple resource representations. A representation is a specific form of a particular resource. For example: a HTML page /index.html might be available in different languagesproduct data located at /products/123 can be served in JSON, XML or CSVan avatar image /user/avatar might available in JPEG, PNG and ...

Read More »

Avoid leaking domain logic

Many software architectures try to separate domain logic from other parts of the application. To follow this practice we always need to know what actually is domain logic and what is not. Unfortunately this is not always that easy to separate. If we get this decision wrong, domain logic can easily leak into other components and layers. We will go ...

Read More »

From layers to onions and hexagons

java-interview-questions-answers

In this post we will explore the transition from a classic layered software architecture to a hexagonal architecture. The hexagonal architecture (also called ports and adapters architecture) is a design pattern to create loosely coupled application components. This post was inspired by a German article from Silas Graffy called Von Schichten zu Ringen – Hexagonale Architekturen erklärt. Classic layers Layering ...

Read More »

File down – and uploads in RESTful web services

java-interview-questions-answers

Usually we use standard data exchange formats like JSON or XML with REST web services. However, many REST services have at least some operations that can be hard to fulfill with just JSON or XML. Examples are uploads of product images, data imports using uploaded CSV files or generation of downloadable PDF reports. In this post we focus on those ...

Read More »

Kotlin: Type conversion with adapters

In this post we will learn how we can use Kotlin extension functions to provide a simple and elegant type conversion mechanism. Maybe you have used Apache Sling before. In this case, you are probably familiar with Slings usage of adapters. We will implement a very similar approach in Kotlin. Creating an extension function With Kotlins extension functions we can ...

Read More »

Making POST and PATCH requests idempotent

java-interview-questions-answers

In an earlier post about idempotency and safety of HTTP methods we learned that idempotency is a positive API feature. It helps making an API more fault-tolerant as a client can safely retry a request in case of connection problems. The HTTP specification defines GET, HEAD, OPTIONS, TRACE, PUT and DELETE methods as idempotent. From these methods GET, PUT and ...

Read More »

Providing useful API error messages with Spring Boot

spring-interview-questions-answers

For API users it is quite important an API provides useful error messages. Otherwise, it can be hard to figure out why things do not work. Debugging what’s wrong can quickly become a larger effort for the client than actually implementing useful error responses on the server side. This is especially true if clients are not able to solve the ...

Read More »

Supporting bulk operations in REST APIs

java-interview-questions-answers

Bulk (or batch) operations are used to perform an action on more than one resource in single request. This can help reduce networking overhead. For network performance it is usually better to make fewer requests instead of more requests with less data. However, before adding support for bulk operations you should think twice if this feature is really needed. Often ...

Read More »

Looking into the JDK 16 vector API

JDK 16 comes with the incubator module jdk.incubator.vector (JEP 338) which provides a portable API for expressing vector computations. In this post we will have a quick look at this new API. Note that the API is in incubator status and likely to change in future releases. Why vector operations? When supported by the underlying hardware vector operations can increase ...

Read More »