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
Java

How to run tasks in parallel with timeout in Java?

The use of Threads is essential to improving the performance and responsiveness of modern applications. With threads, it is possible to execute multiple tasks simultaneously, maximizing processor resources. They allow intensive operations, such as calculations or accessing external resources (e.g., databases, APIs), to be performed in parallel without blocking the main execution. Imagine the following…

Read More
banner api

What is Richardson Maturity Model?

It is a model (developed by Leonard Richardson) to improve API maturity. To achieve the glory of REST, the API must have maturity levels. There are 4 levels, and next we will see how each of them works. Level 0: The Swamp of POX This level defines that the use of the HTTP protocol is…

Read More
Java

What is Garbage Collection in Java?

It is a process that manages memory in software written in Java. When running programs on the JVM (Java Virtual Machine), objects are created in the Heap memory. When these objects are no longer needed, the Garbage Collector will find unused objects and remove them from memory, helping to prevent memory leaks. We need to…

Read More
Java

How to improve the performance of primitive types in Java’s Stream Api?

Java’s Stream API facilitates code maintenance, is used with lambda expressions and functional paradigm. It offers many features such as filtering a list, among others. Let’s see an example. For this, I created a class called Product. I populated a list of products and created the following stream. My goal is to map the quantity,…

Read More