Best of BaeldungSeptember 2024

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

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

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

  4. 4
    Article
    Avatar of baeldungBaeldung·2y

    Introduction to TeaVM

    TeaVM translates Java bytecode to JavaScript, enabling Java applications to run in browsers. It's useful for single-page applications and adding Java features to existing websites. TeaVM supports Java bytecode up to JDK 21, and basic setup requires Maven. It offers interaction with the DOM, and Java methods can be called from JavaScript. Experimental WebAssembly support and Java-to-C transpilation are also available.

  5. 5
    Article
    Avatar of baeldungBaeldung·2y

    Guide to @DynamicInsert in Spring Data JPA

    The @DynamicInsert annotation in Spring Data JPA optimizes insert operations by generating SQL statements that include only non-null fields, enhancing efficiency for entities with many nullable fields. However, it incurs runtime overhead and should be used selectively, especially when dealing with entities with default values or critical insert performance requirements. It may introduce complexity and inefficiencies in cases with mostly non-null fields, bulk insertions, or intricate database constraints.

  6. 6
    Article
    Avatar of baeldungBaeldung·2y

    Using CompletableFuture With Feign Client in Spring Boot

    Learn to parallelize HTTP requests using CompletableFuture and OpenFeign in Spring Boot. This guide covers setting up a demo application, creating Feign clients, and implementing parallel request execution. Additionally, it provides methods for handling errors and adding network and thread timeouts to ensure efficient request management.

  7. 7
    Article
    Avatar of baeldungBaeldung·2y

    How to Make a Field Optional in JPA Entity?

    When working with Spring Data and databases, it's sometimes necessary to make certain fields optional to improve performance and reduce overhead. This guide explores various techniques for achieving this, including projections, DTOs, @SqlResultSetMapping, and using Object or Tuple for native queries. Examples and tests demonstrate how to selectively fetch only the necessary fields from a table.

  8. 8
    Article
    Avatar of baeldungBaeldung·2y

    Building a RAG App Using MongoDB and Spring AI

    Learn how to build a Retrieval-Augmented Generation (RAG) Wiki application using MongoDB and Spring AI. The tutorial details setting up MongoDB Atlas Vector Search for storing documents, adding necessary dependencies, and configuring the application to save and retrieve documents based on context. The application leverages a vector store for similarity search and utilizes LLM for generating responses, making it suitable for developing chatbots, automated wikis, and search engines.

  9. 9
    Article
    Avatar of baeldungBaeldung·2y

    Deploying a Java App on Heroku

    Learn how to deploy a simple Spring Boot Java app to Heroku. The tutorial covers project setup, Heroku CLI usage, Maven Plugin configuration, GitHub and GitLab CI/CD integration, and Docker deployment. Key steps include creating necessary configuration files, initializing Heroku projects, using Git for deployment, and exploring different deployment methods such as CLIs and Docker.

  10. 10
    Article
    Avatar of baeldungBaeldung·2y

    Check if Two 2d Arrays Are Equal in Java

    Learn how to check if two 2D arrays are equal in Java. The tutorial covers both a naive approach using nested loops and a more efficient method for larger arrays, detailing their time and space complexities. It also highlights the importance of array comparison in various domains such as image processing, game development, AI, and cryptography.

  11. 11
    Article
    Avatar of baeldungBaeldung·2y

    Deep Dive Into JVM Tools: Dynamic Attach and Serviceability Agent

    JVM serviceability tools like Dynamic Attach and the Serviceability Agent are critical for managing Java applications in production environments. Dynamic Attach allows real-time diagnostics and dynamic loading of Java agents without restarting the application, but has limitations like potential performance overhead and compatibility issues. The Serviceability Agent provides deep insights into JVM internals, allowing post-mortem debugging and thorough analysis of thread states, memory usage, and locking issues. Both tools complement each other, with Dynamic Attach focusing on live applications and the Serviceability Agent offering comprehensive post-mortem analysis.