1. Optional Tools
Some libraries reduce boilerplate or provide convenience types, but they are not part of the Java language. Treat them as optional tools after you understand the core Java feature they resemble.
1.1. Lombok
Lombok generates code at compile time from annotations. It can reduce repetitive model-class code, but it also adds an annotation processor to the build and requires IDE support.
On current JDKs, configure the annotation processor explicitly instead of depending on compiler classpath scanning.
1<properties>
2 <lombok.version>1.18.42</lombok.version>
3 <maven.compiler.release>25</maven.compiler.release>
4 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
5</properties>
6
7<build>
8 <plugins>
9 <plugin>
10 <groupId>org.apache.maven.plugins</groupId>
11 <artifactId>maven-compiler-plugin</artifactId>
12 <version>3.8.1</version>
13 <configuration>
14 <proc>full</proc>
15 <release>${maven.compiler.release}</release>
16 <annotationProcessorPaths>
17 <path>
18 <groupId>org.projectlombok</groupId>
19 <artifactId>lombok</artifactId>
20 <version>${lombok.version}</version>
21 </path>
22 </annotationProcessorPaths>
23 </configuration>
1}
2
3@Getter
4@Setter
5@RequiredArgsConstructor
6@Accessors(fluent = true)
7@Builder(toBuilder = true)
8@ToString
9@EqualsAndHashCode
10static public class Person {
11
12 @NonNull
13 private final String firstName;
14 @NonNull
15 private final String lastName;
16 @NonNull
Before using Lombok for simple data classes, compare the same design with a record. Records are standard Java and are usually the better default for immutable data carriers.
1public record Student(String id, String firstName, String lastName, int grade) {
2
3 public String fullName() {
4 return firstName + " " + lastName;
5 }
6
7 public boolean passing() {
8 return grade >= 60;
9 }
10}
Lombok still has uses in some teams and frameworks, especially when JavaBeans accessors, builders, or mutable models are required. Keep it out of beginner examples unless the lesson is specifically about build tools or annotation processing.
1.2. Tuples
Java does not have built-in tuple types. The javatuples library provides
tuple classes such as Pair, Triplet, and Quintet.
1var unit = Unit.with("John");
2var pair = Pair.with("John", "Doe");
3var triplet = Triplet.with("John", "Doe", 23);
4var quartet = Quartet.with("John", "Doe", 23, 155.5d);
5var quintet = Quintet.with("John", "Doe", 23, 155.5d, true);
6// 6-tuple => Sextet
7// 7-tuple => Septet
8// 8-tuple => Octet
9// 9-tuple => Ennead
10// 10-tuple => Decade
11
12var tuples = new Tuple[]{unit, pair, triplet, quartet, quintet};
13for (Tuple t : tuples) {
14 System.out.println(t);
15}
Tuple values are accessed by position.
1var tuple = Quintet.with("John", "Doe", 23, 155.5d, true);
2
3var firstName = tuple.getValue0();
4var lastName = tuple.getValue1();
5var age = tuple.getValue2();
6var weight = tuple.getValue3();
Use tuples sparingly. A named record is usually clearer because each field has a name and the type documents the domain concept.
record FullName(String firstName, String lastName) {}
The tuple examples remain useful as a side note, but records and small classes are the idiomatic path for most Java code.