Skip to content

Difference between DTO, VO, POJO, JavaBeans?

In Java, DTO stands for Data Transfer Object, and it is a simple object that is used to carry data between processes. DTOs are typically mutable data carriers used when transferring data over a network or between layers of an application. They usually have private fields with public getter and setter methods, and they do not contain business logic or validation.

java
public class UserDTO {
    private String username;
    private String email;
    // getters and setters
}

VO stands for Value Object. While sometimes confused with "View Object", in modern Java and Domain-Driven Design (DDD), a VO is an immutable object defined strictly by its attributes rather than a unique identity. Unlike mutable DTOs, VOs are typically immutable and are used to represent data values across layers.

java
public final class Money {
    private final BigDecimal amount;
    private final String currency;
    // constructor, getters, equals/hashCode
}

POJO stands for Plain Old Java Object, and it is a Java object that does not have any special methods or features. It is a simple Java object with private fields, and getter and setter methods for accessing the data. POJOs are often used as simple data containers, and may be used as DTOs or VOs.

java
public class Product {
    private String name;
    private double price;
    // getters and setters
}

JavaBeans are a type of POJO that follow certain conventions for naming and accessing the properties of the object. A JavaBean has private fields, and provides public getter and setter methods for accessing the data. Additionally, a JavaBean must have a public no-argument constructor and typically implements java.io.Serializable. These conventions allow JavaBeans to be easily serialized, deserialized, and accessed by various tools and frameworks.

java
public class Person implements Serializable {
    private String name;
    public Person() {} // required no-arg constructor
    // getters and setters
}

In summary, DTOs, VOs, POJOs, and JavaBeans are all simple Java objects that are used to transfer data, but they may have different purposes and conventions. DTOs are typically mutable data carriers used to transfer data between processes. VOs are usually immutable objects defined by their attributes. POJOs are simple data containers without framework requirements, and JavaBeans follow strict conventions including a public no-arg constructor and Serializable implementation.

Do you find this helpful?

Dual-run preview — compare with live Symfony routes.