Sitemap
Level Up Coding

Coding tutorials and news. The developer homepage gitconnected.com && skilled.dev && levelup.dev

Member-only story

Java-14 Features

Record Keyword in Java 14

Get rid of boilerplate code.

4 min readAug 7, 2024

--

Press enter or click to view image in full size
Photo by Kenny Eliason on Unsplash

We write classes that are simply POJO or beans or models that have some fields and their getters and setters along with toString(), hashCode() and equals() methods are overridden to provide good class definitions. These classes are used as transferrable beans between different modules of the application.

Sometimes, these types of POJO classes tend to be immutable which means once the object of these classes is created their object’s fields cannot be modified or changed.

Writing these POJOs is tedious and has many lines of boilerplate code if we have to write multiple classes then for each class we have to repeat the same process.

An example of a Person POJO class is as below:

package com.basecs101.model;


import java.util.Objects;
/**
* A simple POJO clas with 3 fields
*/
public class Person {
private String firstName;
private String lastName;
private int age;
public Person(String firstName, String lastName, int age) {
this.firstName = firstName;
this.lastName = lastName;
this.age = age;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {…

--

--

Vikram Gupta
Vikram Gupta

Written by Vikram Gupta

-: Empowering Developers to Ace Their Technical Interviews :- A Senior Engineer building Scalable, Reliable, and Containerized Cloud Applications. 5M+ views.