What is the difference between POJO (Plain Old Java Object) and DTO (Data Transfer Object)?

27,886

Solution 1

POJO or "Plain Old Java Object" is a name used to describe "ordinary" Java objects, as opposed to EJBs (originally) or anything considered "heavy" with dependencies on other technologies.

DTO or "Data Transfer Object" is an object for... well... transferring data, usually between your "business" classes and persistence layer. It typically is a behavior-less class much like a C-style struct. They are an outdated concept.

Solution 2

A POJO is just a simple Java object, the acronym is used to emphasize that it really is nothing special.

A DTO is a Data Transfer Object which is used to encapsulate data that is transferred over a connection between layers or subsystems. See the wikipedia article, it's also a Core J2EE pattern (http://www.oracle.com/technetwork/java/transferobject-139757.html).

http://en.wikipedia.org/wiki/Data_transfer_object

Solution 3

All DTOs are POJOs, but not all POJOs are DTOs. An example of POJO that is not a DTO is a business class that contains state and behavior (business logic).

Solution 4

DTO (Data transfer object) : Is a Core J2EE design pattern used for transferring data within the system.DTO Pattern


POJO (Plain Old Java Object) : It is just an acronym people use for suggesting that is a simple java object (which nowadays is heavily annotated for doing some meaning full work).

DTO Pattern
J2EE Pattern Catalog

Solution 5

DTO is pojo, but pojo is not dto, because pojo can have more behavior but DTO just basically no behavior

Oracle document has clear description.

Share:
27,886
d1ck50n
Author by

d1ck50n

Updated on February 29, 2020

Comments

  • d1ck50n
    d1ck50n over 4 years

    I cannot find difference between them. Does anyone know how to differentiate them?