Introduction to Project Lombok

Introduction to Project Lombok

Writing a new Model comes with the addition of a lot of boiler plate code. Free up your entity classes with help from Project Lombok.

Writing a new Model/Data comes with the addition of a lot of boiler plate code. Boiler plate code is the code that is repetitive throughout application and has little change in its implementation.

The common step in creating new POJO or Model class is writing Getters, Setters, Constructors, To String methods, Equals method, etc. Even if the IDEs offer to generate them for the user, it still doesn't decrease the amount of repetitive code that goes in these methods.

Lombok is armed with annotations that take care of boiler plate code.

Lombok Annotations:

  • Val** - **Creates a local variable with val which will be initialized based on initialization expression.The local variable will also be made final. 
  • Var** - **Works exactly like Val but the local variable is not declared final.
  • @Setter - Add setter for all variables.
  • @Getter - Add getter for all the variables.
  • @RequiredArgsConstructor - Generates constructor for each field.
  • @NoArgsConstructor - Creates a non-parametrized constructor.
  • @AllArgsConstructor - Creates a parametrized constructor containing all fields.
  • @ToString - Creates toString method.
  • @EqualsAndHashCode - Creates Equals and Hashcode implementation for fields in the class.
  • @Value - Short for final @ToString @EqualsAndHashCode @AllArgsConstructor @FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE) @Getter.
  • @Data - It is a quick way of combining features of @ToString, @EqualsAndHashCode, @Getter, @Setter and @RequiredArgsConstructor. 
  • @Builder - Makes instantiation of class easier and provides a way to statically initialize fields in a class.
  • @NotNull - Makes sure the value of object is not null. This is highly beneficial when dealing with data access object and saves risk NullPointerException that may go unchecked.

java tutorial jpa lombok entity

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

How to Install OpenJDK 11 on CentOS 8

What is OpenJDK? OpenJDk or Open Java Development Kit is a free, open-source framework of the Java Platform, Standard Edition (or Java SE).

Java Tutorial for Beginners | Java Tutorial | Java Programming | Core Java Tutorial | Learn Java

This "Java Tutorial for Beginners" Full course will help you master all the major concepts in java such as Arrays, Polymorphism, Abstraction, Inheritance, and Collections.

Java Core (2020) | Java for beginners | Brush up your Java Skills | Get Hired

In this video we will learn about all the major concepts that come under Java Core . The course is very carefully designed and is made with keeping simplicit...

Java File Class Tutorial | File Class in Java Example

Java File class represents the path of directories and files. It provides the methods for renaming, deleting, and obtaining the properties of file or directory.

Java For Loop Example | For Loop in Java Tutorial

Java For loop provides a concise way of writing the loop structure. For loop consumes the initialization, condition and increment/decrement in one line.