eBook – Guide Spring Cloud – NPI EA (cat=Spring Cloud)
announcement - icon

Let's get started with a Microservice Architecture with Spring Cloud:

>> Join Pro and download the eBook

eBook – Mockito – NPI EA (tag = Mockito)
announcement - icon

Mocking is an essential part of unit testing, and the Mockito library makes it easy to write clean and intuitive unit tests for your Java code.

Get started with mocking and improve your application tests using our Mockito guide:

Download the eBook

eBook – Java Concurrency – NPI EA (cat=Java Concurrency)
announcement - icon

Handling concurrency in an application can be a tricky process with many potential pitfalls. A solid grasp of the fundamentals will go a long way to help minimize these issues.

Get started with understanding multi-threaded applications with our Java Concurrency guide:

>> Download the eBook

eBook – Reactive – NPI EA (cat=Reactive)
announcement - icon

Spring 5 added support for reactive programming with the Spring WebFlux module, which has been improved upon ever since. Get started with the Reactor project basics and reactive programming in Spring Boot:

>> Join Pro and download the eBook

eBook – Java Streams – NPI EA (cat=Java Streams)
announcement - icon

Since its introduction in Java 8, the Stream API has become a staple of Java development. The basic operations like iterating, filtering, mapping sequences of elements are deceptively simple to use.

But these can also be overused and fall into some common pitfalls.

To get a better understanding on how Streams work and how to combine them with other language features, check out our guide to Java Streams:

>> Join Pro and download the eBook

eBook – Jackson – NPI EA (cat=Jackson)
announcement - icon

Do JSON right with Jackson

Download the E-book

eBook – HTTP Client – NPI EA (cat=Http Client-Side)
announcement - icon

Get the most out of the Apache HTTP Client

Download the E-book

eBook – Maven – NPI EA (cat = Maven)
announcement - icon

Get Started with Apache Maven:

Download the E-book

eBook – Persistence – NPI EA (cat=Persistence)
announcement - icon

Working on getting your persistence layer right with Spring?

Explore the eBook

eBook – RwS – NPI EA (cat=Spring MVC)
announcement - icon

Building a REST API with Spring?

Download the E-book

Course – LS – NPI EA (cat=Jackson)
announcement - icon

Get started with Spring and Spring Boot, through the Learn Spring course:

>> LEARN SPRING
Course – RWSB – NPI EA (cat=REST)
announcement - icon

Explore Spring Boot 3 and Spring 6 in-depth through building a full REST API with the framework:

>> The New “REST With Spring Boot”

Course – LSS – NPI EA (cat=Spring Security)
announcement - icon

Yes, Spring Security can be complex, from the more advanced functionality within the Core to the deep OAuth support in the framework.

I built the security material as two full courses - Core and OAuth, to get practical with these more complex scenarios. We explore when and how to use each feature and code through it on the backing project.

You can explore the course here:

>> Learn Spring Security

Course – LSD – NPI EA (tag=Spring Data JPA)
announcement - icon

Spring Data JPA is a great way to handle the complexity of JPA with the powerful simplicity of Spring Boot.

Get started with Spring Data JPA through the guided reference course:

>> CHECK OUT THE COURSE

Partner – Moderne – NPI EA (cat=Spring Boot)
announcement - icon

Refactor Java code safely — and automatically — with OpenRewrite.

Refactoring big codebases by hand is slow, risky, and easy to put off. That’s where OpenRewrite comes in. The open-source framework for large-scale, automated code transformations helps teams modernize safely and consistently.

Each month, the creators and maintainers of OpenRewrite at Moderne run live, hands-on training sessions — one for newcomers and one for experienced users. You’ll see how recipes work, how to apply them across projects, and how to modernize code with confidence.

Join the next session, bring your questions, and learn how to automate the kind of work that usually eats your sprint time.

Course – LJB – NPI EA (cat = Core Java)
announcement - icon

Code your way through and build up a solid, practical foundation of Java:

>> Learn Java Basics

Partner – LambdaTest – NPI EA (cat= Testing)
announcement - icon

Distributed systems often come with complex challenges such as service-to-service communication, state management, asynchronous messaging, security, and more.

Dapr (Distributed Application Runtime) provides a set of APIs and building blocks to address these challenges, abstracting away infrastructure so we can focus on business logic.

In this tutorial, we'll focus on Dapr's pub/sub API for message brokering. Using its Spring Boot integration, we'll simplify the creation of a loosely coupled, portable, and easily testable pub/sub messaging system:

>> Flexible Pub/Sub Messaging With Spring Boot and Dapr

1. Overview

Machine learning is essential in modern software development. We build models with various architectures, train them using different algorithms, and achieve incredible results by improving our systems with neural networks.

In this tutorial, we’ll explore the H2O platform. It helps us create, train, and tune models in a straightforward way.

2. Install the Open Source h2o Platform

We can download h2o from its website. From the destination folder, we can start our h2o platform:

java -jar h2o.jar

After the application is started, we’re able to reach the web console on http://localhost:54321:

h2o assistance menu

