Developer Tools

Java Class Generator

List the fields of a Java class and get a complete POJO or record without the usual boilerplate typing: private fields, no-argument and all-argument constructors, getters and setters, equals and hashCode, toString, Objects.requireNonNull checks, an optional builder and Javadoc. Records get a compact constructor that validates components and copies lists defensively.

  • Runs in your browser
  • No sign-up
  • Free to use
Start from an example

Types: string, int, long, float (double), bool, date (Instant), any (Object), a class name, T[] (List) or map<K, V>. name? = may be null.

Options

    How to use Java Class Generator

    1. Enter the class name and package.
    2. Choose a class or a record.
    3. List the fields as name: type.
    4. Pick constructors, accessors and other methods, then copy the code.

    Java Class Generator features

    POJO or record

    Classic classes or Java 16+ records.

    Constructors

    No-argument for frameworks, all-arguments with null checks.

    Object methods

    equals, hashCode and toString.

    Immutability

    final fields and class, defensive List.copyOf in records.

    Builder

    Fluent builder for classes with many fields.

    Imports

    java.util and java.time imports added as needed.

    When to use Java Class Generator

    • Creating entities and DTOs for Spring Boot.
    • Writing immutable value objects.
    • Generating classes for JSON mapping with Jackson.
    • Learning standard Java class conventions.

    Java Class Generator FAQ

    Should I use a record or a class?

    Records (Java 16+) are ideal for immutable data: the compiler generates the constructor, accessors, equals, hashCode and toString. Use a class when fields must change or a framework needs a no-argument constructor, such as JPA entities.

    Why are some types boxed (Integer instead of int)?

    Fields that may be null and type arguments of List or Map need object types; primitives cannot be null or used in generics.

    What does the builder add?

    A static builder() method and a Builder class with one method per field, so objects with many fields can be created readably: Email.builder().to(…).subject(…).build().

    How are null checks written?

    With Objects.requireNonNull and a message naming the field, so a missing value fails at construction time.

    Which date type is used?

    java.time.Instant, a point in time in UTC. Use LocalDate for calendar dates.

    Is anything uploaded?

    No. The code is generated in your browser.

    Java classes without the boilerplate

    A plain Java data class needs a surprising amount of code: private fields, constructors, a getter and setter per field, and equals, hashCode and toString that must all include the same fields. IDEs can generate these, but a quick generator is useful when you are outside the IDE, when you want a consistent style, or when you are learning what each part is for.

    Fields use a neutral notation that maps to Java types: string to String, int to int, float to double, bool to boolean, date to java.time.Instant, T[] to List<T> and map<K, V> to Map<K, V>. A field that may be null, and any type used inside List or Map, is boxed, for example Integer instead of int. The rawType long is kept as long.

    Records are the modern choice for immutable data. The generator writes the record header and, if needed, a compact constructor that rejects null for required components and copies lists and maps with List.copyOf and Map.copyOf, so the record cannot be changed through a reference held by the caller.

    For classes, you choose the constructors and methods. A no-argument constructor is needed by JPA and some serialisers; an all-arguments constructor with null checks guarantees complete objects. equals uses pattern matching for instanceof and Objects.equals, hashCode uses Objects.hash, and toString lists every field, with a note about removing secrets before logging.

    An immutable class makes every field final, removes setters and declares the class final. Combined with the builder option, it produces the builder pattern popularised by Effective Java: readable construction of objects with many fields, with validation in one place.

    Other useful tools