Wednesday, 24 April 2013

Difference between 'pass by value' and 'pass by reference'

Pass by Value - This means passing the actual value of the variable as an argument to some method.

Pass by Reference - This means passing the reference to the variable as an argument to some method.

Now the question ??? What does Java Use from among the two ??? 

Java is actually pass by value for all the variables within a single VM.

Tuesday, 23 April 2013

How JavaBeans differ from POJO's ???

JavaBeans are governed by certain Java Specifications which a POJO is free from.

The JavaBean specification requires a java class to ...
  1. be Serializable
  2. have getters and setters
  3. have a no argument
JavaBean Property Naming Rules ...
  1. If the property is not a boolean, the getter method's prefix must be get e.g. getSize()
  2. If the property is a boolean, the getter method's prefix should be either get or is e.g. getEmpty(), isEmpty()
  3. The setter method's prefix must be set e.g. setSize()
  4. Name of the getter or setter method is completed by changing the case of the first letter of the property name to UPPERCASE e.g. if property is size then methods are getSize() and getSize()
  5. setter methods should be marked public with void return type with an argument that represents the property type
  6. getter methods should be marked public, take no arguments, and have a return type that matches the argument type of the setter method

Sunday, 21 April 2013

What is a Plain Old Java Object or POJO ???

A "POJO" is an ordinary Java Object which does not follow any of the major Java object models, conventions, or frameworks.  

A "POJO" however is bound by the restrictions forced by the Java Language Specification.

Some of these restrictions are ... 

  1. A POJO cannot extend any Class
  2. A POJO cannot implement any Interface
  3. A POJO cannot contain any prespecified annotation 
An example of a simple POJO may be ...

public class POJO {
 
    private String someProperty;
 
    public String getSomeProperty() {
         return someProperty;
    }
 
    public void setSomeProperty(String someProperty) {
        this.someProperty = someProperty;
    }
}