On the main page, we see a list of actions available in the H2O platform. We can also show this list using the menu bar. Let’s go to the top menu and select Assist Me under the Help option.

3. Prepare the Dataset

Before we start working with the platform, we need to prepare a dataset for our model training.

We’re going to solve one of the standard classification problems in machine learning. The popular dataset for this challenge is called iris.

In this dataset, we have different types of flowers with their properties. Let’s download it in the CSV format. In our dataset file we should see the following information:

"sepal.length","sepal.width","petal.length","petal.width","variety"
5.1,3.5,1.4,.2,"Setosa"
4.9,3,1.4,.2,"Setosa"
4.7,3.2,1.3,.2,"Setosa"
...
5.8,2.7,3.9,1.2,"Versicolor"
6,2.7,5.1,1.6,"Versicolor"
5.4,3,4.5,1.5,"Versicolor"
...
6.5,3,5.2,2,"Virginica"
6.2,3.4,5.4,2.3,"Virginica"
5.9,3,5.1,1.8,"Virginica"

Here we have an iris flower’s characteristics and the name for the flower that matches to specific set of characteristics.

4. Train the Model

Let’s train the model using the prepared dataset.

4.1. Import Dataset

In the web console, we load our prepared dataset. We need to use the importFiles option. In the top menu, let’s select Import Files under the Data option. Then we select the folder with our dataset, search the files, and press the Import button:

h2o importFiles function

4.2. Prepare Training and Test Datasets

After our dataset is uploaded, we can use getFrames function. In the top menu, let’s select List All Frames under the Data option. Then, we press the Parse button:

h2o getFrames function

In the output of this operation, we can see the dataset columns descriptions and a few rows with examples.

To follow standard machine learning practices and prepare data for our model, we need to split the dataset into training and testing parts. We’ll use the splitFrame function. In the top menu let’s select Split Frame under the Data option. Now, let’s apply a common 80/20 ratio for training and testing:

h2o splitFrame function

4.3. Build the Model

Now, let’s build the model. In the top menu let’s select the Model option. We’ll use the Random Forest algorithm, which works well for classification problems:

h2o buildModel function

We need to specify training_frame, validation_frame, and response_column to make the model training process possible. There are many other properties we can modify to achieve better results, depending on the selected algorithm. After all the properties are configured, we press the Build Model button:

h2o buildModel function continuation

4.4. Auto ML Function

Another great feature in H2O is AutoML. In the top menu let’s select Run AutoML under the Model option. If we don’t know which exact algorithm we want to use, we can choose this function. Here we need to specify the same parameters as during the general build process. Additionally, we set the max_runtime_secs we want the platform to train all the models. During this time, the AutoML mechanism will be training the models. The higher the value we set, the more accurately the best model will be determined:

h2o runAutoML function

When we finish the model training process, we can see the leaderboard of all the models. From this list, we can choose a suitable trained model we want to use:

h2o runAutoML function leaderboard

4.5. Download the Model

When we build the model, we can download the necessary artifacts. The Download Gen Model button lets us download a JAR archive with the required classes for Java applications:

h2o getModel function downloadGenModel

We use the Download Model Deployment Package (MOJO) button to download the model itself:

h2o getModel function downloadMojo

5. Use the Model Predictions From Java Application

Now, let’s use our model in a Java application.

5.1. Add the h2o Archives

Let’s add the archives we downloaded from the H2O console into the libs folder inside our application project. Now, we can add it to the classpath.

5.2. Dependencies

Let’s add our model dependency:

<dependency>
    <groupId>ai.h2o</groupId>
    <artifactId>h2o-genmodel</artifactId>
    <version>1.0</version>
    <scope>system</scope>
    <systemPath>${project.basedir}/libs/h2o-genmodel.jar</systemPath>
</dependency>

We specify the path to our model archive. The groupId and artifactId are predefined in the H2O.

5.3. Use the Manually Built Model for Prediction

Now, let’s see how we can use our model in Java code:

public class H2OModelLiveTest {

    Logger logger = LoggerFactory.getLogger(H2OModelLiveTest.class);

    @Test
    public void givenH2OTrainedModel_whenPredictTheIrisByFeatures_thenExpectedFlowerShouldBeReturned() throws IOException, PredictException {
        String mojoFilePath = "libs/mojo.zip";

        MojoModel mojoModel = MojoModel.load(mojoFilePath);
        EasyPredictModelWrapper model = new EasyPredictModelWrapper(mojoModel);

        RowData row = new RowData();
        row.put("sepal.length", 5.1);
        row.put("sepal.width", 3.4);
        row.put("petal.length", 4.6);
        row.put("petal.width", 1.2);

        MultinomialModelPrediction prediction = model.predictMultinomial(row);

        Assertions.assertEquals("Versicolor", prediction.label);

        logger.info("Class probabilities: ");
        for (int i = 0; i < prediction.classProbabilities.length; i++) {
            logger.info("Class " + i + ": " + prediction.classProbabilities[i]);
        }
    }
}

We create a MojoModel from our MOJO archive and wrap it with the EasyPredictModelWrapper class. Next, we prepare a row with the flower criteria we want to classify. Then, we use the predictMultinomial() method to get the predictions. As we can see, this set of properties is classified as Versicolor. Additionally, we print all the output parameters.

