Home » Java (page 20)

Java

Annotation Handling and JPMS

TLDR; Instead of annotation.getClass().getMethod("value") call annotation.annotationType().getMethod("value"). All Java developers have heard about annotations. Annotations are with us since Java 1.5 (or only 1.6 if you insist). Based on my experience interviewing candidates I feel that most Java developers know how to use annotations. I mean, most developers know that it looks like @Test, or @Override and that they come with ...

Read More »

Faster Java Startup with Checkpoint Restore at Main

The Java Virtual Machine provides a managed runtime environment for applications that have been compiled into bytecodes (but may not have necessarily been written in Java).  This offers numerous benefits to application developers and, often, improved performance over code statically compiled for a specific platform.  The JVM handles memory allocation and recovery automatically via the garbage collector (GC), reducing the ...

Read More »

Kogito, ergo Rules — Part 1: Bringing Drools Further

The Kogito initiative is our pledge to bring our business automation suite to the cloud and the larger Kubernetes ecosystem. But what does this mean for our beloved rule engine, Drools? In this post we introduce modular rule bases using rule units: a feature that has been experimental for a while in Drools 7, but that will be instrumental for ...

Read More »

Enhanced CDI contexts & bulkheads with MicroProfile Context Propagation

java-interview-questions-answers

When using CDI with asynchronous execution methods, such as a ManagedExecutorService, it’s traditionally not possible to access all of CDI’s scopes that were active in the originating thread. MicroProfile Context Propagation enables to define and pass thread execution contexts to completion stages where our code can access various CDI contexts despite being executed asynchronously. Additionally, Context Propagation allows to create ...

Read More »

Chicken and egg – resolving Spring properties ahead of a test

spring-interview-questions-answers

Consider a service class responsible for making a remote call and retrieving a detail: 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 ... public class CitiesService {     private final WebClient.Builder webClientBuilder;     private final String baseUrl;       public CitiesService(             WebClient.Builder webClientBuilder,             @Value("${cityservice.url}") String baseUrl) {         this.webClientBuilder = webClientBuilder;         this.baseUrl = baseUrl;     } ...

Read More »

JDBC – Emulating a sequence

Probably each of us encountered this problem at least once in the programmer’s life – how to emulate a database sequence? Below you may find my variation of this problem’s solution. Suppose that we have an interface defining the desired API for returning a sequence of integer numbers: 1 2 3 4 5 public interface Sequences {       int nextValue(String ...

Read More »