Best of Baeldung2024

  1. 1
    Article
    Avatar of baeldungBaeldung·2y

    Apache Kafka Tutorial Series

    This tutorial series covers essential topics about Apache Kafka, including its basics, how to integrate it with Spring Boot, configuring Kafka SSL, and setting up Kafka using Docker. It also explores Kafka consumer groups, retry mechanisms, and message ordering strategies, providing practical guidance for both newcomers and experienced developers.

  2. 2
    Article
    Avatar of baeldungBaeldung·2y

    Returning Errors Using ProblemDetail in Spring Boot

    Learn how to use ProblemDetail for standardized error responses in Spring Boot applications. Discover why it's important for API usability, how it streamlines error handling, and explore its implementation in both MVC and reactive applications. Includes setup, configuration, and global exception handling examples, complete with testing methods.

  3. 3
    Article
    Avatar of baeldungBaeldung·2y

    Reduce Memory Footprint in Java

    Application size is crucial for performance, and optimizing memory usage can significantly reduce an application's memory footprint. This guide explains how to estimate the memory size of Java applications, explore techniques like using primitive types, combining classes, and bit packing for optimizing memory. It also covers using the Java Object Layout (JOL) library for verification and comparing standard Java collections with third-party libraries like Eclipse Collection for additional optimization.

  4. 4
    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.

  5. 5
    Article
    Avatar of baeldungBaeldung·2y

    Why Is 2 * (i * i) Faster Than 2 * i * i in Java?

    Optimizing code can sometimes involve subtle syntax differences, such as the multiplication expressions 2 * (i * i) and 2 * i * i in Java. Even though both yield the same result, 2 * (i * i) is generally faster due to clearer order of operations, allowing better compiler optimization and more efficient CPU execution. Benchmarks confirm minor but notable performance discrepancies, especially with higher values, reinforcing the importance of understanding both language mechanics and hardware for performance-critical code.

  6. 6
    Article
    Avatar of baeldungBaeldung·2y

    A Guide to @Locked in Lombok

    Project Lombok's @Locked annotation, introduced in version 1.18.32, is designed to enhance support for virtual threads in Java by acting as a variant of the ReentrantLock, ensuring better performance in concurrent applications. It simplifies the locking mechanism in methods, reducing boilerplate code, and provides a clear advantage over the @Synchronized annotation, particularly with virtual threads. Multiple methods can share the same lock, or different locks can be specified for read and write operations to boost performance.

  7. 7
    Article
    Avatar of baeldungBaeldung·1y

    Implementing an AI Assistant with Spring AI

    This tutorial delves into the features of Spring AI to create an AI assistant using LLMs like ChatGPT. It highlights the key functionalities, including context-aware response generation, structured output conversion, and integrating with Vector DBs. The process involves setting up necessary dependencies, creating relevant tables, and implementing callback functions. Common concerns like data privacy and maintaining conversational states are addressed using Advisors APIs. Examples demonstrate how to build a chatbot in a legacy Order Management System, showcasing practical applications of these concepts.

  8. 8
    Article
    Avatar of baeldungBaeldung·2y

    What’s the Difference Between interface and @interface in Java?

    An interface in Java specifies a behavior that implementing classes must fulfill, containing method signatures without implementations, and supporting abstraction, multiple inheritance, and loose coupling. On the other hand, the @interface is used to define custom annotations that add metadata to code elements for use during compilation or runtime by tools and frameworks. Key annotations like @Retention and @Target further specify how and where these annotations can be applied.

  9. 9
    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.

  10. 10
    Article
    Avatar of baeldungBaeldung·2y

    Introduction to Lanterna

    Lanterna is a Java library for building text-based user interfaces, similar to the Curses library, but in Java. It allows the creation of terminal UIs even in graphical environments using emulated terminals. This tutorial covers how to set up Lanterna, access and manipulate terminals, handle keyboard inputs, use the buffered screen API, and create text-based GUIs with various components.

  11. 11
    Article
    Avatar of baeldungBaeldung·2y

    Introduction to Java 22

    Java 22 brings updates to the Java language, including unnamed variables and patterns, statements before super(), string templates, and implicitly declared classes and instance main methods. It also introduces new libraries such as the Foreign Function and Memory API, Class File API, Stream Gatherers, Structured Concurrency API, Scoped Values, Vector API, and updates to tooling, such as multi-file source programs. Additionally, there are performance enhancements in the G1 Garbage Collector with region pinning.

  12. 12
    Article
    Avatar of baeldungBaeldung·2y

    Rapid Spring Boot Prototyping with Bootify

    Bootify is a tool designed to accelerate Spring Boot development by automating the creation of boilerplate code and configuration files. It provides a user-friendly interface to set up entities, relationships, and application components, making it easier to focus on business logic and custom features. The post details a step-by-step guide to creating a Spring Boot CRUD application using Bootify, from project setup to code generation.

  13. 13
    Article
    Avatar of baeldungBaeldung·2y

    Vertical Slice Architecture

    Learn about Vertical Slice Architecture and how it addresses the limitations of Layered Architecture by organizing code by business capabilities. This approach improves code expressiveness, coupling, and cohesion, while providing flexibility for diverse design paradigms. Examples using Spring Boot demonstrate the application of this architecture.

  14. 14
    Article
    Avatar of baeldungBaeldung·2y

    Introduction to JavaMelody

    JavaMelody is a lightweight, open-source library designed to monitor Java applications, providing real-time statistics for performance analysis. It tracks various metrics including HTTP requests, SQL queries, CPU usage, and memory usage. Installation is straightforward, involving adding dependencies and configuring the web.xml file. It features optional centralized data collection, customizable trend charts, and error logging, with minimal performance overhead. Security considerations, such as role-based access, should be addressed when deploying in production environments.

  15. 15
    Article
    Avatar of baeldungBaeldung·2y

    Saga Pattern in Microservices Architecture

    An exploration of the Saga Pattern in microservices architecture, including its challenges, benefits, and implementation using Orkes Conductor and Spring Boot 3.

  16. 16
    Article
    Avatar of baeldungBaeldung·2y

    Java IDEs in 2024 – Survey Results

    A recent survey conducted between July 2 and July 10, 2024, revealed that IntelliJ (Community and Ultimate versions) remains the most popular Java IDE, followed by Eclipse. Visual Studio Code ranks third, outpacing NetBeans. The survey had 5788 respondents, some of whom selected multiple IDEs. The trend shows IntelliJ's user base growing while Eclipse's popularity declines compared to a similar survey from 2019.

  17. 17
    Article
    Avatar of baeldungBaeldung·2y

    Protobuf vs. gRPC

    Microservices architecture relies on efficient communication methods. Protobuf, a language-neutral mechanism for serializing structured data, offers compact and efficient data transfer but lacks human readability. gRPC, an open-source RPC framework built on HTTP/2 and using Protobuf for defining services, enables high-performance communication with features like streaming and multiplexing. While Protobuf excels in data serialization, gRPC provides a robust RPC framework suitable for real-time data exchange. The choice between them depends on specific needs, balancing efficiency, readability, and ease of configuration.

  18. 18
    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.

  19. 19
    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.

  20. 20
    Article
    Avatar of baeldungBaeldung·1y

    Introduction to Apache Accumulo

    Apache Accumulo is a powerful, distributed key-value store designed for handling massive datasets with fine-grained security. Developed originally by the NSA and based on Google's Bigtable, it excels in scalability, performance, and security, enabling efficient data ingestion, retrieval, and processing. Accumulo supports cell-level security, server-side programming, and flexible data models, making it ideal for applications requiring strict access controls and large-scale data management.

  21. 21
    Article
    Avatar of baeldungBaeldung·2y

    Checking if an Array Is Null or Empty in Java

    Learn how to check if an array is null or empty in Java, covering both object and primitive type arrays. This guide includes creating a generic method, handling primitive types, and using Apache Commons Lang's ArrayUtils and ObjectUtils utilities. Explore effective practices to write safer and more reliable Java code.

  22. 22
    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.

  23. 23
    Article
    Avatar of baeldungBaeldung·1y

    Exploring Advanced JVM Options

    The Java Virtual Machine (JVM) offers a range of advanced options to fine-tune its performance, manage memory, and conduct diagnostics. These options include configurations for garbage collection, memory management, Just-in-Time (JIT) compilation, and debugging. Developers can achieve optimal application performance by understanding and appropriately using these advanced settings, while also considering potential changes in future JVM versions.

  24. 24
    Article
    Avatar of baeldungBaeldung·2y

    Introduction to the Hilla Framework

    Hilla is a full-stack web framework for Java that enables building applications by combining React views with a Spring Boot backend. It leverages type-safe RPC to call backend Java services from TypeScript and uses Vaadin UI components. The setup involves adding Vaadin dependencies to a Spring Boot project, creating themes for consistent UI, and defining views in React. The framework simplifies calling server methods with annotations and offers automatic CRUD operations. Hilla supports file-based routing and integrated form validation for robust client-server interactions.

  25. 25
    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.