The output shows that our classification is accurate with a probability of 0.9597, which is good enough for us:

19:33:48.648 [main] INFO  com.baeldung.h2o.H2OModelLiveTest - Class probabilities: 
19:33:48.653 [main] INFO  com.baeldung.h2o.H2OModelLiveTest - Class 0: 0.016846955011789237
19:33:48.653 [main] INFO  com.baeldung.h2o.H2OModelLiveTest - Class 1: 0.9597659357519948
19:33:48.653 [main] INFO  com.baeldung.h2o.H2OModelLiveTest - Class 2: 0.023387109236216036

5.4. Use the AutoML Model for Prediction

Now, let’s run the prediction using the best model proposed by the AutoML H2O function:

@Test
public void givenH2OTrainedAutoMLModel_whenPredictTheIrisByFeatures_thenExpectedFlowerShouldBeReturned() throws IOException, PredictException {
    String mojoFilePath = "libs/automl_model.zip";

    MojoModel mojoModel = MojoModel.load(mojoFilePath);
    EasyPredictModelWrapper model = new EasyPredictModelWrapper(mojoModel);

    RowData row = new RowData();
    row.put("sepal.length", 5.1);
    row.put("sepal.width", 3.4);introduction-to-
    row.put("petal.length", 4.6);
    row.put("petal.width", 1.2);

    MultinomialModelPrediction prediction = model.predictMultinomial(row);

    Assertions.assertEquals("Versicolor", prediction.label);

    logger.info("Class probabilities: ");
    for (int i = 0; i < prediction.classProbabilities.length; i++) {
        logger.info("Class " + i + ": " + prediction.classProbabilities[i]);
    }
}

As we can see, this model also completed the classification successfully with the same result. However, the probability is lower in this case:

20:28:06.440 [main] INFO  com.baeldung.h2o.H2OModelLiveTest - Class probabilities: 
20:28:06.443 [main] INFO  com.baeldung.h2o.H2OModelLiveTest - Class 0: 0.08536296008169375
20:28:06.443 [main] INFO  com.baeldung.h2o.H2OModelLiveTest - Class 1: 0.8451806663486182
20:28:06.443 [main] INFO  com.baeldung.h2o.H2OModelLiveTest - Class 2: 0.06945637356968806

6. Conclusion

In this article, we explored the H2O platform. Using this tool, we can train neural networks and prepare artifacts for Java applications. This is helpful when we want to avoid diving deep into the mainstream ML stack, which requires Python knowledge and additional libraries.

The code backing this article is available on GitHub. Once you're logged in as a Baeldung Pro Member, start learning and coding on the project.
Baeldung Pro – NPI EA (cat = Baeldung)
announcement - icon

Baeldung Pro comes with both absolutely No-Ads as well as finally with Dark Mode, for a clean learning experience:

>> Explore a clean Baeldung

Once the early-adopter seats are all used, the price will go up and stay at $33/year.

eBook – HTTP Client – NPI EA (cat=HTTP Client-Side)
announcement - icon

The Apache HTTP Client is a very robust library, suitable for both simple and advanced use cases when testing HTTP endpoints. Check out our guide covering basic request and response handling, as well as security, cookies, timeouts, and more:

>> Download the eBook

eBook – Java Concurrency – NPI EA (cat=Java Concurrency)
announcement - icon

Handling concurrency in an application can be a tricky process with many potential pitfalls. A solid grasp of the fundamentals will go a long way to help minimize these issues.

Get started with understanding multi-threaded applications with our Java Concurrency guide:

>> Download the eBook

eBook – Java Streams – NPI EA (cat=Java Streams)
announcement - icon

Since its introduction in Java 8, the Stream API has become a staple of Java development. The basic operations like iterating, filtering, mapping sequences of elements are deceptively simple to use.

But these can also be overused and fall into some common pitfalls.

To get a better understanding on how Streams work and how to combine them with other language features, check out our guide to Java Streams:

>> Join Pro and download the eBook

eBook – Persistence – NPI EA (cat=Persistence)
announcement - icon

Working on getting your persistence layer right with Spring?

Explore the eBook

Course – LS – NPI EA (cat=REST)

announcement - icon

Get started with Spring Boot and with core Spring, through the Learn Spring course:

>> CHECK OUT THE COURSE

Partner – Moderne – NPI EA (tag=Refactoring)
announcement - icon

Modern Java teams move fast — but codebases don’t always keep up. Frameworks change, dependencies drift, and tech debt builds until it starts to drag on delivery. OpenRewrite was built to fix that: an open-source refactoring engine that automates repetitive code changes while keeping developer intent intact.

The monthly training series, led by the creators and maintainers of OpenRewrite at Moderne, walks through real-world migrations and modernization patterns. Whether you’re new to recipes or ready to write your own, you’ll learn practical ways to refactor safely and at scale.

If you’ve ever wished refactoring felt as natural — and as fast — as writing code, this is a good place to start.

eBook Jackson – NPI EA – 3 (cat = Jackson)