Best of BaeldungAugust 2024

  1. 1
    Article
    Avatar of baeldungBaeldung·2y

    Changing Spring Boot Properties at Runtime

    Discover how to dynamically manage Spring Boot application configurations at runtime using various methods. Learn about creating prototype-scoped beans, utilizing Spring Cloud's @RefreshScope and /actuator/refresh endpoint, and managing external configuration files. These techniques allow for on-the-fly changes without restarting the application, providing flexibility and enhancing maintainability.

  2. 2
    Article
    Avatar of baeldungBaeldung·2y

    Data Oriented Programming in Java

    This post introduces Data-Oriented Programming (DOP) and contrasts it with Object-Oriented Programming (OOP). It highlights the principles of DOP such as separating data from logic, using immutable data structures, and maintaining data in a valid state. The post includes a practical exercise implementing the game Yahtzee using modern Java features like records, sealed interfaces, and pattern matching. Key distinctions between DOP and OOP are discussed, with examples illustrating the implementation and modeling of data and behavior separately.

  3. 3
    Article
    Avatar of baeldungBaeldung·2y

    Best Practices for Sizing the JDBC Connection Pool

    Efficiently managing database connections using a JDBC connection pool is crucial for application performance. By maintaining a pool of reusable connections, applications can save time and resources. Deciding the optimal pool size involves balancing performance and resource utilization. Factors such as transaction response time, database query duration, and load testing results should be considered. Key settings to tune include initial, minimum, and maximum pool sizes, idle timeout, connection timeout, and transaction isolation levels. Following best practices for tuning these settings ensures robust and efficient database connectivity.

  4. 4
    Article
    Avatar of baeldungBaeldung·2y

    Java Virtual Machine Tutorials

    Java applications often face slow startup and warmup times. The CRaC project from OpenJDK addresses this by creating a performance checkpoint and restoring the JVM at that point. BellSoft offers optimized containers for Java applications, packaging Alpaquita Linux and Liberica JDK, enabling easy integration of CRaC in Spring Boot applications.

  5. 5
    Article
    Avatar of baeldungBaeldung·2y

    DDD with jMolecules

    Learn how to leverage jMolecules to express Domain-Driven Design (DDD) concepts using annotations and type-based interfaces. The post covers key DDD elements such as Value Objects, Entities, Aggregate Roots, and Repositories, and demonstrates how to use jMolecules for building a domain model of a blogging application. It also explains how to integrate jMolecules with popular Java and Spring libraries and enforce DDD principles using ArchUnit.

  6. 6
    Article
    Avatar of baeldungBaeldung·2y

    Hibernate Reactive and Quarkus

    Hibernate Reactive and Quarkus are tools for building reactive Java applications. Hibernate Reactive extends Hibernate ORM to work with non-blocking database drivers, while Quarkus is optimized for creating reactive applications with Kubernetes-native features. The post outlines the importance of reactive programming, the use of Mutiny API, and creating a reactive bank deposit application. It also covers entity definition, repository implementation, REST endpoints, and integration testing using Quarkus.

  7. 7
    Article
    Avatar of baeldungBaeldung·2y

    Java Strip Methods

    This tutorial explores various strip methods in the Java String class, including strip(), stripLeading(), stripTrailing(), and stripIndent(). It compares these to the trim() method, highlighting differences in how they define and handle whitespace. Code examples illustrate how each method works and the scenarios best suited for their use.

  8. 8
    Article
    Avatar of baeldungBaeldung·2y

    Guide to Choosing Between Protocol Buffers and JSON

    Protocol Buffers (Protobuf) and JSON are data serialization formats with distinct differences in readability, performance, and efficiency. Protobuf requires a predefined schema and is more space-efficient and fast, making it suitable for high-performance applications like real-time analytics and gaming. JSON, on the other hand, is human-readable, flexible, and widely used in web APIs, configuration files, and logging. While Protobuf enforces strict data integrity through its schema, JSON offers more flexibility but may require JSON Schema for validation.

  9. 9
    Article
    Avatar of baeldungBaeldung·2y

    Introduction to Armeria

    Armeria is a versatile framework designed for building efficient microservice clients and servers that can communicate using various protocols like REST, gRPC, Thrift, and GraphQL. It supports numerous integrations and dependencies and offers functionality such as BOM usage for managing dependencies, server configuration, logging, handlers for different requests, and a flexible routing system. Additionally, it provides support for annotated handlers, request and response converters, and handling exceptions. Features like automatic TLS certificate generation and detailed HTTP request logging make it powerful and adaptable for various use cases.

  10. 10
    Article
    Avatar of baeldungBaeldung·2y

    Dynamic Client Registration in Spring Authorization Server

    Spring Authorization Server provides sensible defaults suitable for client applications with minimal configuration. However, dynamic client registration is not enabled by default. Follow these steps to enable and use dynamic client registration in a Spring Boot application, ensuring proper authentication using bearer tokens and configuring the necessary endpoints. The tutorial includes both server and client implementations, detailing how to register clients dynamically using a custom `RegisteredClientRepository` and integrating the process into a Spring Security-based application for dynamic OAuth2 client management.

  11. 11
    Article
    Avatar of baeldungBaeldung·2y

    Automated End-to-End Testing With Playwright

    End-to-end testing helps ensure software reliability by simulating real user interactions. Using Playwright with TypeScript facilitates the automation of these tests. Detailed steps to set up Playwright via VS Code, along with scenarios for user registration and product search on a sample eCommerce site, are provided. Cloud-based platforms like LambdaTest can enhance the testing process by offering cross-browser capabilities on multiple operating systems. The article includes comprehensive code snippets for setting up and performing these tests.

  12. 12
    Article
    Avatar of baeldungBaeldung·2y

    Create a ChatGPT Like Chatbot With Ollama and Spring AI

    Learn how to create a basic help desk chatbot using the Spring AI module and the open-source Ollama library with Meta's llama3 model. The guide covers setting up the environment, adding necessary dependencies, configuring the chatbot, and managing conversational history. Example API calls and responses are provided to demonstrate interaction with the chatbot.

  13. 13
    Article
    Avatar of baeldungBaeldung·2y

    Java Class.cast() vs. Cast Operator

    Casting in Java involves converting one data type to another, essential in polymorphism. This tutorial compares the cast operator and Class.cast() through an example using a hierarchy of video game characters. Both methods have their pros and cons in terms of readability, simplicity, type safety, performance, code maintenance, and flexibility. The choice between them depends on use case and context.

  14. 14
    Article
    Avatar of baeldungBaeldung·2y

    A Guide to @‌MockBeans

    This guide explores the usage of the @MockBeans annotation in Spring Boot. It provides an example setup with a TicketValidator class and demonstrates how to mock dependencies using @MockBean and @MockBeans annotations. The @MockBean annotation allows for creating mocked versions of specific beans for testing, while @MockBeans serves as a container for multiple @MockBean annotations. The guide also contrasts these approaches and highlights how to organize test cases effectively.

  15. 15
    Article
    Avatar of baeldungBaeldung·2y

    Annotation Based HTTP Filters in Micronaut

    This tutorial explores annotated HTTP filters in the Micronaut framework, focusing on server filters introduced in version 4. It explains how HTTP filters operate, including their use cases such as authentication, header modification, metrics, and logging. New annotation-based methods for filtering requests and responses are discussed, along with details on configuring path patterns and filter order. Practical examples illustrate using @ServerFilter, @RequestFilter, and @ResponseFilter annotations for implementing these filters.