Wednesday, September 28, 2016

Enabling Apache Velocity UI Editor in Eclipse IDE

Adding Velocity UI Editor Plugin to Eclipse IDE

1. Download 'org.apache.velocity_1.7.0.2.jar'  and 'org.vaulttec.velocity.ui_1.0.5.jar'   or other latest versions from
Also refer to

2. Copy them into <Eclipse Installation Location>\plugins  directory.
3. Restart the Eclipse
4. Add new File associations (*.vtl and *.vm and *.vsl) in Eclipse settings at 'Windows>Preferences>General>Editors>File Associations'
5. Notice that a new entry (Velocity UI) can be seen under 'Windows>Preferences>' as the result of installing new JAR files.
6. Optional: Change the settings of 'Velocity UI' if needed.
7. Open a VTL file to see the settings are reflected in editor.

Thursday, September 15, 2016

 Pass by Value or Pass by Reference in Java?

Before coming to conclusion let's look at the example.

class Person {
private String name = null;

public Person() {

public String getName() {

public void setName(String newName) { = newName;

class Manager {
public Person changePersonName1(Person p) {
if (p != null) {
// just change only name
p.setName("I'm changed by Manager in changePersonName1()");
return p;

public Person changePersonName2(Person p) {
if (p != null) {
// just change only name
p.setName("I'm changed by Manager in changePersonName2()");
// create new Person instance, which means you no longer making any
// changes to the argument 'p' but on new Person instance
p = new Person();
p.setName("I'm recreated as new Person by Manager in changePersonName2()");
return p;

public class JavaPassByValueOrReference {
public static void main(String[] args) {
// Create a person
Person p1 = new Person();
p1.setName("I'm in p1 instance");

// Create a Manager
Manager mgr = new Manager();
System.out.println("0: Person p1 name = " + p1.getName());

//1-change name 
System.out.println("1: Person p1 name = " + p1.getName());

//2-change name
System.out.println("2: Person p1 name = " + p1.getName());
0: Person p1 name = I'm in p1 instance
1: Person p1 name = I'm changed by Manager in changePersonName1()
2: Person p1 name = I'm changed by Manager in changePersonName2()

  1. In Main(..) method the 'Name' of Person is defaulted to "I'm in p1 instance".
  2. When Manager instance (mgr) changed the Person's name using  changePersonName1(..), the 'Name' of Person is changed from "I'm in p1 instance" to "I'm changed by Manager in changePersonName1()"
  3. When Manager instance (mgr) changed the Person's name using  changePersonName2(..), the 'Name' of Person is changed from "I'm changed by Manager in changePersonName1()" to "I'm changed by Manager in changePersonName2()"  instead of "I'm recreated as new Person by Manager in changePersonName2()"
The reason is in changePersonName2(Person p) of Manager class, the input argument (p) is reassigned to new Person instance (p = new Person()), changes to done on newly created instance are not returnable to or visible to Caller.

A copy of an object is made and passed to a function. On returning from the function, the copy is again copied back to the original passed object. So, the value set in the function is copied back.

In short 'Java is Pass the Reference By Value" or 'Pass the copy of Pointer(Reference) by Value'  or 'References are passed by Value' .

Wednesday, September 14, 2016










C:/Program Files/Java/jdk1.8.0_102/bin/javaw.exe




















Wednesday, September 7, 2016

Java Enum example

import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;

public class EnumExample{
 public static void main(String args[]){
  // To Get the 'Day' by Abbreviation: 
  System.out.println("1 ="+Day.get("Su"));
  System.out.println("2 ="+Day.findByAbbr("Su"));
  // To get 'Day' name in String:
  System.out.println("3 ="+Day.valueOf("SUNDAY").toString());
  // To Get the Abbreviation by 'Day': 
  System.out.println("4 ="+Day.SUNDAY.getAbbreviation());
  System.out.println("5 ="+Day.valueOf("SUNDAY").getAbbreviation());  

 * Usage: 
 * 1. To Get the 'Day' by Abbreviation: Day.get("Su"))<br/>
 * 2. To Get the Abbreviation by 'Day': <br/>
 *    Day.SUNDAY.getAbbreviation();<br/>
 *        OR <br/>
 *    Day.valueOf("SUNDAY").getAbbreviation(); <br/>
 * 3. To get 'Day' name in String:<br/>
 *    Day.valueOf("SUNDAY").toString();
 enum Day {
 //Enum types

 //internal state
 private final String abbreviation;

 // Reverse-lookup map for getting a day from an abbreviation
 private static final Map<String, Day> lookup_0 = new HashMap<String, Day>();
 // Populate the lookup table on loading time
 static {
  for (Day d : Day.values()) {
   lookup_0.put(d.getAbbreviation(), d);
 //Alternative way populating lookup table
 static {
  for (Day d : EnumSet.allOf(Day.class)) {
   lookup_0.put(d.getAbbreviation(), d);

 private Day(final String abbreviation) {
  this.abbreviation = abbreviation;

 public String getAbbreviation() {
  return abbreviation;
 // This method can be used for reverse lookup purpose
 public static Day get(String abbreviation) {
  return (Day)lookup_0.get(abbreviation);
 public static Day findByAbbr(String abbreviation){
     for(Day d : values()){
         if( d.abbreviation.equals(abbreviation)){
             return d;
     return null;