Best of BaeldungNovember 2024

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

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

  3. 3
    Article
    Avatar of baeldungBaeldung·2y

    Finding IP Address of a URL in Java

    Learn how to find the IP address of a URL in Java through various methods, such as using the InetAddress class, socket connections, and third-party libraries like Apache Commons Lang and Google Guava. Each approach is illustrated with code examples and unit tests to ensure accuracy.

  4. 4
    Article
    Avatar of baeldungBaeldung·2y

    How to Check if Two Boolean Values Are Equal

    The post explores various ways to check for equality between boolean values in Java. It discusses direct comparison with the == operator, using the equals() method for Boolean objects, leveraging the XOR operator, utilizing Boolean.compare(), and employing Objects.equals() for null safety. Each method is explained with code examples, highlighting when and why to use each approach for efficient and readable code.

  5. 5
    Article
    Avatar of baeldungBaeldung·2y

    Java Date and Calendar: From Legacy to Modern Approaches

    Handling dates and times in Java has evolved from using legacy classes like java.util.Date and java.util.Calendar to the modern java.time package introduced in Java 8. The new package addresses many issues found in the older classes, providing immutable, thread-safe classes with clear APIs and support for time zones. The post covers the history, benefits, and usage of modern date-time classes along with best practices for their implementation.

  6. 6
    Article
    Avatar of baeldungBaeldung·2y

    Consuming Messages in Batch in Kafka Using @KafkaListener

    The post discusses handling Kafka messages in batches using the @KafkaListener annotation from the Spring Kafka library. It covers the advantages of batch processing, such as increased system efficiency and fault tolerance, and presents a use case involving an IT infrastructure's KPIs. The article demonstrates the implementation of a basic listener and a batch-processing listener, explaining the configuration details and differences between the two approaches.

  7. 7
    Article
    Avatar of baeldungBaeldung·2y

    Mockito Answer API: Returning Values Based on Parameters

    This post discusses how to use Mockito's Answer API for testing role-based authentication services. It starts with mock creation using the mock() method, followed by method stubbing with thenAnswer(). The post explains how method invocation interception works in Mockito and provides examples of implementing the Answer API for different user roles in a content management system. Lastly, it outlines verifying the implementation through tests, ensuring proper role-based access.

  8. 8
    Article
    Avatar of baeldungBaeldung·1y

    Testing the Main Class of a Spring Boot Application

    Testing the main class of a Spring Boot application is crucial to ensure the application starts correctly. The post covers different strategies for testing, from basic context loading tests to mocking SpringApplication.run(), and explains how to handle application arguments and exclude the main class from code coverage. These methods help catch potential issues early and improve the reliability of the application startup process.

  9. 9
    Article
    Avatar of baeldungBaeldung·2y

    How to use virtual threads with ScheduledExecutorService

    Virtual threads introduced in JEP-444 are a lightweight version of the Thread class, allowing for increased concurrency in applications by using fewer resources than operating system threads. These threads are dynamic and ideal for small tasks but Java currently lacks a standard API to schedule them like with ScheduledExecutorService. The article discusses methods for scheduling virtual threads using Thread.sleep() and SingleThreadExecutor, highlighting their advantages and limitations.