tags:

views:

91

answers:

5

Hi ,

what is the Technical meaning of this context plain-vanilla Java Beans & plain-vanilla Java Class ??.

+2  A: 

A 'plain-vanilla' bean/class means a very basic class usually with the following properties;

  • Doesn't extend or implement anything
  • Has private class variables
  • Has an empty constructor
  • Has standard getter/setter methods

This is also called a POJO (Plain Old Java Object). For example;

public class MyPojo
{
    /*
     * Private class variables
     */
    private String name;
    private int size;

    /**
     * Empty constructor
     */
    public MyPojo()
    {
    }

    /*
     * Standard getter/setters 
     */
    public String getName()
    {
        return name;
    }

    public void setName(String name)
    {
        this.name = name;
    }

    public int getSize()
    {
        return size;
    }

    public void setSize(int size)
    {
        this.size = size;
    }   
}
Qwerky
"Doesn't extend or implement anything" might rather be "Doesn't extend or implement anything from a given framework" , it's a bit fuzzy - but it's fine for POJOs to implement/extend stuff - atheast your own stuff.
nos
A: 

The "plain-vanilla" reference is to differentiate it from JavaBeans (an ancient best-practice for re-usable GUI widgets) and EnterpriseJavaBeans (elements of the Java EE spec).

A plain vanilla class is one that doesn't need to meet requirements of any framework or scheme.

A plain vanilla bean is a class with mutators and accessors (i.e. getters/setters), but no behaviour.

Synesso
A: 

I think the history of the "plain vanilla Java Bean" and POJO went like this:

  1. Java 1.0 comes out, including Java Bean spec (e.g. default ctor, getters/setters for properties, etc.) to allow them to interact with VB-style editors.
  2. "Enterprise" Java Beans (EJB) 1.0 comes out to describe distributed, transactional, persistent components.
  3. J2EE standard is announced at Java One in 1999 to give us containers to manage object lifecycle, threading, pooling, etc. and provide enterprise services like naming, lookup, etc. for EJBs.
  4. People find that EJB 1.0 and 2.0 specs require a lot of code and work to do simple things.
  5. Backlash against EJB 2.0 brings us back to POJO, spawns Spring, Guice, and other DI/AOP frameworks that attempt to simplify things again.
duffymo
A: 

The "plain-vanilla Java Class" (aka. POJO) is a class which has attributes. As the name says, it's a Plain Old Java Object.
Ideally a POJO doesn't extends any class nor implements any interface. It doesn't have annotations either.


The "plain-vanilla Java Bean" (aka. JavaBean) is a class which has some requirements.

  • It must have a default constructor
  • it must have getters and setters for its attributes
  • It must implements Serializable

So a JavaBean is a kind of POJO (not an ideal POJO because it implements Serializable) with some restrictions.


Resources :

On the same topic :

Colin Hebert
A: 

'Vanilla' description comes from ice cream, I think, and describes the usual or basic flavour available. Hence vanilla pojos are unadorned, simple and plain pojos. The term is also used in finance and sex, and probably other domains too. (This is the most non-technical SO answer I have posted!)

Paul McKenzie