Plain Old Java Object
Encyclopedia
In computing
software, POJO is an acronym for Plain Old Java Object. The name is used to emphasize that a given object
is an ordinary Java Object, not a special object. The term was coined by Martin Fowler
, Rebecca Parsons and Josh MacKenzie in September 2000:
The term "POJO" is mainly used to denote a Java object which does not follow any of the major Java object models, conventions, or frameworks. The term continues the pattern of older terms for technologies that do not use fancy new features, such as POTS (Plain Old Telephone Service
) in telephony
, and PODS (Plain Old Data Structures
) that are defined in C++
but use only C
language features, and POD (Plain Old Documentation) in Perl
. The equivalent to POJO on the .NET framework
is Plain Old CLR Object
.
The POJO phenomenon has most likely gained widespread acceptance because of the need for a common and easily understood term that contrasts with complicated object frameworks.
However, due to technical difficulties and other reasons, many software products or frameworks described as POJO-compliant actually still require the use of prespecified annotations for features such as persistence to work properly.
, and allows access to properties using getter and setter methods
that follow a simple naming convention. Because of this convention, simple declarative references can be made to the properties of arbitrary JavaBeans. Code using such a declarative reference does not have to know anything about the type of the bean, and the bean can be used with many frameworks without these frameworks having to know the exact type of the bean.
The following shows an example of a JSF
component having a bidirectional
binding to a POJO's property:
The definition of the POJO can be as follows:
public class MyBean {
private String someProperty;
public String getSomeProperty {
return someProperty;
}
public void setSomeProperty(String someProperty) {
this.someProperty = someProperty;
}
}
Because of the JavaBean naming conventions the single "someProperty" reference can be automatically translated to the "getSomeProperty" method for getting a value, and to the "setSomeProperty(String)" method for setting a value.
frameworks then transparently add cross-cutting concerns like persistence, transactions, security, and so on.
Spring was an early implementation of this idea and one of the driving forces behind popularizing this model.
Other examples are:
The following shows a fully functional EJB bean, demonstrating how EJB3 leverages the POJO model:
public class HelloWorldService {
public String sayHello {
return "Hello, world!";
}
}
As given, the bean does not need to extend any EJB class or implement any EJB interface and also does not need to contain any EJB annotations. Instead, the programmer declares in an external xml file which EJB services should be added to the bean:
helloWorld
com.example.HelloWorldService
stateless
In practice, some people find annotations elegant, while they see XML as verbose, ugly and hard to maintain, yet others find annotations pollute the POJO model.
Thus, as an alternative to XML, many frameworks (e.g. Spring, EJB and JPA) allow annotations to be used instead or in addition to XML:
@Stateless
public class HelloWorldService {
public String sayHello {
return "Hello, world!";
}
}
With the annotation as given above the bean isn't a truly pure POJO anymore, but since annotations are merely passive metadata this has far fewer harmful drawbacks compared to the invasiveness of having to extend classes and/or implement interfaces. Accordingly, the programming model is still very much like the pure POJO model.
BeanExaminer : framework to present any java objects in an interactive surface to browse and edit them. A generator is included to create the desired POJOs through a given db connection.
Roma Meta Framework : DDD centric framework. The innovative holistic approach lets the designer/developer to view anything as a POJO: GUI, I18N, Persistence, etc.
OpenXava : Framework to develop J2EE business applications rapidly and easily. It's based in business components defined with XML. Feature rich and flexible since it's used for years to create business applications. Generates POJO Hibernate EJB2 and EJB3 JPA ...
PlainXML : Generating POJO by DTD; XML-POJO mapping via Java5 annotations or DTD; XML manipulations using POJO without SAX/DOM; Preprocessing of XML documents using expression language; Binary XML; RMI friendly XML; Exporting to JSON; XML marshall/unmarshall ...
PAT : AOP (JBossAOP) persistence library (aspect library). Provides persistence layer with underlying Prevayler (1.02). Allows users to write their code without worrying about persistence code (POJO). Uses annotations.
Java O/RM : This is a Java Object Relational mapping tool that is very simple to use. It works with all major databases and requires only minimal coding effort. JOR strictly follows the POJO / POJI (Plain Old Java Objects / Plain Old Java Interfaces) model.
AutoPersistJ : This project aims to assist developers in developing java EE persistence layer for existing database tables. It gets metadata of selected database tables and generates classes for them. it uses and extends the ideas of DbGen project to EJB 3.0 POJO.
PojoGen: It is a small tool to generate Java Code (a POJO) for an APPFUSE-based project from a DDL file, which is created from an ER diagram by Microsoft VISIO. It makes an APPFUSE-based project more easy to use.
Pojodbc: An easy-to-use Java Object Relation mapping library without configurations file or annotations. Built on top of JDBC, you still use your optimized native SQL and get POJOs.
Apache Felix iPOJO : A new type of dynamic service-oriented
component
runtime that runs pure POJO applications on the top of OSGi
platforms. Non-functional (extra-functional) services can be added and removed at runtime.
JBoss Microcontainer: The JBoss
Microcontainer is a refactoring of JBoss
's JMX Microkernel
to support direct POJO deployment and standalone use outside the JBoss
application server.
Naked Objects: An open source framework that auto-creates an object-oriented user interface from POJOs using the naked objects
pattern.
Metawidget: A 'smart User Interface widget' that populates itself, at runtime, with UI components to match the properties of POJOs.
fbDaoGenerator: Fbdaogenerator connects to a Firebird
Database, reads the metadata
of the Database by querying the system-tables, and generates POJOs and Data Access Object
s.
Computing
Computing is usually defined as the activity of using and improving computer hardware and software. It is the computer-specific part of information technology...
software, POJO is an acronym for Plain Old Java Object. The name is used to emphasize that a given object
Object (computer science)
In computer science, an object is any entity that can be manipulated by the commands of a programming language, such as a value, variable, function, or data structure...
is an ordinary Java Object, not a special object. The term was coined by Martin Fowler
Martin Fowler
-Online presentations:* at RailsConf 2006* at JAOO 2006* at QCon London 2007 * at QCon London 2008 * at ThoughtWorks Quarterly Technology Briefing, October 2008...
, Rebecca Parsons and Josh MacKenzie in September 2000:
"We wondered why people were so against using regular objects in their systems and concluded that it was because simple objects lacked a fancy name. So we gave them one, and it's caught on very nicely."
The term "POJO" is mainly used to denote a Java object which does not follow any of the major Java object models, conventions, or frameworks. The term continues the pattern of older terms for technologies that do not use fancy new features, such as POTS (Plain Old Telephone Service
Plain old telephone service
Plain old telephone service is the voice-grade telephone service that remains the basic form of residential and small business service connection to the telephone network in many parts of the world....
) in telephony
Telephony
In telecommunications, telephony encompasses the general use of equipment to provide communication over distances, specifically by connecting telephones to each other....
, and PODS (Plain Old Data Structures
Plain Old Data Structures
A plain old data structure is a data structure that is represented only as passive collections of field values, without using encapsulation or other object-oriented features....
) that are defined in C++
C++
C++ is a statically typed, free-form, multi-paradigm, compiled, general-purpose programming language. It is regarded as an intermediate-level language, as it comprises a combination of both high-level and low-level language features. It was developed by Bjarne Stroustrup starting in 1979 at Bell...
but use only C
C (programming language)
C is a general-purpose computer programming language developed between 1969 and 1973 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system....
language features, and POD (Plain Old Documentation) in Perl
Perl
Perl is a high-level, general-purpose, interpreted, dynamic programming language. Perl was originally developed by Larry Wall in 1987 as a general-purpose Unix scripting language to make report processing easier. Since then, it has undergone many changes and revisions and become widely popular...
. The equivalent to POJO on the .NET framework
.NET Framework
The .NET Framework is a software framework that runs primarily on Microsoft Windows. It includes a large library and supports several programming languages which allows language interoperability...
is Plain Old CLR Object
Plain Old CLR Object
Plain Old CLR Object or POCO is a play on the term POJO, from the Java EE programming world, and is used by developers targeting the Common Language Runtime of the .NET Framework....
.
The POJO phenomenon has most likely gained widespread acceptance because of the need for a common and easily understood term that contrasts with complicated object frameworks.
Definition
Ideally speaking, a POJO is a Java object not bound by any restriction other than those forced by the Java Language Specification. I.e., a POJO should not have to- Extend prespecified classes, as in
- Implement prespecified interfaces, as in
- Contain prespecified annotations, as in
However, due to technical difficulties and other reasons, many software products or frameworks described as POJO-compliant actually still require the use of prespecified annotations for features such as persistence to work properly.
JavaBeans
A JavaBean is a POJO that is serializable, has a no-argument constructorConstructor (computer science)
In object-oriented programming, a constructor in a class is a special type of subroutine called at the creation of an object. It prepares the new object for use, often accepting parameters which the constructor uses to set any member variables required when the object is first created...
, and allows access to properties using getter and setter methods
Mutator method
In computer science, a mutator method is a method used to control changes to a variable.The mutator method, sometimes called a "setter", is most often used in object-oriented programming, in keeping with the principle of encapsulation...
that follow a simple naming convention. Because of this convention, simple declarative references can be made to the properties of arbitrary JavaBeans. Code using such a declarative reference does not have to know anything about the type of the bean, and the bean can be used with many frameworks without these frameworks having to know the exact type of the bean.
The following shows an example of a JSF
JavaServer Faces
JavaServer Faces is a Java-based Web application framework intended to simplify development integration of web-based user interfaces....
component having a bidirectional
Duplex (telecommunications)
A duplex communication system is a system composed of two connected parties or devices that can communicate with one another in both directions. The term multiplexing is used when describing communication between more than two parties or devices....
binding to a POJO's property:
The definition of the POJO can be as follows:
public class MyBean {
private String someProperty;
public String getSomeProperty {
return someProperty;
}
public void setSomeProperty(String someProperty) {
this.someProperty = someProperty;
}
}
Because of the JavaBean naming conventions the single "someProperty" reference can be automatically translated to the "getSomeProperty" method for getting a value, and to the "setSomeProperty(String)" method for setting a value.
Transparently adding services
As designs using POJOs have become more commonly used, systems have arisen that give POJOs the full functionality used in frameworks and more choice about which areas of functionality are actually needed. In this model, the programmer creates nothing more than a POJO. This POJO purely focusses on business logic and has no dependencies on (enterprise) frameworks. AOPAspect-oriented programming
In computing, aspect-oriented programming is a programming paradigm which aims to increase modularity by allowing the separation of cross-cutting concerns...
frameworks then transparently add cross-cutting concerns like persistence, transactions, security, and so on.
Spring was an early implementation of this idea and one of the driving forces behind popularizing this model.
Other examples are:
- Enterprise JavaBeans,
- JPAJava Persistence APIThe Java Persistence API, sometimes referred to as JPA, is a Java programming language framework managing relational data in applications using Java Platform, Standard Edition and Java Platform, Enterprise Edition....
(including HibernateHibernate (Java)Hibernate is an object-relational mapping library for the Java language, providing a framework for mapping an object-oriented domain model to a traditional relational database...
) - CDI
The following shows a fully functional EJB bean, demonstrating how EJB3 leverages the POJO model:
public class HelloWorldService {
public String sayHello {
return "Hello, world!";
}
}
As given, the bean does not need to extend any EJB class or implement any EJB interface and also does not need to contain any EJB annotations. Instead, the programmer declares in an external xml file which EJB services should be added to the bean:
In practice, some people find annotations elegant, while they see XML as verbose, ugly and hard to maintain, yet others find annotations pollute the POJO model.
Thus, as an alternative to XML, many frameworks (e.g. Spring, EJB and JPA) allow annotations to be used instead or in addition to XML:
@Stateless
public class HelloWorldService {
public String sayHello {
return "Hello, world!";
}
}
With the annotation as given above the bean isn't a truly pure POJO anymore, but since annotations are merely passive metadata this has far fewer harmful drawbacks compared to the invasiveness of having to extend classes and/or implement interfaces. Accordingly, the programming model is still very much like the pure POJO model.
POJO generation projects
Prevayler : an open source system prevalence layer that transparently persists POJOs.BeanExaminer : framework to present any java objects in an interactive surface to browse and edit them. A generator is included to create the desired POJOs through a given db connection.
Roma Meta Framework : DDD centric framework. The innovative holistic approach lets the designer/developer to view anything as a POJO: GUI, I18N, Persistence, etc.
OpenXava : Framework to develop J2EE business applications rapidly and easily. It's based in business components defined with XML. Feature rich and flexible since it's used for years to create business applications. Generates POJO Hibernate EJB2 and EJB3 JPA ...
PlainXML : Generating POJO by DTD; XML-POJO mapping via Java5 annotations or DTD; XML manipulations using POJO without SAX/DOM; Preprocessing of XML documents using expression language; Binary XML; RMI friendly XML; Exporting to JSON; XML marshall/unmarshall ...
PAT : AOP (JBossAOP) persistence library (aspect library). Provides persistence layer with underlying Prevayler (1.02). Allows users to write their code without worrying about persistence code (POJO). Uses annotations.
Java O/RM : This is a Java Object Relational mapping tool that is very simple to use. It works with all major databases and requires only minimal coding effort. JOR strictly follows the POJO / POJI (Plain Old Java Objects / Plain Old Java Interfaces) model.
AutoPersistJ : This project aims to assist developers in developing java EE persistence layer for existing database tables. It gets metadata of selected database tables and generates classes for them. it uses and extends the ideas of DbGen project to EJB 3.0 POJO.
PojoGen: It is a small tool to generate Java Code (a POJO) for an APPFUSE-based project from a DDL file, which is created from an ER diagram by Microsoft VISIO. It makes an APPFUSE-based project more easy to use.
Pojodbc: An easy-to-use Java Object Relation mapping library without configurations file or annotations. Built on top of JDBC, you still use your optimized native SQL and get POJOs.
Apache Felix iPOJO : A new type of dynamic service-oriented
Service-oriented architecture
In software engineering, a Service-Oriented Architecture is a set of principles and methodologies for designing and developing software in the form of interoperable services. These services are well-defined business functionalities that are built as software components that can be reused for...
component
Component-based software engineering
Component-based software engineering is a branch of software engineering that emphasizes the separation of concerns in respect of the wide-ranging functionality available throughout a given software system...
runtime that runs pure POJO applications on the top of OSGi
OSGi
The Open Services Gateway initiative framework is a module system and service platform for the Java programming language that implements a complete and dynamic component model, something that does not exist in standalone Java/VM environments...
platforms. Non-functional (extra-functional) services can be added and removed at runtime.
JBoss Microcontainer: The JBoss
JBoss
JBoss Application Server is an open-source Java EE-based application server. An important distinction for this class of software is that it not only implements a server that runs on Java, but it actually implements the Java EE part of Java...
Microcontainer is a refactoring of JBoss
JBoss
JBoss Application Server is an open-source Java EE-based application server. An important distinction for this class of software is that it not only implements a server that runs on Java, but it actually implements the Java EE part of Java...
's JMX Microkernel
Microkernel
In computer science, a microkernel is the near-minimum amount of software that can provide the mechanisms needed to implement an operating system . These mechanisms include low-level address space management, thread management, and inter-process communication...
to support direct POJO deployment and standalone use outside the JBoss
JBoss
JBoss Application Server is an open-source Java EE-based application server. An important distinction for this class of software is that it not only implements a server that runs on Java, but it actually implements the Java EE part of Java...
application server.
Naked Objects: An open source framework that auto-creates an object-oriented user interface from POJOs using the naked objects
Naked objects
Naked objects is an architectural pattern used in software engineering.-Definition:The naked objects pattern is defined by three principles:...
pattern.
Metawidget: A 'smart User Interface widget' that populates itself, at runtime, with UI components to match the properties of POJOs.
fbDaoGenerator: Fbdaogenerator connects to a Firebird
Firebird (database server)
Firebird is an open source SQL relational database management system that runs on Linux, Windows, and a variety of Unix. The database forked from Borland's open source edition of InterBase in 2000, but since Firebird 1.5 the code has been largely rewritten ....
Database, reads the metadata
Metadata
The term metadata is an ambiguous term which is used for two fundamentally different concepts . Although the expression "data about data" is often used, it does not apply to both in the same way. Structural metadata, the design and specification of data structures, cannot be about data, because at...
of the Database by querying the system-tables, and generates POJOs and Data Access Object
Data Access Object
In computer software, a data access object is an object that provides an abstract interface to some type of database or persistence mechanism, providing some specific operations without exposing details of the database. It provides a mapping from application calls to the persistence layer...
s.