Bitsmi Blog
IntelliJ Hotkeys Cheatsheet
Ubuntu - Referencia de comandos útiles
Docker - Referencia de comandos
Validation groups
jakarta.validation.groups
allow us to configure the constraints to be validated depending on the context.
For example, in some situations may have sense only to validate certain constraints when a domain entity is being created (not managed)
and not when is updated (managed), the ID and creation / update timestamps for example.
In that case we can define the constraints that will be executed in each case using different groups
Mocking external services with Wiremock
If we need to mock an external service during application development, we can configure a Wiremock container
as part of the docker-compose-DEV.yaml
service stack:
Introduction to dependency injection
Spring Dependency Injection capabilities allow us to manage bean bindings in different ways. Here is a basic guide on how to:
-
Having a single bean candidate and a single injection point, that is the base case when we define a bean and use
@Autowired
annotation to inject it -
Having multiple bean candidates of the same type and a single injection point. Here we can define a default bean or use identifiers to select which one will be injected
-
Having zero bean candidates for a type and a single injection point, which means that we can have optional beans
-
Having multiple bean candidates of the same type and a multiple injection point, allowing accessing all beans for the specified type in the same injection point
-
Having conditional bean candidates that are only available when a condition is met
-
Create and inject prototype scoped beans
Guía rápida Maven
Multi-release JARs
En los últimos años Java ha estado evolucionando muy rápido con el nuevo ciclo de distribución en el que se liberan 2 nuevas versiones por año. Con la nueva versión 17 Long Time Support (LTS) de la JDK y la versión 18 a la vuelta de la esquina, muchos desarrollos aún están asimilando la anterior versión LTS, la JDK 11. Se hace patente el hecho que los desarrollos de aplicaciones Java no pueden seguir el ritmo en el que van apareciendo las nuevas características del lenguaje y por eso muchas de ellas tardan en ser de uso general. Una de las consecuencias de este hecho es que los desarrolladores de librerías y frameworks están forzados esperar hasta que la base de aplicaciones a los que dan soporte se adapta para seguir siendo compatibles con ellas.
Desde la aparición de Java 9 han aparecido mecanismos para paliar este hecho, posibilitando la construcción de artefactos compatibles con múltiples versiones de JDK. Uno de ellos son los Multi-Release JARs (MRJAR), que hace posible integrar en un mismo componente (fichero JAR) diversas versiones de código compatibles con múltiples versiones de JDK.
En este artículo se explica el funcionamiento de los MRJAR así como su integración en un proyecto construido mediante Maven.
OCP11 - Localization & Internationalization
Internationalization is the process by which an application is designed to adapt to multiple regions and languages using the mechanisms provided by the platform, Java Platform in this case. This includes placing text strings in properties files for every supported language, ensure that a proper formatting is used when data is displayed (E.G. numbers and dates), etc. This process is also known as I18N
A localized application is compatible with multiple language and country/region configurations (locales). The localization process is also known as L12N.
OCP11 - Creating nested classes (V) - Defining an Anonymous Class
A ** anonymouys class** is a specialized form of a local class that does not have a name.
It is declared and instantiated all in one statement using the new keyword, a type name with parenthesis, and a set of braces {}.
Anonymous classes are required to extend an existing class or implement an existing interface.
Example using an Abstract class:
public class ZooGiftShop {
abstract class SaleTodayOnly {
abstract int dollarsOff();
}
public int admission(int basePrice) {
SaleTodayOnly sale = new SaleTodayOnly() {
int dollarsOff() { return 3; }
}; // Don't forget the semicolon!
return basePrice - sale.dollarsOff();
} }
Line 2 through 4 define an abstract class through . Line 6 through 8 define the anonymous class (it hasn’t a name). The code says to instantiatea new SaleTodayOnly object. It is abstract but it is ok because we provide the class body right there - anonymously. In this example, writing an anonymous class is equivalent to writing a local class with an unspecified name that extends SaleTodayOnly and then immediately using it. Line 8 specifically we are declaring a local variable on these lines. Local variable declarations are required to end with semicolons, just like ohter java statements - even if they are long and happen to contain an anonymous class.