Java

What’s the difference between Concurrency and Parallelism?

Concurrency and Parallelism are important concepts for bringing more efficiency to software, but they do not mean the same thing. A software application can handle multiple tasks, and the way these tasks are processed differs in each concept. Concurrency Imagine the scenario where we have a software that needs to process multiple tasks, such as…

Read More

How to create a custom repository in Spring Data JPA?

Spring Data JPA is great for abstracting away boilerplate code when accessing the database. It allows us to create query methods by simply defining method signatures. But sometimes, we need more complex or dynamic queries — and that’s where custom repositories come into play. In this post, I’ll show how to create a custom repository…

Read More

What is Spring Data JPA?

Spring Data JPA is a module of Spring Data that simplifies the implementation of repositories. It provides an automatic way to create repository implementations based on Java interfaces, eliminating the need to manually write the repository implementation. To make this work, you need to create an interface using the @Repository annotation and extend JpaRepository. The…

Read More
Java

How to avoid NullPointerException in Java using Optional?

Optional was introduced in Java 8 as a way to handle potentially null values more safely and expressively. It helps to avoid NullPointerException and makes the code more readable. Hands on Creating an Optional Optional can be created in several ways: Printing the results will show the following output. Checking for Value Presence Optional provides…

Read More
Java

How do @PostConstruct and @PreDestroy annotation work in java?

Methods annotated with @PostConstruct and @PreDestroy are commonly used in the lifecycle of beans managed by the container, such as in frameworks like Spring or Quarkus. An example of their use is opening and closing database connections. If you want to know more about Bean management in Spring, don’t hesitate to read this post. @PostConstruct…

Read More
Java

How do functional interfaces work in Java?

Functional Interfaces are a fundamental concept in functional programming introduced in Java 8. They are interfaces that have exactly one abstract method, allowing the use of lambda expressions and method references to make the code more concise and readable. They can be used in Streams, for example, and promote code reuse. We can find several…

Read More
Java

What is Shallow Copy and Deep Copy in Java?

When developing software, there may be situations where it is necessary to create copies of objects to prevent unwanted behaviors, whether to avoid different parts of the system modifying the same object or for any other reason that prevents undesired behavior. Java provides the Cloneable interface, which allows object copying. There are two types of…

Read More
Java

How does serialization and deserialization work in Java?

Serialization and deserialization are essential for persisting or transferring data between systems. Serialization transforms Java objects into formats like JSON or XML, enabling storage or network transmission. Deserialization, on the other hand, restores these objects, making the data reusable in applications. These processes are widely used in APIs, data persistence, and communication between distributed systems,…

Read More
Java

How to use Generic Types in Java?

The use of Generics in Java improves security, readability, and code reuse, simplifying the development of robust and secure applications. Let’s see some usage examples below. Generic Methods <T>: It’s a generic type parameter, accepting any type. T Item: The method accepts a parameter of the generic type. We can specify, for example, String and…

Read More
Java

How to sort Java Collections?

Sorting in Java Collections is an essential feature for organizing collection elements in ascending or descending order. Using the Comparable or Comparator interfaces, custom sorting criteria can be defined. The Collections class provides utility methods, such as sort(), to apply these rules. This enables efficient and flexible data processing. Hands on The following example is…

Read More