David Vlijmincx | Senior software developer

I am a Senior developer, Public speaker, Java blogger, and Author

Read a file from resources directory

There comes a time when you need to read a file from the resource folder of your project. You could have a file you want to read in the src/main/resources or src/test/resources directory. In this tutorial, I am going to show you how to read a file from your production or testing code. Using NIO files The most straightforward way to read a file is to the files belonging to the NIO (New Input/Output) package.

Create a Thread with Runnable in Java

This post will teach you how to implement a thread in three different ways, all of which rely on the Runnable interface. You will learn that using the Runnable interface is the most flexible way to create multi-threaded code in Java. Implementing Runnable interface with a class The easiest way to create a Runnable to run in a thread. It to create a class that implements the Runnable interface. The Runnable interface only has a single method void run();, Because of this it is called a functional interface.

Extending the Thread class in Java

Introduction Using Java, there are two ways to implement a thread. You can implement the Runnable interface, or you can extend the Thread class. In this tutorial, we will delve into the latter approach of extending the Thread class to create threads. Extending the thread class Extending the Thread class is done by adding extends Thread after the class name. By extending the Thread class you can override the run method from this class.

Future with Virtual threads

Introduction We are gonna look at how to use virtual threads with a future. Doing this requires only a couple lines of code. A future makes it is easy to return a value from a (virtual) thread. Future with a virtual thread Creating a future from a virtual thread is done by using the newVirtualThreadPerTaskExecutor. Since Java 21 the ExecutorService now implements the autocloseable interface which means that we can use it with the try-with-resource statement.

CompletableFuture with Virtual threads

Introduction In this post, we look at how to use virtual threads with compatible futures. While it is possible to combine virtual threads and CompletableFuture I also want to show you an alternative way of writing your code. Using CompletableFuture with Virtual Threads The easiest way to use virtual threads with CompletableFuture is to pass an ExecutorService as a second parameter to the supplyAsync or runAsync method. In the following example, on lines 2 and 3 you can see the executorService being created and used for the execution of the CompletableFuture.

Helidon quickstart with an IDE

Introduction Helidon is a collection of libraries for writing microservices. It fully supports GraalVM, Jakarta EE, and Microprofile. While the quickstart on the Helidon site already tells you how to create a project, I wanted to offer you a few great alternatives. This tutorial will look at creating a Helidon project using the online starter and IntelliJ. I will also cover how to create a run profile for your project, so you don't have to use the command line every time.