ArticleslgStudy

computer science

Plain old Java object

Plain old Java object is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Plain old Java object rather than just read about it. In short: In software engineering, a plain old Java object (POJO) is an ordinary Java object, not bound by any special restriction. The term was coined by Martin Fowler, 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.

Key takeaways

  • Plain old Java object belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Plain old Java object to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Plain old Java object from memory before moving on to harder problems.

Reference excerpt

In software engineering, a plain old Java object (POJO) is an ordinary Java object, not bound by any special restriction. The term was coined by Martin Fowler, 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" 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 pattern to coin retronyms for constructs that do not use fancy new features:

"Plain old JavaScript object" in JavaScript "Plain old Ruby object" (PORO) in Ruby "Plain old Documentation" (pod) in Perl Plain old CLR object (POCO) in the .NET Framework "Plain old PHP object" (POPO) in PHP Plain old telephone service (POTS) in telephony

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, many software products or frameworks that require annotations for features like persistence still consider an object (or rather a class) a POJO if it uses annotations.

Contextual variations

JavaBeans A JavaBean 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 (JSF) component having a bidirectional binding to a POJO's property:

The definition of the POJO can be as follows:

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) method for getting a value, and to the "setSomeProperty(String)" method for setting a value. The Project 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:

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 and has no dependencies on (enterprise) frameworks. Aspect-oriented programming (AOP) 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. An example of an EJB bean being a POJO:

Enterprise JavaBeans (EJB), Java Persistence API (JPA) (including Hibernate) 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:

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 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:

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 and acceptable at points where more complex Java interfaces are not permitted.

See also Data transfer object (DTO) Anemic domain model KISS principle

References

Worked examples

Example 1 — a first encounter with Plain old Java object

Start with the simplest possible case. Write down what Plain old Java object claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Plain old Java object before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Plain old Java object ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Plain old Java object

In research
Plain old Java object appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Plain old Java object in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Plain old Java object is common in secondary-school and first-year university syllabi. It links to neighbouring topics Computer jargon, Java (programming language), so understanding it makes those chapters shorter.
In everyday life
Look for Plain old Java object outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Plain old Java object” →

How to study Plain old Java object in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Plain old Java object means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Plain old Java object out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Plain old Java object in simple terms?

In software engineering, a plain old Java object (POJO) is an ordinary Java object, not bound by any special restriction. The term was coined by Martin Fowler, Rebecca Parsons and Josh MacKenzie in September 2000: We wondered why people were so against using regular objects in their systems and con…

Why does Plain old Java object matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Plain old Java object?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Plain old Java object.

Tags

  • Computer jargon
  • Java (programming language)

Keep exploring