---
tags: Software Engineer, programming language, Java,
---
# Java Reusable Code Snippets
## Handle Nullable List with Optional.
```java
Optional.ofNullable()
orElse(Collections.emptyList())
// do map, filter, functional stuff here ...
```
```java
Optional.ofNullable(x)
.map(...) // if optional of null gets mapped, what happens?
.orElseGet(...)
```
Optional.of()
.map
.orElse()
Instant, Duration, Period, LocalDate, LocalDateTime
## Spring
injection syntax
- field injection
- setter injection
- constructor injection
lombok `UtilityClass`
toBuilder
retry
## SQL snippets
check tables & columns in Oracle.
time processing snippets
window function
https://www.postgresql.org/docs/current/tutorial-window.html
mapstruct mapper `qualifiedNyName`
What is Generics type.
Use `?`
`Function<A, ?>`
TestNG, validating the flow throws exception
use `expectThrows`, don't use try catch and assert exception.
spring batch concepts