HOME

TheInfoList



OR:

In
software engineering Software engineering is a branch of both computer science and engineering focused on designing, developing, testing, and maintaining Application software, software applications. It involves applying engineering design process, engineering principl ...
, a plain old Java object (POJO) is an ordinary
Java Java is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea (a part of Pacific Ocean) to the north. With a population of 156.9 million people (including Madura) in mid 2024, proje ...
object Object may refer to: General meanings * Object (philosophy), a thing, being, or concept ** Object (abstract), an object which does not exist at any particular time or place ** Physical object, an identifiable collection of matter * Goal, an a ...
, not bound by any special restriction. The term was coined by Martin Fowler, Rebecca Parsons and Josh MacKenzie in September 2000: The term "POJO" initially denoted a Java object which does not follow any of the major Java object models, conventions, or frameworks. It has since gained adoption as a language-agnostic term, because of the need for a common and easily understood term that contrasts with complicated object frameworks. The term continues an
acronym An acronym is a type of abbreviation consisting of a phrase whose only pronounced elements are the initial letters or initial sounds of words inside that phrase. Acronyms are often spelled with the initial Letter (alphabet), letter of each wor ...
pattern to coin retronyms for constructs that do not use fancy new features: * "Plain old JavaScript object" in
JavaScript JavaScript (), often abbreviated as JS, is a programming language and core technology of the World Wide Web, alongside HTML and CSS. Ninety-nine percent of websites use JavaScript on the client side for webpage behavior. Web browsers have ...
* "Plain old Ruby object" (PORO) in
Ruby Ruby is a pinkish-red-to-blood-red-colored gemstone, a variety of the mineral corundum ( aluminium oxide). Ruby is one of the most popular traditional jewelry gems and is very durable. Other varieties of gem-quality corundum are called sapph ...
* "Plain old Documentation" (pod) in
Perl Perl is a high-level, general-purpose, interpreted, dynamic programming language. Though Perl is not officially an acronym, there are various backronyms in use, including "Practical Extraction and Reporting Language". Perl was developed ...
*
Plain old CLR object In software engineering, a plain old CLR object, or plain old class object (POCO) is a simple object created in the .NET Common Language Runtime (CLR) that is unencumbered by inheritance or attributes. This is often used in opposition to the comp ...
(POCO) in the .NET Framework * "Plain old PHP object" (POPO) in
PHP PHP is a general-purpose scripting language geared towards web development. It was originally created by Danish-Canadian programmer Rasmus Lerdorf in 1993 and released in 1995. The PHP reference implementation is now produced by the PHP Group. ...
*
Plain old telephone service Plain old telephone service (POTS), or publicly offered telephone service, is basic Voice band, voice-grade telephone service. Historically, POTS has been delivered by Analog signal, analog signal transmission over copper loops, but the term also d ...
(POTS) in
telephony Telephony ( ) is the field of technology involving the development, application, and deployment of telecommunications services for the purpose of electronic transmission of voice, fax, or data, between distant parties. The history of telephony is ...


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 inpublic class Foo extends javax.servlet.http.HttpServlet { ... #Implement prespecified interfaces, as inpublic class Bar implements javax.ejb.EntityBean { ... #Contain prespecified
annotations An annotation is extra information associated with a particular point in a document or other piece of information. It can be a note that includes a comment or explanation. Annotations are sometimes presented in the margin of book pages. For anno ...
, as in@javax.persistence.Entity public class Baz { ... 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. The idea is that if the object (actually class) were a POJO before any annotations were added, and would return to POJO status if the annotations are removed then it can still be considered a POJO. Then the basic object remains a POJO in that it has no special characteristics (such as an implemented interface) that makes it a "Specialized Java Object" (SJO or (sic) SoJO).


Contextual variations


JavaBeans

A
JavaBean In computing based on the Java Platform, JavaBeans is a technology developed by Sun Microsystems and released in 1996, as part of JDK 1.1. The 'beans' of JavaBeans are classes that encapsulate one or more objects into a single standardized ob ...
is a POJO that is serializable, has a no-argument constructor, 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 JavaBeans specification, if fully implemented, slightly breaks the POJO model as the class must implement the Serializable interface to be a true JavaBean. Many POJO classes still called JavaBeans do not meet this requirement. Since Serializable is a marker (method-less) interface, this is not much of a burden. The following shows an example of a
JavaServer Faces Jakarta Faces, formerly Jakarta Server Faces and JavaServer Faces (JSF) is a Java specification for building component-based user interfaces for web applications. It was formalized as a standard through the Java Community Process as part of the ...
(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()" (or "isSomeProperty()" if the property is of
Boolean type In computer science, the Boolean (sometimes shortened to Bool) is a data type that has one of two possible values (usually denoted ''true'' and ''false'') which is intended to represent the two truth values of logic and Boolean algebra. It is nam ...
) method for getting a value, and to the "setSomeProperty(String)" method for setting a value. Th
lombok
library allows to change the code dynamically to integrate those conventions without the hassle to write them. The following code would generate the same bean, with the addition of an empty constructor :@NoArgsConstructor public class MyBean { @Getter @Setter private String someProperty; }Other libraries or framework generate code (or bytecode) with those conventions directly. The addition of those tools help alleviate the boilerplate, which in turn reduces the bugs frequency and maintenance cost .


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 focuses on
business logic In computer software, business logic or domain logic is the part of the program that encodes the real-world business rules that determine how data can be created, stored, and changed. It is contrasted with the remainder of the software that might ...
and has no dependencies on (enterprise) frameworks.
Aspect-oriented programming In computing, aspect-oriented programming (AOP) is a programming paradigm that aims to increase modularity by allowing the separation of cross-cutting concerns. It does so by adding behavior to existing code (an advice) ''without'' modifying t ...
(AOP) frameworks then transparently add cross-cutting concerns like persistence, transactions, security, and so on.Martin, Robert C; (2008); ''Clean Code'', Chapter 11, ''Pure Java AOP Frameworks'' Spring was an early implementation of this idea and one of the driving forces behind popularizing this model. An example of an EJB bean being a POJO: *
Enterprise JavaBeans Jakarta Enterprise Beans (EJB; formerly Enterprise JavaBeans) is one of several Java APIs for modular construction of enterprise software. EJB is a server-side software component that encapsulates business logic of an application. An EJB web ...
(EJB), *
Java Persistence API Jakarta Persistence, also known as JPA (abbreviated from the former name Java Persistence API) is a Jakarta EE application programming interface specification that describes the management of relational data in enterprise Java applications. Per ...
(JPA) (including
Hibernate Hibernation is a state of minimal activity and metabolic reduction entered by some animal species. Hibernation is a seasonal heterothermy characterized by low body-temperature, slow breathing and heart-rate, and low metabolic rate. It is most ...
)
CDI (Contexts and Dependency Injection for the Java EE platform)
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 Extensible Markup Language (XML) is a markup language and file format for storing, transmitting, and reconstructing data. It defines a set of rules for encoding electronic document, documents in a format that is both human-readable and Machine-r ...
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.Panda, Debu; Rahman, Reza; Lane, Derek; (2007). ''EJB 3 in action'', Manning Publications Co., Shelter Island (NY), (www.manning.com/books/ejb-3-in-action). Chapter 11, ''Deployment descriptors vs. annotations'' Thus, as an alternative to XML, many frameworks (e.g. Spring, EJB and JPA) allow annotations to be used instead of or in addition to XML. The following shows the same EJB bean as shown above but with an annotation added. In this case the XML file is no longer needed: @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.


Related Acronyms


Plain old Java Interface

A Plain old Java Interface (POJI) is a basic form of
Java interface An interface in the Java programming language is an abstract type that is used to declare a behavior that classes must implement. They are similar to protocols. Interfaces are declared using the interface keyword, and may only contain method sig ...
and acceptable at points where more complex Java interfaces are not permitted.


See also

*
Data transfer object In the field of programming a data transfer object (DTOMSDN (2010). Data Transfer Object. Microsoft MSDN Library. Retrieved from https://msdn.microsoft.com/en-us/library/ms978717.aspx.Fowler, Martin (2010). Data Transfer Object. Patterns of Enterpr ...
(DTO) *
Anemic domain model The anemic domain model is described as a programming anti-pattern where the domain objects contain little or no business logic like validations, calculations, rules, and so forth. The business logic is thus baked into the architecture of the prog ...
*
KISS principle KISS, an acronym for "Keep it simple, stupid!", is a design principle first noted by the U.S. Navy in 1960. First seen partly in American English by at least 1938, KISS implies that simplicity should be a design goal. The phrase has been associate ...


References

{{Reflist, refs= {{cite book, title=Rational Application Developer V7.5 Programming Guide, first1=Ueli, last1=Wahli, first2=Miguel, last2=Vieira, first3=Ferreira Lopes, last3=Gomes, first4=Brian, last4=Hainey, first5=Ahmed, last5=Moharram, first6=JuanPablo, last6=Napoli, first7=Marco, last7=Rohr, first8=Henry, last8=Cui, first9=Patrick, last9=Gan, first10=Celso, last10=Gonzalez, first11=Pinar, last11=Ugurlu, first12=Lara, last12=Ziosi, date=29 June 2009, publisher=IBM Redbooks, isbn=978-0738432892 Java (programming language) Computer jargon